Created
December 4, 2019 20:11
-
-
Save ayende/0f0ee9c79965bc918cf05f2b73dc5aea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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