Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
|
Macros | |
#define | BKTHOMPS_U_MAP_STARTING_BUCKETS 16 |
#define | BKTHOMPS_U_MAP_RESIZE_AT 0.75 |
#define | BKTHOMPS_U_MAP_RESIZE_RATIO 2 |
Functions | |
unordered_map | unordered_map_init (const size_t key_size, const size_t value_size, unsigned long(*hash)(const void *const), int(*comparator)(const void *const, const void *const)) |
bk_err | unordered_map_rehash (unordered_map me) |
size_t | unordered_map_size (unordered_map me) |
bk_bool | unordered_map_is_empty (unordered_map me) |
bk_err | unordered_map_put (unordered_map me, void *const key, void *const value) |
bk_bool | unordered_map_get (void *const value, unordered_map me, void *const key) |
bk_bool | unordered_map_contains (unordered_map me, void *const key) |
bk_bool | unordered_map_remove (unordered_map me, void *const key) |
int | unordered_map_clear (unordered_map me) |
unordered_map | unordered_map_destroy (unordered_map me) |
#define BKTHOMPS_U_MAP_RESIZE_AT 0.75 |
#define BKTHOMPS_U_MAP_RESIZE_RATIO 2 |
#define BKTHOMPS_U_MAP_STARTING_BUCKETS 16 |
int unordered_map_clear | ( | unordered_map | me | ) |
Clears the key-value pairs from the unordered map.
me | the unordered map to clear |
bk_bool unordered_map_contains | ( | unordered_map | me, |
void *const | key | ||
) |
Determines if the unordered map contains the specified key. The pointer to the key being passed in should point to the key type which this unordered map holds. For example, if this unordered map holds key integers, the key pointer should be a pointer to an integer. Since the key is being copied, the pointer only has to be valid when this function is called.
me | the unordered map to check for the key |
key | the key to check |
unordered_map unordered_map_destroy | ( | unordered_map | me | ) |
Frees the unordered map memory. Performing further operations after calling this function results in undefined behavior. Freeing NULL is legal, and causes no operation to be performed.
me | the unordered map to free from memory |
bk_bool unordered_map_get | ( | void *const | value, |
unordered_map | me, | ||
void *const | key | ||
) |
Gets the value associated with a key in the unordered map. The pointer to the key being passed in and the value being obtained should point to the key and value types which this unordered map holds. For example, if this unordered map holds integer keys and values, the key and value pointers should be a pointer to an integer. Since the key and value are being copied, the pointer only has to be valid when this function is called.
value | the value to copy to |
me | the unordered map to get from |
key | the key to search for |
unordered_map unordered_map_init | ( | const size_t | key_size, |
const size_t | value_size, | ||
unsigned long(*)(const void *const) | hash, | ||
int(*)(const void *const, const void *const) | comparator | ||
) |
Initializes an unordered map.
key_size | the size of each key in the unordered map; must be positive |
value_size | the size of each value in the unordered map; must be positive |
hash | the hash function which computes the hash from the key; must not be NULL |
comparator | the comparator function which compares two keys; must not be NULL |
bk_bool unordered_map_is_empty | ( | unordered_map | me | ) |
Determines whether or not the unordered map is empty.
me | the unordered map to check |
bk_err unordered_map_put | ( | unordered_map | me, |
void *const | key, | ||
void *const | value | ||
) |
Adds a key-value pair to the unordered map. If the unordered map already contains the key, the value is updated to the new value. The pointer to the key and value being passed in should point to the key and value type which this unordered map holds. For example, if this unordered map holds integer keys and values, the key and value pointer should be a pointer to an integer. Since the key and value are being copied, the pointer only has to be valid when this function is called.
me | the unordered map to add to |
key | the key to add |
value | the value to add |
bk_err unordered_map_rehash | ( | unordered_map | me | ) |
Rehashes all the keys in the unordered map. Used when storing references and changing the keys. This should rarely be used.
me | the unordered map to rehash |
bk_bool unordered_map_remove | ( | unordered_map | me, |
void *const | key | ||
) |
Removes the key-value pair from the unordered map if it contains it. The pointer to the key being passed in should point to the key type which this unordered map holds. For example, if this unordered map holds key integers, the key pointer should be a pointer to an integer. Since the key is being copied, the pointer only has to be valid when this function is called.
me | the unordered map to remove a key from |
key | the key to remove |
size_t unordered_map_size | ( | unordered_map | me | ) |
Gets the size of the unordered map.
me | the unordered map to check |