Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_queue.h File Reference
#include "vl_linear_pool.h"
+ Include dependency graph for vl_queue.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vl_queue
 First in, first out queue. More...
 

Functions

void vlQueueInit (vl_queue *queue, vl_memsize_t elementSize)
 Initializes the specified queue.
 
void vlQueueFree (vl_queue *queue)
 Frees the specified queue.
 
vl_queuevlQueueNew (vl_memsize_t elementSize)
 Allocates on the heap, initializes, and returns a queue instance.
 
void vlQueueDelete (vl_queue *queue)
 Deletes the specified queue.
 
vl_queuevlQueueClone (const vl_queue *src, vl_queue *dest)
 Clones the specified queue to another.
 
void vlQueueReserve (vl_queue *queue, vl_memsize_t n)
 Reserves space for n-many elements in the underlying buffer of the specified queue.
 
void vlQueueClear (vl_queue *queue)
 Clears the specified queue.
 
void vlQueuePushBack (vl_queue *queue, const void *element)
 Adds a new element to the end of the queue.
 
int vlQueuePopFront (vl_queue *queue, void *element)
 Copies the first element in the queue, and removes it from the queue.
 
vl_dsidx_t vlQueueSize (vl_queue *queue)
 Returns the total number of elements in the specified queue.
 

Data Structure Documentation

◆ vl_queue

struct vl_queue

First in, first out queue.

The Queue data structure is a simplified forward-facing linked list. It is implemented on top of a pool allocator, and thus requires all elements in the queue to be the same size.

Items may be added to the end and removed from the beginning. Just like the vl_deque data structure, direct sampling is also disallowed. Thus, all IO requires a copy.

See also
vl_deque
+ Collaboration diagram for vl_queue:
Data Fields
vl_memsize_t elementSize
vl_linearpool_idx head
vl_linearpool nodes
vl_linearpool_idx tail

Function Documentation

◆ vlQueueClear()

void vlQueueClear ( vl_queue * queue)

Clears the specified queue.

The underlying data in the queue is untouched, but rather some book-keeping variables are reset.

Parameters
queue
Complexity of O(1) constant.
+ Here is the call graph for this function:

◆ vlQueueClone()

vl_queue * vlQueueClone ( const vl_queue * src,
vl_queue * dest )

Clones the specified queue to another.

Clones the entirety of the src queue to the dest queue.

The 'src' queue pointer must be non-null and initialized. The 'dest' queue pointer may be null, but if it is not null it must be initialized.

If the 'dest' queue pointer is null, a new queue is created via vlQueueNew. Otherwise, its element size is set to the source's and all of its existing data is replaced.

Parameters
srcpointer
destpointer
Returns
pointer to queue that was copied to or created.
+ Here is the call graph for this function:

◆ vlQueueDelete()

void vlQueueDelete ( vl_queue * queue)

Deletes the specified queue.

The queue should have been initialized via vlQueueNew.

See also
vlQueueNew
Parameters
queuepointer
Complexity of O(1) constant.
+ Here is the call graph for this function:

◆ vlQueueFree()

void vlQueueFree ( vl_queue * queue)

Frees the specified queue.

The queue should have been initialized via vlQueueInit.

See also
vlQueueFree
Parameters
queuepointer
Complexity of O(1) constant.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlQueueInit()

void vlQueueInit ( vl_queue * queue,
vl_memsize_t elementSize )

Initializes the specified queue.

The queue should then later be freed via vlQueueFree.

See also
vlQueueFree
Parameters
queuepointer
elementSizesize of a single queue element, in bytes
Complexity of O(1) constant.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlQueueNew()

vl_queue * vlQueueNew ( vl_memsize_t elementSize)

Allocates on the heap, initializes, and returns a queue instance.

The queue should then later be deleted via vlQueueDelete.

See also
vlQueueDelete
Parameters
elementSizesize of a single queue element, in bytes
Complexity of O(1) constant.
Returns
pointer to queue
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlQueuePopFront()

int vlQueuePopFront ( vl_queue * queue,
void * element )

Copies the first element in the queue, and removes it from the queue.

This is a no-op if the queue is empty.

Parameters
queuepointer
elementdata pointer
Complexity of O(1) constant.
Returns
1 if an element was copied and removed, 0 otherwise.
+ Here is the call graph for this function:

◆ vlQueuePushBack()

void vlQueuePushBack ( vl_queue * queue,
const void * element )

Adds a new element to the end of the queue.

The element data is copied to the queue.

Parameters
queuepointer
elementdata pointer
Complexity of O(1) constant.
+ Here is the call graph for this function:

◆ vlQueueReserve()

void vlQueueReserve ( vl_queue * queue,
vl_memsize_t n )

Reserves space for n-many elements in the underlying buffer of the specified queue.

This is done by doubling the size until the requested growth is met or exceeded. This function will always result in the reallocation of the underlying memory.

Parameters
queuepointer
ntotal number of elements to reserve space for.
+ Here is the call graph for this function:

◆ vlQueueSize()

vl_dsidx_t vlQueueSize ( vl_queue * queue)

Returns the total number of elements in the specified queue.

Parameters
queuepointer
Complexity of O(1) constant.
Returns
size of the queue