Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

khash: factor out kh_release_* #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions khash.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,16 @@ static const double __ac_HASH_UPPER = 0.77;
SCOPE kh_##name##_t *kh_init_##name(void) { \
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
} \
SCOPE void kh_release_##name(kh_##name##_t *h) \
{ \
kfree(h->flags); \
kfree((void *)h->keys); \
kfree((void *)h->vals); \
} \
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
{ \
if (h) { \
kfree((void *)h->keys); kfree(h->flags); \
kfree((void *)h->vals); \
kh_release_##name(h); \
kfree(h); \
} \
} \
Expand Down Expand Up @@ -445,6 +450,13 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
*/
#define kh_destroy(name, h) kh_destroy_##name(h)

/*! @function
@abstract Free the memory of a hash table, keep the [khash_t(name)*].
@param name Name of the hash table [symbol]
@param h Pointer to the hash table [khash_t(name)*]
*/
#define kh_release(name, h) kh_release_##name(h)

/*! @function
@abstract Reset a hash table without deallocating memory.
@param name Name of the hash table [symbol]
Expand Down