From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/common/impl/FFlist.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/common/impl/FFlist.c (limited to 'src/common/impl/FFlist.c') diff --git a/src/common/impl/FFlist.c b/src/common/impl/FFlist.c new file mode 100644 index 0000000..eddd0fa --- /dev/null +++ b/src/common/impl/FFlist.c @@ -0,0 +1,34 @@ +#include "common/FFlist.h" + +#include +#include + +void* ffListAdd(FFlist* list, uint32_t elementSize) { + if (list->length == list->capacity) { + ffListReserve(list, elementSize, list->capacity == 0 ? FF_LIST_DEFAULT_ALLOC : list->capacity * 2); + } + + ++list->length; + return ffListGet(list, elementSize, list->length - 1); +} + +bool ffListShift(FFlist* list, uint32_t elementSize, void* __restrict result) { + if (list->length == 0) { + return false; + } + + memcpy(result, list->data, elementSize); + memmove(list->data, list->data + elementSize, (size_t) elementSize * (list->length - 1)); + --list->length; + return true; +} + +bool ffListPop(FFlist* list, uint32_t elementSize, void* __restrict result) { + if (list->length == 0) { + return false; + } + + memcpy(result, ffListGet(list, elementSize, list->length - 1), elementSize); + --list->length; + return true; +} -- cgit v1.2.3