lifo.h File Reference

LIFO buffer API, read long description carefully. More...

Detailed Description

LIFO buffer API, read long description carefully.

Author
Heiko Will hwill.nosp@m.@inf.nosp@m..fu-b.nosp@m.erli.nosp@m.n.de

This LIFO implementation very efficiently handles integer values. The caveat is that it can only handle values between 0 and its own size - 1. Also it can only handle up to one element of each value. If you insert a value twice the LIFO will break.

Definition in file lifo.h.

Go to the source code of this file.

int lifo_empty (int *array)
 Check if the given lifo is empty. More...
 
void lifo_init (int *array, int n)
 Initialize a lifo array. More...
 
void lifo_insert (int *array, int i)
 Insert an element into the lifo. More...
 
int lifo_get (int *array)
 Extract the least recently inserted element from the lifo. More...
 

Function Documentation

◆ lifo_empty()

int lifo_empty ( int *  array)

Check if the given lifo is empty.

Parameters
[in]arrayThe lifo array to check.
Returns
1, if empty
0, otherwise.

◆ lifo_get()

int lifo_get ( int *  array)

Extract the least recently inserted element from the lifo.

Precondition
array != NULL
Parameters
[in]arrayAn integer array. Must not be NULL.
Returns
-1, if the lifo is empty.
the least recently inserted element, otherwise.

◆ lifo_init()

void lifo_init ( int *  array,
int  n 
)

Initialize a lifo array.

Precondition
array != NULL
Parameters
[in,out]arrayAn array of size n + 1. Must not be NULL.
[in]nMaximum integer value the lifo is able to store.

◆ lifo_insert()

void lifo_insert ( int *  array,
int  i 
)

Insert an element into the lifo.

Precondition
array != NULL
Parameters
[in,out]arrayAn integer array of least i + 1 size that **does not already contain *i***. Must not be NULL.
[in]iThe integer value to store, between 0 and the size of the array - 1, must not be stored already.