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.
multiset.c File Reference
#include <string.h>
#include "include/multiset.h"
Include dependency graph for multiset.c:

Functions

multiset multiset_init (const size_t key_size, int(*const comparator)(const void *const, const void *const))
 
size_t multiset_size (multiset me)
 
bk_bool multiset_is_empty (multiset me)
 
bk_bool multiset_put (multiset me, void *const key)
 
size_t multiset_count (multiset me, void *const key)
 
bk_bool multiset_contains (multiset me, void *const key)
 
bk_bool multiset_remove (multiset me, void *const key)
 
bk_bool multiset_remove_all (multiset me, void *const key)
 
void * multiset_first (multiset me)
 
void * multiset_last (multiset me)
 
void * multiset_lower (multiset me, void *const key)
 
void * multiset_higher (multiset me, void *const key)
 
void * multiset_floor (multiset me, void *const key)
 
void * multiset_ceiling (multiset me, void *const key)
 
void multiset_clear (multiset me)
 
multiset multiset_destroy (multiset me)
 

Function Documentation

◆ multiset_ceiling()

void* multiset_ceiling ( multiset  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-set 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

◆ multiset_clear()

void multiset_clear ( multiset  me)

Clears the keys from the multiset.

Parameters
methe multi-set to clear

◆ multiset_contains()

bk_bool multiset_contains ( multiset  me,
void *const  key 
)

Determines if the multi-set contains the specified key. The pointer to the key being passed in should point to the key type which this multi-set holds. For example, if this multi-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.

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

◆ multiset_count()

size_t multiset_count ( multiset  me,
void *const  key 
)

Determines the count of a specific key in the multi-set. The pointer to the key being passed in should point to the key type which this multi-set holds. For example, if this multi-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.

Parameters
methe multi-set to check for the count
keythe key to check
Returns
the count of a specific key in the multi-set

◆ multiset_destroy()

multiset multiset_destroy ( multiset  me)

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

◆ multiset_first()

void* multiset_first ( multiset  me)

Returns the first (lowest) key in this multi-set. 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-set to get the key from
Returns
the lowest key in this multi-set, or NULL if it is empty

◆ multiset_floor()

void* multiset_floor ( multiset  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-set 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

◆ multiset_higher()

void* multiset_higher ( multiset  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-set 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

◆ multiset_init()

multiset multiset_init ( const size_t  key_size,
int(*)(const void *const, const void *const)  comparator 
)

Initializes a multi-set.

Parameters
key_sizethe size of each element in the multi-set; must be positive
comparatorthe comparator function used for key ordering; must not be NULL
Returns
the newly-initialized multi-set, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error

◆ multiset_is_empty()

bk_bool multiset_is_empty ( multiset  me)

Determines whether or not the multi-set is empty.

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

◆ multiset_last()

void* multiset_last ( multiset  me)

Returns the last (highest) key in this multi-set. 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-set to get the key from
Returns
the highest key in this multi-set, or NULL if it is empty

◆ multiset_lower()

void* multiset_lower ( multiset  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-set 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

◆ multiset_put()

bk_bool multiset_put ( multiset  me,
void *const  key 
)

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

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

◆ multiset_remove()

bk_bool multiset_remove ( multiset  me,
void *const  key 
)

Removes a key from the multi-set if it contains it. The pointer to the key being passed in should point to the key type which this multi-set holds. For example, if this multi-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.

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

◆ multiset_remove_all()

bk_bool multiset_remove_all ( multiset  me,
void *const  key 
)

Removes all the occurrences of a specified key in the multi-set. The pointer to the key being passed in should point to the key type which this multi-set holds. For example, if this multi-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.

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

◆ multiset_size()

size_t multiset_size ( multiset  me)

Gets the size of the multi-set.

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