ECSTL
The Embedded C Standard Template Library
deque.h File Reference
#include <stdint.h>

Macros

#define DEFINE_DEQUE_TYPE(typename, value_type, max_size)
 A new deque type definition. More...
 
#define DEFINE_DEQUE(typename, deque)
 A predefined deque definition with no elements. More...
 
#define DEQUE_PUSH_BACK(deque, value)
 Add data to the end of the deque. More...
 
#define DEQUE_PUSH_FRONT(deque, value)
 Add data to the front of the deque. More...
 
#define DEQUE_FRONT(deque)
 
#define DEQUE_BACK(deque)
 
#define DEQUE_EMPTY(deque)
 
#define DEQUE_POP_FRONT(deque)
 Removes the first element. More...
 
#define DEQUE_POP_BACK(deque)
 Removes the last element. More...
 
#define DEQUE_SIZE(deque)
 
#define DEQUE_MAX_SIZE(deque)
 
#define DEQUE_CLEAR(deque)
 
#define DEQUE_FILL(deque, n, value)
 
#define DEQUE_AT(deque, n)
 

Detailed Description

deque (usually pronounced like "deck") is an irregular acronym of double-ended deque. Double-ended queues are sequence containers that can be expanded or contracted on both ends (either its front or its back).

Unlike vectors, deques are not guaranteed to store all its elements in contiguous storage locations: accessing elements in a deque by offsetting a pointer to another element causes undefined behavior.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <deque.h>
DEFINE_DEQUE_TYPE(mydeque_int_t, int, 16);
int main(void)
{
DEFINE_DEQUE(mydeque_int_t, mydeque);
int sum = 0;
DEQUE_PUSH_BACK(mydeque, 10);
DEQUE_PUSH_BACK(mydeque, 20);
DEQUE_PUSH_BACK(mydeque, 30);
while(!DEQUE_EMPTY( mydeque ))
{
sum += *DEQUE_BACK( mydeque );
DEQUE_POP_BACK( mydeque );
}
printf( "The elements of mydeque add up to %d\n", sum );
printf( "\nThe final size of mydeque is %d\n", DEQUE_SIZE( mydeque ));
return 0;
}

Output:

The elements of mydeque add up to 60
The final size of mydeque is 0

Macro Definition Documentation

◆ DEFINE_DEQUE

#define DEFINE_DEQUE (   typename,
  deque 
)

A predefined deque definition with no elements.

Parameters
typenameThe deque type
dequeThe deque

◆ DEFINE_DEQUE_TYPE

#define DEFINE_DEQUE_TYPE (   typename,
  value_type,
  max_size 
)

A new deque type definition.

Parameters
typenameName of the new deque type
value_typeType of element.
max_sizeMaximal size of the deque. It defines the fixed-size of the static defined array.

◆ DEQUE_AT

#define DEQUE_AT (   deque,
 
)

Returns a pointer to the element at position n in the deque.

Parameters
dequeThe deque
nNumber of elements

◆ DEQUE_BACK

#define DEQUE_BACK (   deque)

Returns a read/write pointer to the data at the last element of the deque.

Parameters
dequeThe deque

◆ DEQUE_CLEAR

#define DEQUE_CLEAR (   deque)

Remove all elements from the deque.

Parameters
dequeThe deque

◆ DEQUE_EMPTY

#define DEQUE_EMPTY (   deque)

Returns true if the deque is empty.

Parameters
dequeThe deque

◆ DEQUE_FILL

#define DEQUE_FILL (   deque,
  n,
  value 
)

Fill container with n elements. Each element is a copy of value.

Parameters
dequeThe deque
nNumber of elements
valueInitial value

◆ DEQUE_FRONT

#define DEQUE_FRONT (   deque)

Returns a read/write pointer to the data at the first element of the deque.

Parameters
dequeThe deque

◆ DEQUE_MAX_SIZE

#define DEQUE_MAX_SIZE (   deque)

Returns the size() of the largest possible deque.

Parameters
dequeThe deque

◆ DEQUE_POP_BACK

#define DEQUE_POP_BACK (   deque)

Removes the last element.

Parameters
dequeThe deque This is a typical stack operation. It shrinks the deque by one.
Note
that no data is returned, and if the last element's data is needed, it should be retrieved before DEQUE_POP_BACK() is called.

◆ DEQUE_POP_FRONT

#define DEQUE_POP_FRONT (   deque)

Removes the first element.

Parameters
dequeThe deque This is a typical stack operation. It shrinks the deque by one.
Note
that no data is returned, and if the first element's data is needed, it should be retrieved before DEQUE_POP_FRONT() is called.

◆ DEQUE_PUSH_BACK

#define DEQUE_PUSH_BACK (   deque,
  value 
)

Add data to the end of the deque.

Parameters
dequeThe deque
valueData to be added.

This is a typical stack operation. The function add an element at the end of the deque. Due to the nature of a deque this operation can be done in constant time.

◆ DEQUE_PUSH_FRONT

#define DEQUE_PUSH_FRONT (   deque,
  value 
)

Add data to the front of the deque.

Parameters
dequeThe deque
valueData to be added.

This is a typical stack operation. The function add an element at the front of the deque. Due to the nature of a deque this operation can be done in constant time.

◆ DEQUE_SIZE

#define DEQUE_SIZE (   deque)

Returns the number of elements in the deque.

Parameters
dequeThe deque