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

Functions

unordered_set unordered_set_init (size_t key_size, unsigned long(*hash)(const void *const key), int(*comparator)(const void *const one, const void *const two))
 
bk_err unordered_set_rehash (unordered_set me)
 
size_t unordered_set_size (unordered_set me)
 
bk_bool unordered_set_is_empty (unordered_set me)
 
bk_err unordered_set_put (unordered_set me, void *key)
 
bk_bool unordered_set_contains (unordered_set me, void *key)
 
bk_bool unordered_set_remove (unordered_set me, void *key)
 
bk_err unordered_set_clear (unordered_set me)
 
unordered_set unordered_set_destroy (unordered_set me)
 

Typedef Documentation

◆ unordered_set

typedef struct internal_unordered_set* unordered_set

The unordered_set data structure, which is a collection of unique keys, hashed by keys.

Function Documentation

◆ unordered_set_clear()

bk_err unordered_set_clear ( unordered_set  me)

Clears the keys from the unordered set.

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

◆ unordered_set_contains()

bk_bool unordered_set_contains ( unordered_set  me,
void *const  key 
)

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

◆ unordered_set_destroy()

unordered_set unordered_set_destroy ( unordered_set  me)

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

◆ unordered_set_init()

unordered_set unordered_set_init ( size_t  key_size,
unsigned long(*)(const void *const key)  hash,
int(*)(const void *const one, const void *const two)  comparator 
)

◆ unordered_set_is_empty()

bk_bool unordered_set_is_empty ( unordered_set  me)

Determines whether or not the unordered set is empty.

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

◆ unordered_set_put()

bk_err unordered_set_put ( unordered_set  me,
void *const  key 
)

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

◆ unordered_set_rehash()

bk_err unordered_set_rehash ( unordered_set  me)

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

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

◆ unordered_set_remove()

bk_bool unordered_set_remove ( unordered_set  me,
void *const  key 
)

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

◆ unordered_set_size()

size_t unordered_set_size ( unordered_set  me)

Gets the size of the unordered set.

Parameters
methe unordered set to check
Returns
the size of the unordered set