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 | |
map | map_init (const size_t key_size, const size_t value_size, int(*const comparator)(const void *const, const void *const)) |
size_t | map_size (map me) |
bk_bool | map_is_empty (map me) |
bk_err | map_put (map me, void *const key, void *const value) |
bk_bool | map_get (void *const value, map me, void *const key) |
bk_bool | map_contains (map me, void *const key) |
bk_bool | map_remove (map me, void *const key) |
void * | map_first (map me) |
void * | map_last (map me) |
void * | map_lower (map me, void *const key) |
void * | map_higher (map me, void *const key) |
void * | map_floor (map me, void *const key) |
void * | map_ceiling (map me, void *const key) |
void | map_clear (map me) |
map | map_destroy (map me) |
void* map_ceiling | ( | map | 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 map to get the ceiling key from |
key | the key to use for comparison |
void map_clear | ( | map | me | ) |
Clears the key-value pairs from the map.
me | the map to clear |
Determines if the map contains the specified key. The pointer to the key being passed in should point to the key type which this map holds. For example, if this 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 map to check for the element |
key | the key to check |
Frees the 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 map to free from memory |
void* map_first | ( | map | me | ) |
Returns the first (lowest) key in this 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 map to get the key from |
void* map_floor | ( | map | 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 map to get the floor key from |
key | the key to use for comparison |
Gets the value associated with a key in the map. The pointer to the key being passed in and the value being obtained should point to the key and value types which this map holds. For example, if this 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 map to get from |
key | the key to search for |
void* map_higher | ( | map | 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 map to get the higher key from |
key | the key to use for comparison |
map map_init | ( | const size_t | key_size, |
const size_t | value_size, | ||
int(*)(const void *const, const void *const) | comparator | ||
) |
Initializes a map.
key_size | the size of each key in the map; must be positive |
value_size | the size of each value in the map; must be positive |
comparator | the comparator function used for key ordering; must not be NULL |
Determines whether or not the map is empty.
me | the map to check |
void* map_last | ( | map | me | ) |
Returns the last (highest) key in this 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 map to get the key from |
void* map_lower | ( | map | 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 map to get the lower key from |
key | the key to use for comparison |
Adds a key-value pair to the map. If the 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 map holds. For example, if this 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 map to add to |
key | the key to add |
value | the value to add |
Removes the key-value pair from the map if it contains it. The pointer to the key being passed in should point to the key type which this map holds. For example, if this 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 map to remove an element from |
key | the key to remove |
size_t map_size | ( | map | me | ) |
Gets the size of the map.
me | the map to check |