From 04843fe714192139c9a6d8c013b30fac1e5a1fc2 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Fri, 20 Dec 2024 20:17:53 +0100 Subject: [PATCH] do not use xor to combine keys since when more than two layers deep this would result in identical keys --- src/ugui_core.c3 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ugui_core.c3 b/src/ugui_core.c3 index 9e0905c..3d7f50f 100644 --- a/src/ugui_core.c3 +++ b/src/ugui_core.c3 @@ -182,10 +182,13 @@ fn Elem*! Ctx.get_parent(&ctx) return ctx.cache.search(parent_id); } +// generate an id combining the hashes of the parent id and the label +// with the Cantor pairing function macro Id! Ctx.gen_id(&ctx, String label) { - Id parent_id = ctx.tree.get(ctx.active_div)!; - return parent_id ^ label.hash(); + Id a = ctx.tree.get(ctx.active_div)!; + Id b = label.hash(); + return (a + b) * (a + b + 1) / 2 + a; } // get or push an element from the cache, return a pointer to it