Typedef in stdx_hashtable.h

XHashFnClone

typedef void(*XHashFnClone)(void *dst, const void *src);
Typedef in stdx_hashtable.h

XHashFnCompare

typedef bool(*XHashFnCompare)(const void *a, const void *b);
Typedef in stdx_hashtable.h

XHashFnDestroy

typedef void(*XHashFnDestroy)(void *ptr);
Typedef in stdx_hashtable.h

XHashFnHash

typedef size_t(*XHashFnHash)(const void *key, size_t);
Function in stdx_hashtable.h

x_hashtable_count

Get the number of stored entries in the hashtable.

X_HASHTABLE_API size_t x_hashtable_count(const XHashtable *table);

Parameters

const XHashtable *table
Hashtable instance.

Returns

Number of key/value pairs currently stored.

Function in stdx_hashtable.h

x_hashtable_create_ex

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
);

Parameters

size_t key_size
Size in bytes of the key type.
bool key_null_terminated
True if the key is a NUL-terminated string (C string).
bool key_is_pointer
True if the key is stored as a pointer value.
size_t value_size
Size in bytes of the value type.
bool value_null_terminated
True if the value is a NUL-terminated string (C string).
bool value_is_pointer
True if the value is stored as a pointer value.

Returns

Pointer to a newly created hashtable, or NULL on failure.

Function in stdx_hashtable.h

x_hashtable_create_full

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
);

Parameters

size_t key_size
Size in bytes of the key type.
size_t value_size
Size in bytes of the value type.
XHashFnHash fn_key_hash
Function used to hash keys.
XHashFnCompare fn_key_compare
Function used to compare keys for equality.
XHashFnClone fn_key_copy
Function used to clone/copy keys into the table.
XHashFnDestroy fn_key_free
Function used to destroy/free keys owned by the table.
XHashFnClone fn_value_copy
Function used to clone/copy values into the table.
XHashFnDestroy fn_value_free
Function used to destroy/free values owned by the table.

Returns

Pointer to a newly created hashtable, or NULL on failure.

Function in stdx_hashtable.h

x_hashtable_destroy

Destroy a hashtable and free all associated resources.

X_HASHTABLE_API void x_hashtable_destroy(XHashtable *table);

Parameters

XHashtable *table
Hashtable instance to destroy.

Returns

Nothing.

Function in stdx_hashtable.h

x_hashtable_get

Retrieve a value from the hashtable by key.

X_HASHTABLE_API bool x_hashtable_get(
 XHashtable *table,
 const void *key,
 void *out_value
);

Parameters

XHashtable *table
Hashtable instance.
const void *key
Pointer to the key data.
void *out_value
Output buffer to receive the value.

Returns

True if the key was found and out_value was written, false otherwise.

Function in stdx_hashtable.h

x_hashtable_has

Check whether the hashtable contains a key.

X_HASHTABLE_API bool x_hashtable_has(
 XHashtable *table,
 const void *key
);

Parameters

XHashtable *table
Hashtable instance.
const void *key
Pointer to the key data.

Returns

True if the key exists, false otherwise.

Function in stdx_hashtable.h

x_hashtable_remove

Remove an entry from the hashtable by key.

X_HASHTABLE_API bool x_hashtable_remove(
 XHashtable *table,
 const void *key
);

Parameters

XHashtable *table
Hashtable instance.
const void *key
Pointer to the key data.

Returns

True if an entry was removed, false if the key was not found.

Function in stdx_hashtable.h

x_hashtable_set

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
);

Parameters

XHashtable *table
Hashtable instance.
const void *key
Pointer to the key data.
const void *value
Pointer to the value data.

Returns

True on success, false on failure (e.g., allocation failure).