Double-Ended Queue

A double-ended queue (deque) that will automatically increase in size as necessary as data is pushed to the front or back.

#include <util/deque.h>

Added in version 30.1.

Deque Structure (struct deque)

struct deque
void *deque.data
size_t deque.size
size_t deque.start_pos
size_t deque.end_pos
size_t deque.capacity

Deque Inline Functions

void deque_init(struct deque *dq)

Initializes a deque (just zeroes out the entire structure).

Parameters:
  • dq – The deque


void deque_free(struct deque *dq)

Frees a deque.

Parameters:
  • dq – The deque


void deque_reserve(struct deque *dq, size_t capacity)

Reserves a specific amount of buffer space to ensure minimum upsizing.

Parameters:
  • dq – The deque

  • capacity – The new capacity, in bytes


void deque_upsize(struct deque *dq, size_t size)

Sets the current active (not just reserved) size. Any new data is zeroed.

Parameters:
  • dq – The deque

  • size – The new size, in bytes


void deque_place(struct deque *dq, size_t position, const void *data, size_t size)

Places data at a specific positional index (relative to the starting point) within the deque.

Parameters:
  • dq – The deque

  • position – Positional index relative to starting point

  • data – Data to insert

  • size – Size of data to insert


void deque_push_back(struct deque *dq, const void *data, size_t size)

Pushes data to the end of the deque.

Parameters:
  • dq – The deque

  • data – Data

  • size – Size of data


void deque_push_front(struct deque *dq, const void *data, size_t size)

Pushes data to the front of the deque.

Parameters:
  • dq – The deque

  • data – Data

  • size – Size of data


void deque_push_back_zero(struct deque *dq, size_t size)

Pushes zeroed data to the end of the deque.

Parameters:
  • dq – The deque

  • size – Size


void deque_push_front_zero(struct deque *dq, size_t size)

Pushes zeroed data to the front of the deque.

Parameters:
  • dq – The deque

  • size – Size


void deque_peek_front(struct deque *dq, void *data, size_t size)

Peeks data at the front of the deque.

Parameters:
  • dq – The deque

  • data – Buffer to store data in

  • size – Size of data to retrieve


void deque_peek_back(struct deque *dq, void *data, size_t size)

Peeks data at the back of the deque.

Parameters:
  • dq – The deque

  • data – Buffer to store data in

  • size – Size of data to retrieve


void deque_pop_front(struct deque *dq, void *data, size_t size)

Pops data from the front of the deque.

Parameters:
  • dq – The deque

  • data – Buffer to store data in, or NULL

  • size – Size of data to retrieve


void deque_pop_back(struct deque *dq, void *data, size_t size)

Pops data from the back of the deque.

Parameters:
  • dq – The deque

  • data – Buffer to store data in, or NULL

  • size – Size of data to retrieve


void *deque_data(struct deque *dq, size_t idx)

Gets a direct pointer to data at a specific positional index within the deque, relative to the starting point.

Parameters:
  • dq – The deque

  • idx – Byte index relative to the starting point