1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #16098 from kfessel/p-remove-lifo

core/lifo: Remove lifo [after 2021.04]
This commit is contained in:
Francisco 2021-06-15 13:55:30 +02:00 committed by GitHub
commit d7b3328601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 197 deletions

View File

@ -1,128 +0,0 @@
/*
* 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.
*/
/**
* @ingroup core_util
* @{
*
* @file
* @brief LIFO buffer API, read long description carefully
* @author Heiko Will <hwill@inf.fu-berlin.de>
* @deprecated Is no longer used in RIOT.
* Has very tight constrains making new use unlikely.
* Will be removed after release 2021.04.
*
* @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
#include "log.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.
*/
static inline int lifo_empty(int *array)
{
return array[0] == -1;
}
/**
* @brief Initialize a lifo array.
*
* @pre `array != NULL`
*
* @param[in,out] array An array of size *n* + 1. Must not be `NULL`.
* @param[in] n Maximum integer value the lifo is able to store.
*/
static inline void lifo_init(int *array, int n)
{
LOG_DEBUG("lifo_init(%i)\n", n);
for (int i = 0; i <= n; i++) {
array[i] = -1;
}
}
/**
* @brief Insert an element into the lifo
*
* @pre `array != NULL`
*
* @param[in,out] array An integer array of least *i* + 1 size that **does not
* already contain *i***. Must 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.
*
*/
static inline void lifo_insert(int *array, int i)
{
LOG_DEBUG("lifo_insert(%i)\n", i);
int index = i + 1;
#ifdef DEVELHELP
if ((array[index] != -1) && (array[0] != -1)) {
LOG_WARNING(
"lifo_insert: overwriting array[%i] == %i with %i\n\n\n"
"\t\tThe lifo is broken now.\n\n\n", index,
array[index], array[0]);
}
#endif
array[index] = array[0];
array[0] = i;
}
/**
* @brief Extract the least recently inserted element from the lifo.
*
* @pre `array != NULL`
*
* @param[in] array An integer array. Must not be NULL.
*
* @return -1, if the lifo is empty.
* @return the least recently inserted element, otherwise.
*/
static inline int lifo_get(int *array)
{
LOG_DEBUG("lifo_get\n");
int head = array[0];
if (head != -1) {
array[0] = array[head + 1];
}
#ifdef DEVELHELP
/* make sure a double insert does not result in an infinite
* resource of values */
array[head + 1] = -1;
#endif
LOG_DEBUG("lifo_get: returning %i\n", head);
return head;
}
#ifdef __cplusplus
}
#endif
#endif /* LIFO_H */
/** @} */

View File

@ -1,61 +0,0 @@
/*
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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.
*/
#include "embUnit.h"
#include "lifo.h"
#include "tests-core.h"
#define TEST_LIFO_MAX_ELEM 2
int lifo[TEST_LIFO_MAX_ELEM + 1];
static void set_up(void)
{
lifo_init(lifo, TEST_LIFO_MAX_ELEM);
}
static void test_lifo_empty(void)
{
TEST_ASSERT(lifo_empty(lifo));
}
static void test_lifo_insert(void)
{
lifo_insert(lifo, 0);
TEST_ASSERT(!lifo_empty(lifo));
}
static void test_lifo_get_one(void)
{
lifo_insert(lifo, 0);
TEST_ASSERT_EQUAL_INT(0, lifo_get(lifo));
}
static void test_lifo_get_two(void)
{
lifo_insert(lifo, 0);
lifo_insert(lifo, 1);
TEST_ASSERT_EQUAL_INT(1, lifo_get(lifo));
TEST_ASSERT_EQUAL_INT(0, lifo_get(lifo));
}
Test *tests_core_lifo_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_lifo_empty),
new_TestFixture(test_lifo_insert),
new_TestFixture(test_lifo_get_one),
new_TestFixture(test_lifo_get_two),
};
EMB_UNIT_TESTCALLER(core_lifo_tests, set_up, NULL, fixtures);
return (Test *)&core_lifo_tests;
}

View File

@ -14,7 +14,6 @@ void tests_core(void)
TESTS_RUN(tests_core_bitarithm_tests());
TESTS_RUN(tests_core_cib_tests());
TESTS_RUN(tests_core_clist_tests());
TESTS_RUN(tests_core_lifo_tests());
TESTS_RUN(tests_core_list_tests());
TESTS_RUN(tests_core_priority_queue_tests());
TESTS_RUN(tests_core_byteorder_tests());

View File

@ -57,13 +57,6 @@ Test *tests_core_cib_tests(void);
*/
Test *tests_core_clist_tests(void);
/**
* @brief Generates tests for lifo.h
*
* @return embUnit tests if successful, NULL if not.
*/
Test *tests_core_lifo_tests(void);
/**
* @brief Generates tests for list.h
*