Skip to content

Instantly share code, notes, and snippets.

@ayende
Created December 4, 2019 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayende/0f0ee9c79965bc918cf05f2b73dc5aea to your computer and use it in GitHub Desktop.
Save ayende/0f0ee9c79965bc918cf05f2b73dc5aea to your computer and use it in GitHub Desktop.
int compare_ptrs(const void* a, const void* b) {
hash_bucket_t* x = *(hash_bucket_t**)a;
hash_bucket_t* y = *(hash_bucket_t**)b;
ptrdiff_t diff = x - y;
if (diff)
return diff > 0 ? 1 : -1;
return 0;
}
void hash_table_free(hash_ctx_t* ctx) {
qsort(ctx->dir->buckets, ctx->dir->number_of_buckets, sizeof(hash_bucket_t*), compare_ptrs);
hash_bucket_t* prev = NULL;
for (size_t i = 0; i < ctx->dir->number_of_buckets; i++)
{
if (prev == ctx->dir->buckets[i]) {
continue;
}
prev = ctx->dir->buckets[i];
ctx->release_page(ctx->dir->buckets[i]);
}
ctx->release_page(ctx->dir);
ctx->dir = NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment