summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/map.c b/map.c
index c720bbc..0a6a896 100644
--- a/map.c
+++ b/map.c
@@ -280,7 +280,9 @@ static void rehash_set(set_t* set) {
void* key = old_buckets[i];
if (key == NULL) continue;
size_t idx = fetch_set_idx(set, key, true);
- if (idx >= set->__num_buckets) crash("wtf\n"); // TODO
+ if (idx >= set->__num_buckets)
+ crash(
+ "Set failed rehashing, likely due to bad hash function.\n");
set->__buckets[idx] = key;
}
free(old_buckets);
@@ -290,11 +292,12 @@ static size_t fetch_set_idx_rehashing(set_t* set, void* key) {
size_t idx = fetch_set_idx(set, key, true);
if ((double) ++set->size / set->__num_buckets > set->load_limit
|| idx >= set->__num_buckets) {
- // TODO: no need for do/while
- do {
- rehash_set(set);
- idx = fetch_set_idx(set, key, true);
- } while (idx >= set->__num_buckets);
+ rehash_set(set);
+ idx = fetch_set_idx(set, key, true);
+ if (idx >= set->__num_buckets)
+ crash(
+ "Set still full after rehashing, "
+ "likely due to bad hash function.\n");
}
return idx;
}