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_SET_STARTING_BUCKETS 16 |
#define | BKTHOMPS_U_SET_RESIZE_AT 0.75 |
#define | BKTHOMPS_U_SET_RESIZE_RATIO 2 |
Functions | |
unordered_set | unordered_set_init (const size_t key_size, unsigned long(*hash)(const void *const), int(*comparator)(const void *const, const void *const)) |
bk_err | unordered_set_rehash (unordered_set me) |
size_t | unordered_set_size (unordered_set me) |
bk_bool | unordered_set_is_empty (unordered_set me) |
int | unordered_set_put (unordered_set me, void *const key) |
int | unordered_set_contains (unordered_set me, void *const key) |
int | unordered_set_remove (unordered_set me, void *const key) |
int | unordered_set_clear (unordered_set me) |
unordered_set | unordered_set_destroy (unordered_set me) |
#define BKTHOMPS_U_SET_RESIZE_AT 0.75 |
#define BKTHOMPS_U_SET_RESIZE_RATIO 2 |
#define BKTHOMPS_U_SET_STARTING_BUCKETS 16 |
int unordered_set_clear | ( | unordered_set | me | ) |
Clears the keys from the unordered set.
me | the unordered set to clear |
int unordered_set_contains | ( | unordered_set | me, |
void *const | key | ||
) |
Determines if the unordered set contains the specified element. The pointer to the key being passed in should point to the key type which this unordered set holds. For example, if this unordered set 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 set to check for the element |
key | the element to check |
unordered_set unordered_set_destroy | ( | unordered_set | me | ) |
Frees the unordered set 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 set to free from memory |
unordered_set unordered_set_init | ( | const size_t | key_size, |
unsigned long(*)(const void *const) | hash, | ||
int(*)(const void *const, const void *const) | comparator | ||
) |
Initializes an unordered set.
key_size | the size of each key in the unordered set; 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_set_is_empty | ( | unordered_set | me | ) |
Determines whether or not the unordered set is empty.
me | the unordered set to check |
int unordered_set_put | ( | unordered_set | me, |
void *const | key | ||
) |
Adds an element to the unordered set if the unordered set does not already contain it. The pointer to the key being passed in should point to the key type which this unordered set holds. For example, if this unordered set 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 set to add to |
key | the element to add |
bk_err unordered_set_rehash | ( | unordered_set | me | ) |
Rehashes all the keys in the unordered set. Used when storing references and changing the keys. This should rarely be used.
me | the unordered set to rehash |
int unordered_set_remove | ( | unordered_set | me, |
void *const | key | ||
) |
Removes the key from the unordered set if it contains it. The pointer to the key being passed in should point to the key type which this unordered set holds. For example, if this unordered set 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 set to remove a key from |
key | the key to remove |
size_t unordered_set_size | ( | unordered_set | me | ) |
Gets the size of the unordered set.
me | the unordered set to check |