reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
deque.h File Reference
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  deque_t
 

Typedefs

typedef struct deque_t deque_t
 

Functions

void deque_initialize (deque_t *d)
 
bool deque_is_empty (deque_t *d)
 
size_t deque_size (deque_t *d)
 
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 is the header file for an implementation of a double-ended queue. Each node in the queue contains a void* pointer.

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_t

typedef struct deque_t deque_t

A double-ended queue data structure.

Function Documentation

◆ 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.