fix: use children list to store threads with repr and not just parent

This commit is contained in:
Nemo D'ACREMONT 2025-05-07 08:32:14 +02:00
parent 6d97e0ee60
commit 7a1ab1415a
No known key found for this signature in database
GPG Key ID: 85F245EC3BB1E022
2 changed files with 13 additions and 6 deletions

View File

@ -5,10 +5,10 @@
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread) void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
{ {
TAILQ_INIT(&ufd->children);
ufd->thread = thread; ufd->thread = thread;
ufd->repr = ufd, ufd->repr = ufd,
ufd->parent = NULL; ufd->parent = NULL;
ufd->child = NULL;
} }
@ -21,6 +21,7 @@ void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
{ {
a->parent = th2; a->parent = th2;
a->repr = b; a->repr = b;
TAILQ_INSERT_TAIL(&a->repr->children, a, link);
} }
} }
@ -38,9 +39,10 @@ struct ufd_t* ufd__find(struct ufd_t* th)
void ufd__delete(struct ufd_t* th) void ufd__delete(struct ufd_t* th)
{ {
if (th->child != NULL) struct ufd_t* child;
{
th->child->parent = th->child; TAILQ_FOREACH(child, &th->children, link) {
th->child->repr = th->child; child->parent = NULL;
child->repr = child;
} }
} }

View File

@ -2,15 +2,20 @@
#define _UNION_FIND_H_ #define _UNION_FIND_H_
#include <sys/queue.h> #include <sys/queue.h>
TAILQ_HEAD(ufd_children_t, ufd_t);
// union find delete data structure // union find delete data structure
struct ufd_t { struct ufd_t {
struct ufd_t* parent; struct ufd_t* parent;
struct ufd_t* repr; struct ufd_t* repr;
struct ufd_t* child;
struct context_entry_t* thread; struct context_entry_t* thread;
struct ufd_children_t children;
TAILQ_ENTRY(ufd_t) link;
}; };
struct ufd_t ufd__make_set(struct context_entry_t* thread);
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread); void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread);
/* /*