Pārlūkot izejas kodu

fix bug in hashindex_set on resize, fixes #4829

the problem was that after a resize that was triggered by too few
empty buckets, the rebuilt new hash table had entries at different
positions than before, but the idx where to SET the entry was not
recomputed afterwards.
Thomas Waldmann 5 gadi atpakaļ
vecāks
revīzija
7bb90b6a51
1 mainītis faili ar 10 papildinājumiem un 0 dzēšanām
  1. 10 0
      borg/_hashindex.c

+ 10 - 0
borg/_hashindex.c

@@ -449,6 +449,16 @@ hashindex_set(HashIndex *index, const void *key, const void *value)
                 if(!hashindex_resize(index, index->num_buckets)) {
                     return 0;
                 }
+                /* we have just built a fresh hashtable and removed all tombstones,
+                 * so we only have EMPTY or USED buckets, but no DELETED ones any more.
+                 */
+                idx = hashindex_index(index, key);
+                while(!BUCKET_IS_EMPTY(index, idx)) {
+                    idx++;
+                    if (idx >= index->num_buckets){
+                        idx -= index->num_buckets;
+                    }
+                }
             }
         }
         ptr = BUCKET_ADDR(index, idx);