cdsa
Arena allocators and friends
|
Data Structures | |
struct | List |
Represents a doubly linked list. More... | |
struct | ListItem |
Represents a single item of a list. More... | |
Macros | |
#define | list_for_each(item, self) for (auto(item) = (self)->begin; item; (item) = (item)->next) |
Iterate over all items of a list. | |
Typedefs | |
typedef int | ListDataCompare(const void *, const void *, void *) |
Data comparison function. | |
typedef void * | ListDataCopy(Arena *, void *, const void *, long) |
Data copy function. | |
Functions | |
static List | list_create (Arena *arena, long size, ListDataCompare *compare) |
Create a new list. | |
static void | list_insert (List *self, long index, void *data) |
Insert a new item into a list. | |
static void | list_append (List *self, void *data) |
Append a new item to the back of a list. | |
static void * | list_pop (List *self, long index) |
Remove an item from a list. | |
static void * | list_remove (List *self, const void *data) |
Remove the first occurrence of a matching item from a list. | |
static void * | list_get (const List *self, long index) |
Retrieve an item from a list. | |
static void * | list_find (const List *self, const void *data) |
Find the first occurrence of a matching item of a list. | |
static long | list_index (const List *self, const void *data) |
Retrieve the index of the first occurrence of a matching item of a list. | |
static long | list_count (const List *self, const void *data) |
Count the number of matching items of a list. | |
static void | list_sort (List *self, void *context) |
Sort the items of a list. | |
static void | list_reverse (List *self) |
Reverse the order of items in a list. | |
static List | list_clone (const List *self, Arena *arena) |
Create a clone of a list. | |
static ListItem * | list_items (const List *self, Arena *arena) |
Retrieve an array of list items. | |
#define list_for_each | ( | item, | |
self | |||
) | for (auto(item) = (self)->begin; item; (item) = (item)->next) |
Iterate over all items of a list.
item | Current list item |
self | Pointer to a list |
|
static |
Create a new list.
arena | Pointer to an arena allocator |
size | Size of item data in bytes (optional) |
compare | Pointer to a data comparison function (optional) |
size == 0
, the data pointers will be directly assigned rather than copied
|
static |
Insert a new item into a list.
self | Pointer to a list |
index | Index of the new item |
data | Pointer to the item data |
index
is interpreted as from the back (self->length - index
)
|
static |
Append a new item to the back of a list.
self | Pointer to a list |
data | Pointer to the item data |
|
static |
Remove an item from a list.
self | Pointer to a list |
index | Index of the item to remove |
nullptr
if the list is empty index
is interpreted as from the back (self->length - index
)
|
static |
Remove the first occurrence of a matching item from a list.
self | Pointer to a list |
data | Pointer to the item data to match |
nullptr
if no matching item is found
|
static |
Retrieve an item from a list.
self | Pointer to a list |
index | Index of the item to retrieve |
nullptr
if the list is empty index
is interpreted as from the back (self->length - index
)
|
static |
Find the first occurrence of a matching item of a list.
self | Pointer to a list |
data | Pointer to the item data to match |
nullptr
if no matching item is found
|
static |
Retrieve the index of the first occurrence of a matching item of a list.
self | Pointer to a list |
data | Pointer to the item data to match |
-1
if no matching item is found
|
static |
Count the number of matching items of a list.
self | Pointer to a list |
data | Pointer to the item data to match |
|
static |
Sort the items of a list.
self | Pointer to a list |
context | Pointer to a user-provided context for the comparison function (optional) |
|
static |
Reverse the order of items in a list.
self | Pointer to a list |
Create a clone of a list.
self | Pointer to a list |
arena | Pointer to an arena allocator (optional) |