orca-software
Functions
queue.c File Reference
#include <hal.h>
#include <libc.h>
#include <malloc.h>
#include <queue.h>

Functions

struct queuehf_queue_create (int32_t size)
 Creates a queue of specified size. More...
 
int32_t hf_queue_destroy (struct queue *q)
 Destroys a queue. More...
 
int32_t hf_queue_count (struct queue *q)
 Counts the number of nodes in a queue. More...
 
int32_t hf_queue_addtail (struct queue *q, void *ptr)
 Adds a node to the tail of the queue. More...
 
void * hf_queue_remhead (struct queue *q)
 Removes a node from the head of the queue. More...
 
void * hf_queue_remtail (struct queue *q)
 Removes a node from the tail of the queue. More...
 
void * hf_queue_get (struct queue *q, int32_t elem)
 Returns a node from the queue. More...
 
int32_t hf_queue_set (struct queue *q, int32_t elem, void *ptr)
 Updates a node on the queue. More...
 
int32_t hf_queue_swap (struct queue *q, int32_t elem1, int32_t elem2)
 Swap the position of two nodes in the queue. More...
 

Detailed Description

Author
Sergio Johann Filho
Date
February 2016

LICENSE

This source code is licensed under the GNU General Public License, Version 2. See the file 'doc/license/gpl-2.0.txt' for more details.

DESCRIPTION

Queue manipulation primitives and auxiliary functions. Queue structures are allocated only on the creation of queues, so little additional overhead regarding memory management is incurred at runtime.

Function Documentation

§ hf_queue_addtail()

int32_t hf_queue_addtail ( struct queue q,
void *  ptr 
)

Adds a node to the tail of the queue.

Parameters
qis a pointer to a queue structure.
ptra pointer to data belonging to the queue node.
Returns
0 when successful and -1 otherwise.

§ hf_queue_count()

int32_t hf_queue_count ( struct queue q)

Counts the number of nodes in a queue.

Parameters
qis a pointer to a queue structure.
Returns
the number of nodes.

§ hf_queue_create()

struct queue* hf_queue_create ( int32_t  size)

Creates a queue of specified size.

Parameters
sizeis the maximum number of elements.
Returns
pointer to the queue on success and NULL otherwise.

§ hf_queue_destroy()

int32_t hf_queue_destroy ( struct queue q)

Destroys a queue.

Parameters
qis a pointer to a queue structure.
Returns
0 when successful and -1 otherwise.

§ hf_queue_get()

void* hf_queue_get ( struct queue q,
int32_t  elem 
)

Returns a node from the queue.

Parameters
qis a pointer to a queue structure.
elemis the n-th element from the queue.
Returns
pointer to node data success and 0 otherwise.

§ hf_queue_remhead()

void* hf_queue_remhead ( struct queue q)

Removes a node from the head of the queue.

Parameters
qis a pointer to a queue structure.
Returns
pointer to node data on success and 0 otherwise.

§ hf_queue_remtail()

void* hf_queue_remtail ( struct queue q)

Removes a node from the tail of the queue.

Parameters
qis a pointer to a queue structure.
Returns
pointer to node data on success and 0 otherwise.

§ hf_queue_set()

int32_t hf_queue_set ( struct queue q,
int32_t  elem,
void *  ptr 
)

Updates a node on the queue.

Parameters
qis a pointer to a queue structure.
elemis the n-th element from the queue.
ptra pointer to data belonging to the queue node.
Returns
0 success and -1 otherwise.

§ hf_queue_swap()

int32_t hf_queue_swap ( struct queue q,
int32_t  elem1,
int32_t  elem2 
)

Swap the position of two nodes in the queue.

Parameters
qis a pointer to a queue structure.
elem1is the first n-th element from the queue.
elem2is the second n-th element from the queue.
Returns
0 when successful and -1 otherwise.