mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-05 12:44:19 +01:00
FFlist: add new functions to make it be able to work as a queue
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "FFlist.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capacity)
|
||||
{
|
||||
@@ -34,6 +35,27 @@ uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compF
|
||||
return list->length;
|
||||
}
|
||||
|
||||
bool ffListShift(FFlist* list, void* result)
|
||||
{
|
||||
if(list->length == 0)
|
||||
return false;
|
||||
|
||||
memcpy(result, list->data, list->elementSize);
|
||||
memmove(list->data, list->data + list->elementSize, list->elementSize * (list->length - 1));
|
||||
--list->length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffListPop(FFlist* list, void* result)
|
||||
{
|
||||
if(list->length == 0)
|
||||
return false;
|
||||
|
||||
memcpy(result, ffListGet(list, list->length - 1), list->elementSize);
|
||||
--list->length;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ffListDestroy(FFlist* list)
|
||||
{
|
||||
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
|
||||
|
||||
@@ -26,6 +26,11 @@ void* ffListAdd(FFlist* list);
|
||||
|
||||
FF_C_NODISCARD uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*));
|
||||
|
||||
// Removes the first element, and copy its value to `*result`
|
||||
bool ffListShift(FFlist* list, void* result);
|
||||
// Removes the last element, and copy its value to `*result`
|
||||
bool ffListPop(FFlist* list, void* result);
|
||||
|
||||
void ffListDestroy(FFlist* list);
|
||||
|
||||
static inline void ffListInit(FFlist* list, uint32_t elementSize)
|
||||
|
||||
Reference in New Issue
Block a user