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.
unordered_multimap.h File Reference
#include "_bk_defines.h"
Include dependency graph for unordered_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_unordered_multimap * unordered_multimap
 

Functions

unordered_multimap unordered_multimap_init (size_t key_size, size_t value_size, unsigned long(*hash)(const void *const key), int(*key_comparator)(const void *const one, const void *const two), int(*value_comparator)(const void *const one, const void *const two))
 
bk_err unordered_multimap_rehash (unordered_multimap me)
 
size_t unordered_multimap_size (unordered_multimap me)
 
bk_bool unordered_multimap_is_empty (unordered_multimap me)
 
bk_err unordered_multimap_put (unordered_multimap me, void *key, void *value)
 
void unordered_multimap_get_start (unordered_multimap me, void *key)
 
bk_bool unordered_multimap_get_next (void *value, unordered_multimap me)
 
size_t unordered_multimap_count (unordered_multimap me, void *key)
 
bk_bool unordered_multimap_contains (unordered_multimap me, void *key)
 
bk_bool unordered_multimap_remove (unordered_multimap me, void *key, void *value)
 
bk_bool unordered_multimap_remove_all (unordered_multimap me, void *key)
 
bk_err unordered_multimap_clear (unordered_multimap me)
 
unordered_multimap unordered_multimap_destroy (unordered_multimap me)
 

Typedef Documentation

◆ unordered_multimap

typedef struct internal_unordered_multimap* unordered_multimap

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

Function Documentation

◆ unordered_multimap_clear()

bk_err unordered_multimap_clear ( unordered_multimap  me)

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

Parameters
methe unordered multi-map to clear
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ unordered_multimap_contains()

bk_bool unordered_multimap_contains ( unordered_multimap  me,
void *const  key 
)

Determines if the unordered multi-map contains the specified key. The pointer to the key being passed in should point to the key type which this unordered multi-map holds. For example, if this unordered 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 unordered multi-map to check for the key
keythe key to check
Returns
BK_TRUE if the unordered multi-map contained the key, otherwise BK_FALSE

◆ unordered_multimap_count()

size_t unordered_multimap_count ( unordered_multimap  me,
void *const  key 
)

Determines the number of times the key appears in the unordered multi-map. The pointer to the key being passed in should point to the key type which this unordered multi-map holds. For example, if this unordered 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 unordered multi-map to check for the key
keythe key to check
Returns
the number of times the key appears in the unordered multi-map

◆ unordered_multimap_destroy()

unordered_multimap unordered_multimap_destroy ( unordered_multimap  me)

Frees the unordered 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 unordered multi-map to free from memory
Returns
NULL

◆ unordered_multimap_get_next()

bk_bool unordered_multimap_get_next ( void *const  value,
unordered_multimap  me 
)

Iterates over the values for the specified key. Must be called after starting the iterator. The unordered 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 unordered multi-map holds. For example, if this unordered 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 unordered multi-map to iterate over
Returns
BK_TRUE if there exist more values for the key which is being iterated over, otherwise BK_FALSE

◆ unordered_multimap_get_start()

void unordered_multimap_get_start ( unordered_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 unordered multi-map must not be mutated. The pointer to the key being passed in should point to the key type which this unordered multi-map holds. For example, if this unordered 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 unordered multi-map to start the iterator for
keythe key to start the iterator for

◆ unordered_multimap_init()

unordered_multimap unordered_multimap_init ( size_t  key_size,
size_t  value_size,
unsigned long(*)(const void *const key)  hash,
int(*)(const void *const one, const void *const two)  key_comparator,
int(*)(const void *const one, const void *const two)  value_comparator 
)

◆ unordered_multimap_is_empty()

bk_bool unordered_multimap_is_empty ( unordered_multimap  me)

Determines whether or not the unordered multi-map is empty.

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

◆ unordered_multimap_put()

bk_err unordered_multimap_put ( unordered_multimap  me,
void *const  key,
void *const  value 
)

Adds a key-value pair to the unordered multi-map. The pointer to the key and value being passed in should point to the key and value type which this unordered multi-map holds. For example, if this unordered 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 unordered 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

◆ unordered_multimap_rehash()

bk_err unordered_multimap_rehash ( unordered_multimap  me)

Rehashes all the keys in the unordered multi-map. Used when storing references and changing the keys. This should rarely be used.

Parameters
methe unordered multi-map to rehash
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ unordered_multimap_remove()

bk_bool unordered_multimap_remove ( unordered_multimap  me,
void *const  key,
void *const  value 
)

Removes the key-value pair from the unordered 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 unordered multi-map holds. For example, if this unordered 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 unordered multi-map to remove a key from
keythe key to remove
valuethe value to remove
Returns
BK_TRUE if the unordered multi-map contained the key, otherwise BK_FALSE

◆ unordered_multimap_remove_all()

bk_bool unordered_multimap_remove_all ( unordered_multimap  me,
void *const  key 
)

Removes all the key-value pairs from the unordered multi-map specified by the key. The pointer to the key being passed in should point to the key type which this unordered multi-map holds. For example, if this unordered 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 unordered multi-map to remove a key-value pair from
keythe key to remove
Returns
BK_TRUE if the unordered multi-map contained the key, otherwise BK_FALSE

◆ unordered_multimap_size()

size_t unordered_multimap_size ( unordered_multimap  me)

Gets the size of the unordered multi-map.

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