Skip to content

Instantly share code, notes, and snippets.

@corsix
Created December 8, 2025 17:37
Show Gist options
  • Select an option

  • Save corsix/65ffbd66bbd199b3d77e4ec24c3d3724 to your computer and use it in GitHub Desktop.

Select an option

Save corsix/65ffbd66bbd199b3d77e4ec24c3d3724 to your computer and use it in GitHub Desktop.
uint64_t table_lookup(hash_table_t* table, uint32_t key) {
uint64_t mask = table->mask;
uint64_t* slots = table->slots;
for (uint64_t d = 0;; ++d) {
uint64_t idx = (int32_t)(key + d) & mask;
uint64_t slot = slots[idx];
if (slot == 0) {
return 0;
} else if (key == (uint32_t)slot) {
return (slot >> 32) | (slot << 32);
} else if (((idx - slot) & mask) < d) {
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment