Skip to content

Commit

Permalink
hashtable: fix (and speed up) post-deletion backshift logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaricchi committed Sep 18, 2024
1 parent 2869ddd commit 6f969de
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/SDL_hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ static SDL_HashItem *insert_item(SDL_HashItem *restrict item_to_insert, SDL_Hash
static void delete_item(SDL_HashTable *restrict ht, SDL_HashItem *item)
{
Uint32 hash_mask = ht->hash_mask;
Uint32 num_buckets = hash_mask + 1;
SDL_HashItem *table = ht->table;

if (ht->nuke) {
Expand All @@ -229,13 +228,14 @@ static void delete_item(SDL_HashTable *restrict ht, SDL_HashItem *item)
idx = (idx + 1) & hash_mask;
SDL_HashItem *next_item = table + idx;

if (get_probe_length(next_item->hash & hash_mask, idx, num_buckets) < 1) {
item->live = false;
if (next_item->probe_len < 1) {
SDL_zerop(item);
return;
}

*item = *next_item;
item->probe_len -= 1;
HT_ASSERT(item->probe_len < ht->max_probe_len);
item = next_item;
}
}
Expand Down

0 comments on commit 6f969de

Please sign in to comment.