fix: use child list properly

This commit is contained in:
Nemo D'ACREMONT 2025-05-07 12:30:27 +02:00
parent 93a4b1341c
commit 7476ccc821
No known key found for this signature in database
GPG Key ID: 85F245EC3BB1E022

View File

@ -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->parent = th->child;
if (child->repr == th)
child->repr = th->child;
child = TAILQ_FIRST(&th->children);
TAILQ_REMOVE(&th->children, child, link);
child->parent = th->child;
child->repr = th->child;
if (child != th->child)
TAILQ_INSERT_TAIL(&th->child->children, child, link);
}
DBG("prefix %d", a);
}