Go to the source code of this file.
|
typedef struct internal_deque * | deque |
|
|
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) |
|
◆ deque
typedef struct internal_deque* deque |
The deque data structure, which is a doubly-ended queue.
◆ 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
-
me | the deque to add data to |
arr | the array to copy data from |
size | the 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()
Clears the deque and sets it to the original state from initialization.
- Parameters
-
- 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
-
arr | the initialized array to copy the deque to |
me | the deque to copy to the array |
◆ deque_destroy()
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
-
- 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
-
data | the data to set |
me | the deque to set the value of |
index | the index to set at |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ deque_get_first()
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
-
data | the data to set |
me | the deque to set the value of |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ deque_get_last()
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
-
data | the data to set |
me | the 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_size | the 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()
Determines if the deque is empty. It is empty if it has no elements.
- Parameters
-
me | the deque to check if empty |
- Returns
- BK_TRUE if the deque is empty, otherwise BK_FALSE
◆ deque_pop_back()
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
-
data | the value to copy to |
me | the deque to remove from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ deque_pop_front()
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
-
data | the value to copy to |
me | the deque to remove from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ deque_push_back()
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
-
me | the deque to add an element to |
data | the 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()
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
-
me | the deque to add an element to |
data | the 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
-
me | the deque to set the value of |
index | the index to set at |
data | the data to set |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ deque_set_first()
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
-
me | the deque to set the value of |
data | the data to set |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ deque_set_last()
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
-
me | the deque to set the value of |
data | the 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
-
me | the deque to check the size of |
- Returns
- the size of the deque
◆ deque_trim()
Trims the deque so that it does not use memory which does not need to be used.
- Parameters
-
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory