2013-11-27 16:28:31 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup core_util
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file lifo.h
|
2013-12-20 00:00:29 +01:00
|
|
|
* @brief LIFO buffer API, read long description carefully
|
|
|
|
* @author probably Kaspar Schleiser
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2013-12-20 00:00:29 +01:00
|
|
|
* @long 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
|
2013-12-20 00:27:46 +01:00
|
|
|
* handle up to one element of each value. If you insert
|
|
|
|
* a value twice the LIFO will break.
|
2013-11-27 16:28:31 +01:00
|
|
|
*/
|
|
|
|
|
2010-12-10 16:49:29 +01:00
|
|
|
#ifndef __LIFO_H
|
2013-06-20 18:18:29 +02:00
|
|
|
#define __LIFO_H
|
2010-12-10 16:49:29 +01:00
|
|
|
|
2013-12-20 00:00:29 +01:00
|
|
|
/**
|
|
|
|
* @brief: check if the given lifo is empty
|
|
|
|
* @return: true if empty, false otherwise
|
|
|
|
*/
|
2010-12-10 16:49:29 +01:00
|
|
|
int lifo_empty(int *array);
|
2013-12-20 00:00:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief: initialize a lifo array
|
|
|
|
*
|
|
|
|
* @param array: an array of int of size n+1
|
|
|
|
* @param n: maximum integer value the lifo is able to store
|
|
|
|
*/
|
2010-12-10 16:49:29 +01:00
|
|
|
void lifo_init(int *array, int n);
|
2013-12-20 00:00:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief: insert an element into the lifo
|
|
|
|
*
|
|
|
|
* @param array: an integer array of least i+1 size that does not
|
|
|
|
* already contain i
|
|
|
|
* @param i: the integer value to store, between 0 and the size
|
|
|
|
* of the array -1, must not be stored already
|
|
|
|
*
|
|
|
|
*/
|
2010-12-10 16:49:29 +01:00
|
|
|
void lifo_insert(int *array, int i);
|
2013-12-20 00:00:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief: extract the least recently inserted element from the lifo
|
|
|
|
*
|
|
|
|
* @param array: an integer array
|
|
|
|
*
|
|
|
|
* @return: -1 if the lifo is empty, the least recently
|
2013-12-20 00:27:46 +01:00
|
|
|
* inserted element otherwise
|
2013-12-20 00:00:29 +01:00
|
|
|
*/
|
2010-12-10 16:49:29 +01:00
|
|
|
int lifo_get(int *array);
|
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
/** @} */
|
2010-12-10 16:49:29 +01:00
|
|
|
#endif /* __LIFO_H */
|