reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
deque.c File Reference
#include "deque.h"

Data Structures

struct  deque_node_t
 

Typedefs

typedef struct deque_node_t deque_node_t
 

Functions

void deque_initialize (deque_t *d)
 
bool deque_is_empty (deque_t *d)
 
size_t deque_size (deque_t *d)
 
deque_node_t_deque_create_node (void *value)
 
void deque_push_front (deque_t *d, void *value)
 
void deque_push_back (deque_t *d, void *value)
 
void * deque_pop_front (deque_t *d)
 
void * deque_pop_back (deque_t *d)
 
void * deque_peek_back (deque_t *d)
 
void * deque_peek_front (deque_t *d)
 

Detailed Description

Author
Arthur Deng
Edward A. Lee

LICENSE

Copyright (c) 2021, The University of California at Berkeley.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DESCRIPTION

This provides an implementation of a double-ended queue. Each node contains a void* pointer.

To use this, include the following in your target properties: To use this, include the following in your target properties:

target C {
    cmake-include: "/lib/c/reactor-c/util/deque.cmake"
    files: ["/lib/c/reactor-c/util/deque.c", "/lib/c/reactor-c/util/deque.h"]
};

In addition, you need this in your Lingua Franca file:

preamble {=
    #include "deque.h"
=}

To create a deque, use calloc to ensure that it gets initialized with null pointers and zero size:

    deque_t* my_deque = (deque_t*) calloc(1, sizeof(deque_t));

Alternatively, you can call initialize:

    deque my_deque;
    deque_initialize(&my_deque);

Typedef Documentation

◆ deque_node_t

typedef struct deque_node_t deque_node_t

A node in the queue.

Function Documentation

◆ _deque_create_node()

deque_node_t * _deque_create_node ( void * value)

Internal function to create a node to insert in the deque. Users should not call this function. It is used internally by deque_push_front and deque_push_back. It allocates memory that is freed in popped using deque_pop_back and deque_pop_front.

Parameters
valueThe payload of the node.

◆ deque_initialize()

void deque_initialize ( deque_t * d)

Initialize the specified deque to an empty deque.

Parameters
dThe deque.

◆ deque_is_empty()

bool deque_is_empty ( deque_t * d)

Return true if the queue is empty.

Parameters
dThe deque.

◆ deque_peek_back()

void * deque_peek_back ( deque_t * d)

Peek at the value on the front of the queue, leaving it on the queue.

Parameters
dThe queue.
Returns
The value on the front of the queue or NULL if the queue is empty.

◆ deque_peek_front()

void * deque_peek_front ( deque_t * d)

Peek at the value on the back of the queue, leaving it on the queue.

Parameters
dThe queue.
Returns
The value on the back of the queue or NULL if the queue is empty.

◆ deque_pop_back()

void * deque_pop_back ( deque_t * d)

Pop a value from the back of the queue, removing it from the queue.

Parameters
dThe queue.
Returns
The value on the back of the queue or NULL if the queue is empty.

◆ deque_pop_front()

void * deque_pop_front ( deque_t * d)

Pop a value from the front of the queue, removing it from the queue.

Parameters
dThe queue.
Returns
The value on the front of the queue or NULL if the queue is empty.

◆ deque_push_back()

void deque_push_back ( deque_t * d,
void * value )

Push a value to the back of the queue.

Parameters
dThe queue.
valueThe value to push.

◆ deque_push_front()

void deque_push_front ( deque_t * d,
void * value )

Push a value to the front of the queue.

Parameters
dThe queue.
valueThe value to push.

◆ deque_size()

size_t deque_size ( deque_t * d)

Return the size of the queue.

Parameters
dThe deque.
Returns
The size of the queue.