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

Functions

priority_queue priority_queue_init (size_t data_size, int(*comparator)(const void *const one, const void *const two))
 
size_t priority_queue_size (priority_queue me)
 
bk_bool priority_queue_is_empty (priority_queue me)
 
bk_err priority_queue_push (priority_queue me, void *data)
 
bk_bool priority_queue_pop (void *data, priority_queue me)
 
bk_bool priority_queue_front (void *data, priority_queue me)
 
bk_err priority_queue_clear (priority_queue me)
 
priority_queue priority_queue_destroy (priority_queue me)
 

Typedef Documentation

◆ priority_queue

typedef struct internal_priority_queue* priority_queue

The priority_queue data structure, which adapts a container to provide a priority queue. Adapts the vector container.

Function Documentation

◆ priority_queue_clear()

bk_err priority_queue_clear ( priority_queue  me)

Clears the elements from the priority queue.

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

◆ priority_queue_destroy()

priority_queue priority_queue_destroy ( priority_queue  me)

Frees the priority queue 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 priority queue to free from memory
Returns
NULL

◆ priority_queue_front()

bk_bool priority_queue_front ( void *const  data,
priority_queue  me 
)

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

◆ priority_queue_init()

priority_queue priority_queue_init ( size_t  data_size,
int(*)(const void *const one, const void *const two)  comparator 
)

◆ priority_queue_is_empty()

bk_bool priority_queue_is_empty ( priority_queue  me)

Determines whether or not the priority queue is empty.

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

◆ priority_queue_pop()

bk_bool priority_queue_pop ( void *const  data,
priority_queue  me 
)

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

◆ priority_queue_push()

bk_err priority_queue_push ( priority_queue  me,
void *const  data 
)

Adds an element to the priority queue. The pointer to the data being passed in should point to the data type which this priority queue holds. For example, if this priority 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 priority 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

◆ priority_queue_size()

size_t priority_queue_size ( priority_queue  me)

Gets the size of the priority queue.

Parameters
methe priority queue to check
Returns
the size of the priority queue