Forráskód Böngészése

ncd: NCDStringIndex: use CHash_MultiplyBuckets() to increase the size of the hash table buckets array when
we resize the entries array

ambrop7 13 éve
szülő
commit
ea9eed6af4
2 módosított fájl, 12 hozzáadás és 5 törlés
  1. 11 4
      ncd/NCDStringIndex.c
  2. 1 1
      ncd/NCDStringIndex.h

+ 11 - 4
ncd/NCDStringIndex.c

@@ -90,9 +90,16 @@ static NCD_string_id_t do_get (NCDStringIndex *o, const char *str, size_t str_le
         return ref.link;
     }
     
-    if (o->entries_size == o->entries_capacity && !Array_DoubleUp(o)) {
-        BLog(BLOG_ERROR, "Array_DoubleUp failed");
-        return -1;
+    if (o->entries_size == o->entries_capacity) {
+        if (!Array_DoubleUp(o)) {
+            BLog(BLOG_ERROR, "Array_DoubleUp failed");
+            return -1;
+        }
+        
+        if (!NCDStringIndex__Hash_MultiplyBuckets(&o->hash, o->entries, 1)) {
+            BLog(BLOG_ERROR, "NCDStringIndex__Hash_MultiplyBuckets failed");
+            return -1;
+        }
     }
     
     ASSERT(o->entries_size < o->entries_capacity)
@@ -121,7 +128,7 @@ int NCDStringIndex_Init (NCDStringIndex *o)
         goto fail0;
     }
     
-    if (!NCDStringIndex__Hash_Init(&o->hash, NCDSTRINGINDEX_HASH_BUCKETS)) {
+    if (!NCDStringIndex__Hash_Init(&o->hash, NCDSTRINGINDEX_INITIAL_HASH_BUCKETS)) {
         BLog(BLOG_ERROR, "NCDStringIndex__Hash_Init failed");
         goto fail1;
     }

+ 1 - 1
ncd/NCDStringIndex.h

@@ -37,7 +37,7 @@
 #include <base/DebugObject.h>
 
 #define NCDSTRINGINDEX_INITIAL_CAPACITY 1
-#define NCDSTRINGINDEX_HASH_BUCKETS 100
+#define NCDSTRINGINDEX_INITIAL_HASH_BUCKETS 1
 
 typedef int NCD_string_id_t;