]> granicus.if.org Git - yasm/commitdiff
HAMT: Update stored key when building tree downwards from identical keys.
authorPeter Johnson <peter@tortall.net>
Wed, 1 Aug 2007 05:14:53 +0000 (05:14 -0000)
committerPeter Johnson <peter@tortall.net>
Wed, 1 Aug 2007 05:14:53 +0000 (05:14 -0000)
Not doing this could cause us to lose an entry if the tree is deep enough
that we need to rehash the keys as we're moving downward.

Reported by: Stefan Sellmer <stefansel@hotmail.de>

svn path=/trunk/yasm/; revision=1905

libyasm/hamt.c

index 033a48acb8cb3ac4bc3eccd6a639a4fa75bc5af1..ceee28f75a1b3e38a133e0adac74f0b587ecbffa 100644 (file)
@@ -281,7 +281,8 @@ HAMT_insert(HAMT *hamt, const char *str, void *data, int *replace,
                          * downward.
                          */
                         newnodes = yasm_xmalloc(sizeof(HAMTNode));
-                        newnodes[0] = *node;    /* structure copy */
+                        newnodes[0].BitMapKey = key2;
+                        newnodes[0].BaseValue = node->BaseValue;
                         node->BitMapKey = 1<<keypart;
                         SetSubTrie(hamt, node, newnodes);
                         node = &newnodes[0];
@@ -297,13 +298,15 @@ HAMT_insert(HAMT *hamt, const char *str, void *data, int *replace,
 
                         /* Copy nodes into subtrie based on order */
                         if (keypart2 < keypart) {
-                            newnodes[0] = *node;    /* structure copy */
+                            newnodes[0].BitMapKey = key2;
+                            newnodes[0].BaseValue = node->BaseValue;
                             newnodes[1].BitMapKey = key;
                             SetValue(hamt, &newnodes[1], entry);
                         } else {
                             newnodes[0].BitMapKey = key;
                             SetValue(hamt, &newnodes[0], entry);
-                            newnodes[1] = *node;    /* structure copy */
+                            newnodes[1].BitMapKey = key2;
+                            newnodes[1].BaseValue = node->BaseValue;
                         }
 
                         /* Set bits in bitmap corresponding to keys */