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.
deque.h File Reference
#include "_bk_defines.h"
Include dependency graph for deque.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct internal_deque * deque
 

Functions

deque deque_init (size_t data_size)
 
size_t deque_size (deque me)
 
bk_bool deque_is_empty (deque me)
 
bk_err deque_trim (deque me)
 
void deque_copy_to_array (void *arr, deque me)
 
bk_err deque_add_all (deque me, void *arr, size_t size)
 
bk_err deque_push_front (deque me, void *data)
 
bk_err deque_push_back (deque me, void *data)
 
bk_err deque_pop_front (void *data, deque me)
 
bk_err deque_pop_back (void *data, deque me)
 
bk_err deque_set_first (deque me, void *data)
 
bk_err deque_set_at (deque me, size_t index, void *data)
 
bk_err deque_set_last (deque me, void *data)
 
bk_err deque_get_first (void *data, deque me)
 
bk_err deque_get_at (void *data, deque me, size_t index)
 
bk_err deque_get_last (void *data, deque me)
 
bk_err deque_clear (deque me)
 
deque deque_destroy (deque me)
 

Typedef Documentation

◆ deque

typedef struct internal_deque* deque

The deque data structure, which is a doubly-ended queue.

Function Documentation

◆ deque_add_all()

bk_err deque_add_all ( deque  me,
void *const  arr,
const size_t  size 
)

Copies elements from an array to the deque. The size specifies the number of elements to copy, starting from the beginning of the array. The size must be less than or equal to the size of the array.

Parameters
methe deque to add data to
arrthe array to copy data from
sizethe number of elements to copy
Returns
BK_OK if no error
-BK_ENOMEM if out of memory
-BK_ERANGE if size has reached representable limit

◆ deque_clear()

bk_err deque_clear ( deque  me)

Clears the deque and sets it to the original state from initialization.

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

◆ deque_copy_to_array()

void deque_copy_to_array ( void *const  arr,
deque  me 
)

Copies the deque to an array. Since it is a copy, the array may be modified without causing side effects to the deque data structure. Memory is not allocated, thus the array being used for the copy must be allocated before this function is called. The size of the deque should be queried prior to calling this function, which also serves as the size of the newly-copied array.

Parameters
arrthe initialized array to copy the deque to
methe deque to copy to the array

◆ deque_destroy()

deque deque_destroy ( deque  me)

Destroys the deque. Performing further operations after calling this function results in undefined behavior. Freeing NULL is legal, and causes no operation to be performed.

Parameters
methe deque to destroy
Returns
NULL

◆ deque_get_at()

bk_err deque_get_at ( void *const  data,
deque  me,
size_t  index 
)

Gets the value of the deque at the specified index. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.

Parameters
datathe data to set
methe deque to set the value of
indexthe index to set at
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_get_first()

bk_err deque_get_first ( void *const  data,
deque  me 
)

Gets the first value of the deque. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.

Parameters
datathe data to set
methe deque to set the value of
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_get_last()

bk_err deque_get_last ( void *const  data,
deque  me 
)

Gets the last value of the deque. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.

Parameters
datathe data to set
methe deque to set the value of
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_init()

deque deque_init ( const size_t  data_size)

Initializes a deque.

Parameters
data_sizethe size of each element in the deque; must be positive
Returns
the newly-initialized deque, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error

◆ deque_is_empty()

bk_bool deque_is_empty ( deque  me)

Determines if the deque is empty. It is empty if it has no elements.

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

◆ deque_pop_back()

bk_err deque_pop_back ( void *const  data,
deque  me 
)

Removes the back element from the deque and copies it to a data value. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.

Parameters
datathe value to copy to
methe deque to remove from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_pop_front()

bk_err deque_pop_front ( void *const  data,
deque  me 
)

Removes the front element from the deque and copies it to a data value. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.

Parameters
datathe value to copy to
methe deque to remove from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_push_back()

bk_err deque_push_back ( deque  me,
void *const  data 
)

Adds an element to the back of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.

Parameters
methe deque to add an element to
datathe element to add
Returns
BK_OK if no error
-BK_ENOMEM if out of memory
-BK_ERANGE if size has reached representable limit

◆ deque_push_front()

bk_err deque_push_front ( deque  me,
void *const  data 
)

Adds an element to the front of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.

Parameters
methe deque to add an element to
datathe element to add
Returns
BK_OK if no error
-BK_ENOMEM if out of memory
-BK_ERANGE if size has reached representable limit

◆ deque_set_at()

bk_err deque_set_at ( deque  me,
size_t  index,
void *const  data 
)

Sets the value of the deque at the specified index. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.

Parameters
methe deque to set the value of
indexthe index to set at
datathe data to set
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_set_first()

bk_err deque_set_first ( deque  me,
void *const  data 
)

Sets the first value of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.

Parameters
methe deque to set the value of
datathe data to set
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_set_last()

bk_err deque_set_last ( deque  me,
void *const  data 
)

Sets the last value of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.

Parameters
methe deque to set the value of
datathe data to set
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ deque_size()

size_t deque_size ( deque  me)

Determines the size of the deque. The size is the number of data spaces being used. The size starts at zero, and every time an element is added, it increases by one.

Parameters
methe deque to check the size of
Returns
the size of the deque

◆ deque_trim()

bk_err deque_trim ( deque  me)

Trims the deque so that it does not use memory which does not need to be used.

Parameters
methe deque to trim
Returns
BK_OK if no error
-BK_ENOMEM if out of memory