diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-07-10 14:45:07 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-07-10 14:45:07 -0400 |
| commit | 394da24c854fdd2dc08e37090263972b732f5424 (patch) | |
| tree | 5fafbf0b64b0883d176418747b45b7d8316ca6c9 /src/stdlib/tables.c | |
| parent | 39501916acc08208360d9f920af425d0e8e230bb (diff) | |
| parent | cd1e9b5fd52dbc993463d58c41895aba9cd78966 (diff) | |
Merge branch 'main' into decimals
Diffstat (limited to 'src/stdlib/tables.c')
| -rw-r--r-- | src/stdlib/tables.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c index 762afb06..9301914c 100644 --- a/src/stdlib/tables.c +++ b/src/stdlib/tables.c @@ -177,20 +177,16 @@ static void Table$set_bucket(Table_t *t, const void *entry, int32_t index, const // Move mid-chain entry to free space and update predecessor buckets[predecessor].next_bucket = t->bucket_info->last_free; buckets[t->bucket_info->last_free] = *bucket; - } else { // Collided with the start of a chain + + bucket->occupied = 1; + bucket->index = index; + bucket->next_bucket = END_OF_CHAIN; + } else { // Collided with the start of a chain, put the new entry in chain position #2 hdebug("Hit start of a chain\n"); - uint64_t end_of_chain = hash; - while (buckets[end_of_chain].next_bucket != END_OF_CHAIN) - end_of_chain = buckets[end_of_chain].next_bucket; - hdebug("Appending to chain\n"); - // Chain now ends on the free space: - buckets[end_of_chain].next_bucket = t->bucket_info->last_free; - bucket = &buckets[t->bucket_info->last_free]; - } - - bucket->occupied = 1; - bucket->index = index; - bucket->next_bucket = END_OF_CHAIN; + buckets[t->bucket_info->last_free] = (bucket_t){ + .occupied = 1, .index=index, .next_bucket=bucket->next_bucket}; + bucket->next_bucket = t->bucket_info->last_free; + } hshow(t); } |
