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.
|
Functions | |
multimap | multimap_init (const size_t key_size, const size_t value_size, int(*const key_comparator)(const void *const, const void *const), int(*const value_comparator)(const void *const, const void *const)) |
size_t | multimap_size (multimap me) |
bk_bool | multimap_is_empty (multimap me) |
bk_err | multimap_put (multimap me, void *const key, void *const value) |
void | multimap_get_start (multimap me, void *const key) |
bk_bool | multimap_get_next (void *const value, multimap me) |
size_t | multimap_count (multimap me, void *const key) |
bk_bool | multimap_contains (multimap me, void *const key) |
bk_bool | multimap_remove (multimap me, void *const key, void *const value) |
bk_bool | multimap_remove_all (multimap me, void *const key) |
void * | multimap_first (multimap me) |
void * | multimap_last (multimap me) |
void * | multimap_lower (multimap me, void *const key) |
void * | multimap_higher (multimap me, void *const key) |
void * | multimap_floor (multimap me, void *const key) |
void * | multimap_ceiling (multimap me, void *const key) |
void | multimap_clear (multimap me) |
multimap | multimap_destroy (multimap me) |
void* multimap_ceiling | ( | multimap | me, |
void *const | key | ||
) |
Returns the key which is the ceiling of the comparison key. Meaning that the the lowest key which is higher or equal to the key used for comparison is returned.
me | the multi-map to get the ceiling key from |
key | the key to use for comparison |
void multimap_clear | ( | multimap | me | ) |
Clears the key-value pairs from the multi-map.
me | the multi-map to clear |
Determines if the multi-map contains the specified key. The pointer to the key being passed in should point to the key type which this multi-map holds. For example, if this multi-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 multi-map to check for the key |
key | the key to check |
size_t multimap_count | ( | multimap | me, |
void *const | key | ||
) |
Determines the number of times the key appears in the multi-map. The pointer to the key being passed in should point to the key type which this multi-map holds. For example, if this multi-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 multi-map to check for the key |
key | the key to check |
Frees the multi-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 multi-map to free from memory |
void* multimap_first | ( | multimap | me | ) |
Returns the first (lowest) key in this multi-map. The returned key is a pointer to the internally stored key, which should not be modified. Modifying it results in undefined behaviour.
me | the multi-map to get the key from |
void* multimap_floor | ( | multimap | me, |
void *const | key | ||
) |
Returns the key which is the floor of the comparison key. Meaning that the the highest key which is lower or equal to the key used for comparison is returned.
me | the multi-map to get the floor key from |
key | the key to use for comparison |
Iterates over the values for the specified key. Must be called after starting the iterator. The multi-map must not be mutated between start and iterations. The pointer to the value being obtained should point to the value type which this multi-map holds. For example, if this multi-map holds value integers, the value pointer should be a pointer to an integer. Since the value is being copied, the pointer only has to be valid when this function is called.
value | the value to be copied to from iteration |
me | the multi-map to iterate over |
void multimap_get_start | ( | multimap | me, |
void *const | key | ||
) |
Creates the iterator for the specified key. To iterate over the values, keep getting the next value. Between starting and iterations, the multi-map must not be mutated. The pointer to the key being passed in should point to the key type which this multi-map holds. For example, if this multi-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 multi-map to start the iterator for |
key | the key to start the iterator for |
void* multimap_higher | ( | multimap | me, |
void *const | key | ||
) |
Returns the key which is strictly higher than the comparison key. Meaning that the lowest key which is higher than the key used for comparison is returned.
me | the multi-map to get the higher key from |
key | the key to use for comparison |
multimap multimap_init | ( | const size_t | key_size, |
const size_t | value_size, | ||
int(*)(const void *const, const void *const) | key_comparator, | ||
int(*)(const void *const, const void *const) | value_comparator | ||
) |
Initializes a multi-map.
key_size | the size of each key in the multi-map; must be positive |
value_size | the size of each value in the multi-map; must be positive |
key_comparator | the key comparator function; must not be NULL |
value_comparator | the value comparator function; must not be NULL |
Determines whether or not the multi-map is empty.
me | the multi-map to check |
void* multimap_last | ( | multimap | me | ) |
Returns the last (highest) key in this multi-map. The returned key is a pointer to the internally stored key, which should not be modified. Modifying it results in undefined behaviour.
me | the multi-map to get the key from |
void* multimap_lower | ( | multimap | me, |
void *const | key | ||
) |
Returns the key which is strictly lower than the comparison key. Meaning that the highest key which is lower than the key used for comparison is returned.
me | the multi-map to get the lower key from |
key | the key to use for comparison |
Adds a key-value pair to the multi-map. If the multi-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 multi-map holds. For example, if this multi-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 multi-map to add to |
key | the key to add |
value | the value to add |
Removes the key-value pair from the multi-map if it contains it. The pointer to the key and value being passed in should point to the key and value type which this multi-map holds. For example, if this multi-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 multi-map to remove a key from |
key | the key to remove |
value | the value to remove |
Removes all the key-value pairs from the multi-map specified by the key. The pointer to the key being passed in should point to the key type which this multi-map holds. For example, if this multi-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 multi-map to remove a key-value pair from |
key | the key to remove |
size_t multimap_size | ( | multimap | me | ) |
Gets the size of the multi-map.
me | the multi-map to check |