Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_deque.c File Reference
#include "vl_deque.h"
#include <stdlib.h>
#include <memory.h>
+ Include dependency graph for vl_deque.c:

Functions

void vlDequeInit (vl_deque *deq, vl_memsize_t elementSize)
 Initializes the specified instance of vl_deque.
 
void vlDequeFree (vl_deque *deq)
 Frees the specified instance of vl_deque.
 
vl_dequevlDequeNew (vl_memsize_t elementSize)
 Allocates, initializes, and returns an instance of vl_deque.
 
void vlDequeDelete (vl_deque *deq)
 De-initializes and deletes the specified instance of vl_deque.
 
void vlDequeClear (vl_deque *deq)
 Clears the specified deque.
 
void vlDequeReserve (vl_deque *deque, vl_memsize_t numElems)
 Reserves space for n-many elements in the underlying buffer of the specified deque.
 
vl_dequevlDequeClone (const vl_deque *src, vl_deque *dest)
 Clones the specified deque to another.
 
vl_memsize_t vlDequeSize (vl_deque *deq)
 Returns the total number of elements.
 
void vlDequePushFront (vl_deque *deq, const void *val)
 Adds and copies an element to the front of the deque.
 
int vlDequePopFront (vl_deque *deq, void *val)
 Copies and removes an element from the front of the deque.
 
void vlDequePushBack (vl_deque *deq, const void *val)
 Adds and copies an en element to the end of the deque.
 
int vlDequePopBack (vl_deque *deq, void *val)
 Copies and removes an element from the end of the deque.
 

Function Documentation

◆ vlDequeClear()

void vlDequeClear ( vl_deque * deq)

Clears the specified deque.

This does not actually touch any underlying element data, but does reset some bookkeeping values.

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

◆ vlDequeClone()

vl_deque * vlDequeClone ( const vl_deque * src,
vl_deque * dest )

Clones the specified deque to another.

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

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

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

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

◆ vlDequeDelete()

void vlDequeDelete ( vl_deque * deq)

De-initializes and deletes the specified instance of vl_deque.

The deque should have been initialized via vlDequeNew.

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

◆ vlDequeFree()

void vlDequeFree ( vl_deque * deq)

Frees the specified instance of vl_deque.

The deque should have been initialized via vlDequeInit.

See also
vlDequeInit
Parameters
deqpointer
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlDequeInit()

void vlDequeInit ( vl_deque * deq,
vl_memsize_t elementSize )

Initializes the specified instance of vl_deque.

The deque should later be freed via vlDequeFree.

See also
vlDequeFree
Parameters
deqpointer
elementSizesize of each element, in bytes.
Complexity O(1) constant.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlDequeNew()

vl_deque * vlDequeNew ( vl_memsize_t elementSize)

Allocates, initializes, and returns an instance of vl_deque.

The deque should later be freed via vlDequeFree.

See also
vlDequeFree
Parameters
deqpointer
elementSizesize of each element, in bytes.
Complexity O(1) constant.
Returns
deque pointer
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlDequePopBack()

int vlDequePopBack ( vl_deque * deq,
void * val )

Copies and removes an element from the end of the deque.

If specified pointer val is NULL, the element is not copied, but the element is still removed.

Parameters
deqpointer
valpointer where the element will be copied to.
Returns
1 if success, 0 if failed.
+ Here is the call graph for this function:

◆ vlDequePopFront()

int vlDequePopFront ( vl_deque * deq,
void * val )

Copies and removes an element from the front of the deque.

If specified pointer val is NULL, the element is not copied, but the element is still removed.

Parameters
deqpointer
valpointer where the element will be copied to.
Complexity O(1) constant.
Returns
1 if success, 0 if failed
+ Here is the call graph for this function:

◆ vlDequePushBack()

void vlDequePushBack ( vl_deque * deq,
const void * val )

Adds and copies an en element to the end of the deque.

Parameters
deqpointer
valelement data pointer
Complexity O(1) constant.
+ Here is the call graph for this function:

◆ vlDequePushFront()

void vlDequePushFront ( vl_deque * deq,
const void * val )

Adds and copies an element to the front of the deque.

Parameters
deqpointer
valelement data pointer
Complexity O(1) constant.
+ Here is the call graph for this function:

◆ vlDequeReserve()

void vlDequeReserve ( vl_deque * deque,
vl_memsize_t n )

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

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
dequepointer
ntotal number of elements to reserve space for.
+ Here is the call graph for this function:

◆ vlDequeSize()

vl_memsize_t vlDequeSize ( vl_deque * deq)

Returns the total number of elements.

Parameters
deqpointer
Complexity O(1) constant.
Returns
total number of elements in the deque.