fix: use child list properly
This commit is contained in:
parent
93a4b1341c
commit
7476ccc821
@ -1,6 +1,7 @@
|
||||
#include "ufd.h"
|
||||
#include "debug.h"
|
||||
#include "stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
|
||||
@ -21,10 +22,11 @@ inline void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
||||
|
||||
if (a != b)
|
||||
{
|
||||
a->parent = th2;
|
||||
th2->child = a;
|
||||
a->repr = b;
|
||||
TAILQ_INSERT_TAIL(&b->repr->children, a, link);
|
||||
th1->parent = th2;
|
||||
th1->repr = b;
|
||||
th2->child = th1;
|
||||
if (th1 != b)
|
||||
TAILQ_INSERT_TAIL(&b->children, th1, link);
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,13 +46,17 @@ inline struct ufd_t* ufd__find(struct ufd_t* th)
|
||||
|
||||
inline void ufd__delete(struct ufd_t* th)
|
||||
{
|
||||
struct ufd_t* child = NULL;
|
||||
struct ufd_t* child;
|
||||
|
||||
TAILQ_FOREACH(child, &th->children, link)
|
||||
while (!TAILQ_EMPTY(&th->children))
|
||||
{
|
||||
if (child->parent == th)
|
||||
child = TAILQ_FIRST(&th->children);
|
||||
TAILQ_REMOVE(&th->children, child, link);
|
||||
|
||||
child->parent = th->child;
|
||||
if (child->repr == th)
|
||||
child->repr = th->child;
|
||||
if (child != th->child)
|
||||
TAILQ_INSERT_TAIL(&th->child->children, child, link);
|
||||
}
|
||||
DBG("prefix %d", a);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user