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

Functions

set set_init (const size_t key_size, int(*const comparator)(const void *const, const void *const))
 
size_t set_size (set me)
 
bk_bool set_is_empty (set me)
 
bk_err set_put (set me, void *const key)
 
bk_bool set_contains (set me, void *const key)
 
bk_err set_remove (set me, void *const key)
 
void * set_first (set me)
 
void * set_last (set me)
 
void * set_lower (set me, void *const key)
 
void * set_higher (set me, void *const key)
 
void * set_floor (set me, void *const key)
 
void * set_ceiling (set me, void *const key)
 
void set_clear (set me)
 
set set_destroy (set me)
 

Function Documentation

◆ set_ceiling()

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

◆ set_clear()

void set_clear ( set  me)

Clears the keys from the set.

Parameters
methe set to clear

◆ set_contains()

bk_bool set_contains ( set  me,
void *const  key 
)

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

◆ set_destroy()

set set_destroy ( set  me)

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

◆ set_first()

void* set_first ( set  me)

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

◆ set_floor()

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

◆ set_higher()

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

◆ set_init()

set set_init ( const size_t  key_size,
int(*)(const void *const, const void *const)  comparator 
)

Initializes a set.

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

◆ set_is_empty()

bk_bool set_is_empty ( set  me)

Determines whether or not the set is empty.

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

◆ set_last()

void* set_last ( set  me)

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

◆ set_lower()

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

◆ set_put()

bk_err set_put ( set  me,
void *const  key 
)

Adds a key to the set if the set does not already contain it. The pointer to the key being passed in should point to the key type which this set holds. For example, if this 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 set to add to
keythe key to add
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ set_remove()

bk_err set_remove ( set  me,
void *const  key 
)

Removes the key from the set if it contains it. The pointer to the key being passed in should point to the key type which this set holds. For example, if this 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 set to remove an key from
keythe key to remove
Returns
BK_TRUE if the set contained the key, otherwise BK_FALSE

◆ set_size()

size_t set_size ( set  me)

Gets the size of the set.

Parameters
methe set to check
Returns
the size of the set