XHashFnClone
typedef void(*XHashFnClone)(void *dst, const void *src);
typedef void(*XHashFnClone)(void *dst, const void *src);
typedef bool(*XHashFnCompare)(const void *a, const void *b);
typedef void(*XHashFnDestroy)(void *ptr);
typedef size_t(*XHashFnHash)(const void *key, size_t);
typedef struct{
size_t key_size;
size_t value_size;
size_t count;
size_t capacity;
XHashEntry *entries;
void *keys;
void *values;
bool key_is_pointer;
bool value_is_pointer;
bool key_is_null_terminated;
bool value_is_null_terminated;
XHashFnHash fn_key_hash;
XHashFnCompare fn_key_compare;
XHashFnClone fn_key_copy;
XHashFnDestroy fn_key_free;
XHashFnClone fn_value_copy;
XHashFnDestroy fn_value_free;
}XHashtable;
Get the number of stored entries in the hashtable.
X_HASHTABLE_API size_t x_hashtable_count(const XHashtable *table);
const XHashtable *tableNumber of key/value pairs currently stored.
Create a hashtable using raw size and explicit string/pointer traits for keys and values.
X_HASHTABLE_API XHashtable * x_hashtable_create_ex(
size_t key_size,
bool key_null_terminated,
bool key_is_pointer,
size_t value_size,
bool value_null_terminated,
bool value_is_pointer
);
size_t key_sizebool key_null_terminatedbool key_is_pointersize_t value_sizebool value_null_terminatedbool value_is_pointerPointer to a newly created hashtable, or NULL on failure.
Create a fully-configurable hashtable with custom hashing, comparison, cloning, and destruction.
XHashtable * x_hashtable_create_full(
size_t key_size,
size_t value_size,
XHashFnHash fn_key_hash,
XHashFnCompare fn_key_compare,
XHashFnClone fn_key_copy,
XHashFnDestroy fn_key_free,
XHashFnClone fn_value_copy,
XHashFnDestroy fn_value_free
);
size_t key_sizesize_t value_sizeXHashFnHash fn_key_hashXHashFnCompare fn_key_compareXHashFnClone fn_key_copyXHashFnDestroy fn_key_freeXHashFnClone fn_value_copyXHashFnDestroy fn_value_freePointer to a newly created hashtable, or NULL on failure.
Destroy a hashtable and free all associated resources.
X_HASHTABLE_API void x_hashtable_destroy(XHashtable *table);
XHashtable *tableNothing.
Retrieve a value from the hashtable by key.
X_HASHTABLE_API bool x_hashtable_get(
XHashtable *table,
const void *key,
void *out_value
);
XHashtable *tableconst void *keyvoid *out_valueTrue if the key was found and out_value was written, false otherwise.
Check whether the hashtable contains a key.
X_HASHTABLE_API bool x_hashtable_has(
XHashtable *table,
const void *key
);
XHashtable *tableconst void *keyTrue if the key exists, false otherwise.
Remove an entry from the hashtable by key.
X_HASHTABLE_API bool x_hashtable_remove(
XHashtable *table,
const void *key
);
XHashtable *tableconst void *keyTrue if an entry was removed, false if the key was not found.
Insert or update a key/value pair in the hashtable.
X_HASHTABLE_API bool x_hashtable_set(
XHashtable *table,
const void *key,
const void *value
);
XHashtable *tableconst void *keyconst void *valueTrue on success, false on failure (e.g., allocation failure).