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

Functions

queue queue_init (size_t data_size)
 
size_t queue_size (queue me)
 
bk_bool queue_is_empty (queue me)
 
bk_err queue_trim (queue me)
 
void queue_copy_to_array (void *arr, queue me)
 
bk_err queue_push (queue me, void *data)
 
bk_bool queue_pop (void *data, queue me)
 
bk_bool queue_front (void *data, queue me)
 
bk_bool queue_back (void *data, queue me)
 
bk_err queue_clear (queue me)
 
queue queue_destroy (queue me)
 

Typedef Documentation

◆ queue

typedef struct internal_deque* queue

The queue data structure, which adapts a container to provide a queue (first-in first-out). Adapts the deque container.

Function Documentation

◆ queue_back()

bk_bool queue_back ( void *const  data,
queue  me 
)

Gets the back element of the queue. The pointer to the data being obtained should point to the data type which this queue holds. For example, if this queue 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 copy of the back element of the queue
methe queue to copy from
Returns
BK_TRUE if the queue contained elements, otherwise BK_FALSE

◆ queue_clear()

bk_err queue_clear ( queue  me)

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

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

◆ queue_copy_to_array()

void queue_copy_to_array ( void *const  arr,
queue  me 
)

Copies the queue to an array. Since it is a copy, the array may be modified without causing side effects to the queue data structure. Memory is not allocated, thus the array being used for the copy must be allocated before this function is called.

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

◆ queue_destroy()

queue queue_destroy ( queue  me)

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

Parameters
methe queue to destroy
Returns
NULL

◆ queue_front()

bk_bool queue_front ( void *const  data,
queue  me 
)

Gets the front element of the queue. The pointer to the data being obtained should point to the data type which this queue holds. For example, if this queue 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 copy of the front element of the queue
methe queue to copy from
Returns
BK_TRUE if the queue contained elements, otherwise BK_FALSE

◆ queue_init()

queue queue_init ( const size_t  data_size)

Initializes a queue.

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

◆ queue_is_empty()

bk_bool queue_is_empty ( queue  me)

Determines if the queue is empty. The queue is empty if it contains no elements.

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

◆ queue_pop()

bk_bool queue_pop ( void *const  data,
queue  me 
)

Removes the next element in the queue and copies the data. The pointer to the data being obtained should point to the data type which this queue holds. For example, if this queue 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 have copied from the queue
methe queue to pop the next element from
Returns
BK_TRUE if the queue contained elements, otherwise BK_FALSE

◆ queue_push()

bk_err queue_push ( queue  me,
void *const  data 
)

Adds an element to the queue. The pointer to the data being passed in should point to the data type which this queue holds. For example, if this queue 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 queue to add an element to
datathe data to add to the queue
Returns
BK_OK if no error
-BK_ENOMEM if out of memory
-BK_ERANGE if size has reached representable limit

◆ queue_size()

size_t queue_size ( queue  me)

Determines the size of the queue.

Parameters
methe queue to get size of
Returns
the queue size

◆ queue_trim()

bk_err queue_trim ( queue  me)

Frees the unused memory in the queue.

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