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.
multimap.h File Reference
#include "_bk_defines.h"
Include dependency graph for multimap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct internal_multimap * multimap
 

Functions

multimap multimap_init (size_t key_size, size_t value_size, int(*key_comparator)(const void *const one, const void *const two), int(*value_comparator)(const void *const one, const void *const two))
 
size_t multimap_size (multimap me)
 
bk_bool multimap_is_empty (multimap me)
 
bk_err multimap_put (multimap me, void *key, void *value)
 
void multimap_get_start (multimap me, void *key)
 
bk_bool multimap_get_next (void *value, multimap me)
 
size_t multimap_count (multimap me, void *key)
 
bk_bool multimap_contains (multimap me, void *key)
 
bk_bool multimap_remove (multimap me, void *key, void *value)
 
bk_bool multimap_remove_all (multimap me, void *key)
 
void * multimap_first (multimap me)
 
void * multimap_last (multimap me)
 
void * multimap_lower (multimap me, void *key)
 
void * multimap_higher (multimap me, void *key)
 
void * multimap_floor (multimap me, void *key)
 
void * multimap_ceiling (multimap me, void *key)
 
void multimap_clear (multimap me)
 
multimap multimap_destroy (multimap me)
 

Typedef Documentation

◆ multimap

typedef struct internal_multimap* multimap

The multimap data structure, which is a collection of key-value pairs, sorted by keys.

Function Documentation

◆ multimap_ceiling()

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.

Parameters
methe multi-map to get the ceiling key from
keythe key to use for comparison
Returns
the key which is the ceiling, or NULL if it does not exist

◆ multimap_clear()

void multimap_clear ( multimap  me)

Clears the key-value pairs from the multi-map.

Parameters
methe multi-map to clear

◆ multimap_contains()

bk_bool multimap_contains ( multimap  me,
void *const  key 
)

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.

Parameters
methe multi-map to check for the key
keythe key to check
Returns
BK_TRUE if the multi-map contained the key, otherwise BK_FALSE

◆ multimap_count()

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.

Parameters
methe multi-map to check for the key
keythe key to check
Returns
the number of times the key appears in the multi-map

◆ multimap_destroy()

multimap multimap_destroy ( multimap  me)

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.

Parameters
methe multi-map to free from memory
Returns
NULL

◆ multimap_first()

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.

Parameters
methe multi-map to get the key from
Returns
the lowest key in this multi-map, or NULL if it is empty

◆ multimap_floor()

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.

Parameters
methe multi-map to get the floor key from
keythe key to use for comparison
Returns
the key which is the floor, or NULL if it does not exist

◆ multimap_get_next()

bk_bool multimap_get_next ( void *const  value,
multimap  me 
)

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.

Parameters
valuethe value to be copied to from iteration
methe multi-map to iterate over
Returns
BK_TRUE if there exist more values for the key which is being iterated over, otherwise BK_FALSE

◆ multimap_get_start()

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.

Parameters
methe multi-map to start the iterator for
keythe key to start the iterator for

◆ multimap_higher()

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.

Parameters
methe multi-map to get the higher key from
keythe key to use for comparison
Returns
the key which is strictly higher, or NULL if it does not exist

◆ multimap_init()

multimap multimap_init ( size_t  key_size,
size_t  value_size,
int(*)(const void *const one, const void *const two)  key_comparator,
int(*)(const void *const one, const void *const two)  value_comparator 
)

◆ multimap_is_empty()

bk_bool multimap_is_empty ( multimap  me)

Determines whether or not the multi-map is empty.

Parameters
methe multi-map to check
Returns
BK_TRUE if the multi-map is empty, otherwise BK_FALSE

◆ multimap_last()

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.

Parameters
methe multi-map to get the key from
Returns
the highest key in this multi-map, or NULL if it is empty

◆ multimap_lower()

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.

Parameters
methe multi-map to get the lower key from
keythe key to use for comparison
Returns
the key which is strictly lower, or NULL if it does not exist

◆ multimap_put()

bk_err multimap_put ( multimap  me,
void *const  key,
void *const  value 
)

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.

Parameters
methe multi-map to add to
keythe key to add
valuethe value to add
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ multimap_remove()

bk_bool multimap_remove ( multimap  me,
void *const  key,
void *const  value 
)

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.

Parameters
methe multi-map to remove a key from
keythe key to remove
valuethe value to remove
Returns
BK_TRUE if the multi-map contained the key, otherwise BK_FALSE

◆ multimap_remove_all()

bk_bool multimap_remove_all ( multimap  me,
void *const  key 
)

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.

Parameters
methe multi-map to remove a key-value pair from
keythe key to remove
Returns
BK_TRUE if the multi-map contained the key, otherwise BK_FALSE

◆ multimap_size()

size_t multimap_size ( multimap  me)

Gets the size of the multi-map.

Parameters
methe multi-map to check
Returns
the size of the multi-map