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

Macros

#define BKTHOMPS_U_MULTISET_STARTING_BUCKETS   16
 
#define BKTHOMPS_U_MULTISET_RESIZE_AT   0.75
 
#define BKTHOMPS_U_MULTISET_RESIZE_RATIO   2
 

Functions

unordered_multiset unordered_multiset_init (const size_t key_size, unsigned long(*hash)(const void *const), int(*comparator)(const void *const, const void *const))
 
bk_err unordered_multiset_rehash (unordered_multiset me)
 
size_t unordered_multiset_size (unordered_multiset me)
 
bk_bool unordered_multiset_is_empty (unordered_multiset me)
 
bk_err unordered_multiset_put (unordered_multiset me, void *const key)
 
size_t unordered_multiset_count (unordered_multiset me, void *const key)
 
bk_bool unordered_multiset_contains (unordered_multiset me, void *const key)
 
bk_bool unordered_multiset_remove (unordered_multiset me, void *const key)
 
bk_bool unordered_multiset_remove_all (unordered_multiset me, void *const key)
 
bk_err unordered_multiset_clear (unordered_multiset me)
 
unordered_multiset unordered_multiset_destroy (unordered_multiset me)
 

Macro Definition Documentation

◆ BKTHOMPS_U_MULTISET_RESIZE_AT

#define BKTHOMPS_U_MULTISET_RESIZE_AT   0.75

◆ BKTHOMPS_U_MULTISET_RESIZE_RATIO

#define BKTHOMPS_U_MULTISET_RESIZE_RATIO   2

◆ BKTHOMPS_U_MULTISET_STARTING_BUCKETS

#define BKTHOMPS_U_MULTISET_STARTING_BUCKETS   16

Function Documentation

◆ unordered_multiset_clear()

bk_err unordered_multiset_clear ( unordered_multiset  me)

Clears the keys from the unordered multi-set.

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

◆ unordered_multiset_contains()

bk_bool unordered_multiset_contains ( unordered_multiset  me,
void *const  key 
)

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

◆ unordered_multiset_count()

size_t unordered_multiset_count ( unordered_multiset  me,
void *const  key 
)

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

◆ unordered_multiset_destroy()

unordered_multiset unordered_multiset_destroy ( unordered_multiset  me)

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

◆ unordered_multiset_init()

unordered_multiset unordered_multiset_init ( const size_t  key_size,
unsigned long(*)(const void *const)  hash,
int(*)(const void *const, const void *const)  comparator 
)

Initializes an unordered multi-set.

Parameters
key_sizethe size of each key in the unordered multi-set; must be positive
hashthe hash function which computes the hash from the key; must not be NULL
comparatorthe comparator function which compares two keys; must not be NULL
Returns
the newly-initialized unordered multi-set, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error

◆ unordered_multiset_is_empty()

bk_bool unordered_multiset_is_empty ( unordered_multiset  me)

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

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

◆ unordered_multiset_put()

bk_err unordered_multiset_put ( unordered_multiset  me,
void *const  key 
)

Adds an element to the unordered multi-set. The pointer to the key being passed in should point to the key type which this unordered 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 unordered multi-set to add to
keythe element to add
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ unordered_multiset_rehash()

bk_err unordered_multiset_rehash ( unordered_multiset  me)

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

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

◆ unordered_multiset_remove()

bk_bool unordered_multiset_remove ( unordered_multiset  me,
void *const  key 
)

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

◆ unordered_multiset_remove_all()

bk_bool unordered_multiset_remove_all ( unordered_multiset  me,
void *const  key 
)

Removes all the keys specified by the key from an unordered multi-set if it contains the 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 unordered multi-set to remove a key from
keythe key to remove
Returns
BK_TRUE if the unordered multi-set contained the key, otherwise BK_FALSE

◆ unordered_multiset_size()

size_t unordered_multiset_size ( unordered_multiset  me)

Gets the size of the unordered multi-set.

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