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

Go to the source code of this file.

Typedefs

typedef struct internal_forward_list * forward_list
 

Functions

forward_list forward_list_init (size_t data_size)
 
size_t forward_list_size (forward_list me)
 
bk_bool forward_list_is_empty (forward_list me)
 
void forward_list_copy_to_array (void *arr, forward_list me)
 
bk_err forward_list_add_all (forward_list me, void *arr, size_t size)
 
bk_err forward_list_add_first (forward_list me, void *data)
 
bk_err forward_list_add_at (forward_list me, size_t index, void *data)
 
bk_err forward_list_add_last (forward_list me, void *data)
 
bk_err forward_list_remove_first (forward_list me)
 
bk_err forward_list_remove_at (forward_list me, size_t index)
 
bk_err forward_list_remove_last (forward_list me)
 
bk_err forward_list_set_first (forward_list me, void *data)
 
bk_err forward_list_set_at (forward_list me, size_t index, void *data)
 
bk_err forward_list_set_last (forward_list me, void *data)
 
bk_err forward_list_get_first (void *data, forward_list me)
 
bk_err forward_list_get_at (void *data, forward_list me, size_t index)
 
bk_err forward_list_get_last (void *data, forward_list me)
 
void forward_list_clear (forward_list me)
 
forward_list forward_list_destroy (forward_list me)
 

Typedef Documentation

◆ forward_list

typedef struct internal_forward_list* forward_list

The forward_list data structure, which is a singly-linked list.

Function Documentation

◆ forward_list_add_all()

bk_err forward_list_add_all ( forward_list  me,
void *const  arr,
const size_t  size 
)

Copies elements from an array to the singly-linked list. 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 singly-linked list 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

◆ forward_list_add_at()

bk_err forward_list_add_at ( forward_list  me,
const size_t  index,
void *const  data 
)

Adds data at a specified index in the singly-linked list. The pointer to the data being passed in should point to the data type which this singly-linked list holds. For example, if this singly-linked list 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 singly-linked list to add data to
indexthe index to add the data at
datathe data to add to the singly-linked list
Returns
BK_OK if no error
-BK_ENOMEM if out of memory
-BK_EINVAL if invalid argument

◆ forward_list_add_first()

bk_err forward_list_add_first ( forward_list  me,
void *const  data 
)

Adds data at the first index in the singly-linked list. The pointer to the data being passed in should point to the data type which this singly-linked list holds. For example, if this singly-linked list 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 singly-linked list to add data to
datathe data to add to the singly-linked list
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ forward_list_add_last()

bk_err forward_list_add_last ( forward_list  me,
void *const  data 
)

Adds data at the last index in the singly-linked list. The pointer to the data being passed in should point to the data type which this singly-linked list holds. For example, if this singly-linked list 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 singly-linked list to add data to
datathe data to add to the singly-linked list
Returns
BK_OK if no error
-BK_ENOMEM if out of memory

◆ forward_list_clear()

void forward_list_clear ( forward_list  me)

Clears all elements from the singly-linked list.

Parameters
methe singly-linked list to clear

◆ forward_list_copy_to_array()

void forward_list_copy_to_array ( void *const  arr,
forward_list  me 
)

Copies the nodes of the singly-linked list to an array. Since it is a copy, the array may be modified without causing side effects to the singly-linked list 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 singly-linked list 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 singly-linked list to
methe singly-linked list to copy to the array

◆ forward_list_destroy()

forward_list forward_list_destroy ( forward_list  me)

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

Parameters
methe singly-linked list to destroy
Returns
NULL

◆ forward_list_get_at()

bk_err forward_list_get_at ( void *const  data,
forward_list  me,
const size_t  index 
)

Gets the data at the specified index in the singly-linked list. The pointer to the data being obtained should point to the data type which this singly- linked list holds. For example, if this singly-linked list 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 get
methe singly-linked list to get data from
indexthe index to get data from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_get_first()

bk_err forward_list_get_first ( void *const  data,
forward_list  me 
)

Gets the data at the first index in the singly-linked list. The pointer to the data being obtained should point to the data type which this singly- linked list holds. For example, if this singly-linked list 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 get
methe singly-linked list to get data from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_get_last()

bk_err forward_list_get_last ( void *const  data,
forward_list  me 
)

Gets the data at the last index in the singly-linked list. The pointer to the data being obtained should point to the data type which this singly- linked list holds. For example, if this singly-linked list 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 get
methe singly-linked list to get data from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_init()

forward_list forward_list_init ( const size_t  data_size)

Initializes a singly-linked list.

Parameters
data_sizethe size of data to store; must be positive
Returns
the newly-initialized singly-linked list, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error

◆ forward_list_is_empty()

bk_bool forward_list_is_empty ( forward_list  me)

Determines if the singly-linked list is empty.

Parameters
methe singly-linked list to check
Returns
BK_TRUE if the singly-linked list is empty, otherwise BK_FALSE

◆ forward_list_remove_at()

bk_err forward_list_remove_at ( forward_list  me,
const size_t  index 
)

Removes data from the singly-linked list at the specified index.

Parameters
methe singly-linked list to remove data from
indexthe index to remove from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_remove_first()

bk_err forward_list_remove_first ( forward_list  me)

Removes the first piece of data from the singly-linked list.

Parameters
methe singly-linked list to remove data from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_remove_last()

bk_err forward_list_remove_last ( forward_list  me)

Removes the last piece of data from the singly-linked list.

Parameters
methe singly-linked list to remove data from
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_set_at()

bk_err forward_list_set_at ( forward_list  me,
const size_t  index,
void *const  data 
)

Sets the data at the specified index in the singly-linked list. The pointer to the data being passed in should point to the data type which this singly- linked list holds. For example, if this singly-linked list 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 singly-linked list to set data for
indexthe index to set data in the singly-linked list
datathe data to set in the singly-linked list
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_set_first()

bk_err forward_list_set_first ( forward_list  me,
void *const  data 
)

Sets the data at the first index in the singly-linked list. The pointer to the data being passed in should point to the data type which this singly- linked list holds. For example, if this singly-linked list 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 singly-linked list to set data for
datathe data to set in the singly-linked list
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_set_last()

bk_err forward_list_set_last ( forward_list  me,
void *const  data 
)

Sets the data at the last index in the singly-linked list. The pointer to the data being passed in should point to the data type which this singly- linked list holds. For example, if this singly-linked list 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 singly-linked list to set data for
datathe data to set in the singly-linked list
Returns
BK_OK if no error
-BK_EINVAL if invalid argument

◆ forward_list_size()

size_t forward_list_size ( forward_list  me)

Gets the number of elements in the singly-linked list.

Parameters
methe singly-linked list to check
Returns
the number of elements