Blame view

RIOT/core/include/lifo.h 1.89 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  /*
   * Copyright (C) 2013 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @addtogroup  core_util
   * @{
   *
   * @file
   * @brief   LIFO buffer API, read long description carefully
   * @author  Heiko Will <hwill@inf.fu-berlin.de>
   *
   * @details 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.
   */
  
  #ifndef LIFO_H_
  #define LIFO_H_
  
  #ifdef __cplusplus
   extern "C" {
  #endif
  
  /**
   * @brief   Check if the given lifo is empty.
   *
   * @param[in] array The lifo array to check.
   *
   * @return  1, if empty
   * @return  0, otherwise.
   */
  int lifo_empty(int *array);
  
  /**
   * @brief               Initialize a lifo array.
   *
   * @param[in,out] array An array of size *n* + 1, may not be NULL.
   * @param[in] n         Maximum integer value the lifo is able to store.
   */
  void lifo_init(int *array, int n);
  
  /**
   * @brief               Insert an element into the lifo
   *
   * @param[in,out] array An integer array of least *i* + 1 size that **does not
   *                      already contain *i***, may not be NULL.
   * @param[in] i         The integer value to store, between 0 and the size of
   *                      the array - 1, must not be stored already.
   *
   */
  void lifo_insert(int *array, int i);
  
  /**
   * @brief           Extract the least recently inserted element from the lifo.
   *
   * @param[in] array An integer array, may not be NULL.
   *
   * @return          -1, if the lifo is empty.
   * @return          the least recently inserted element, otherwise.
   */
  int lifo_get(int *array);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* LIFO_H_ */
  /** @} */