|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
Include dependency graph for vl_linked_list.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | vl_linked_list |
| A doubly-linked list with pool-based memory management. More... | |
Macros | |
| #define | VL_LIST_ITER_INVALID VL_POOL_INVALID_IDX |
| #define | VL_LIST_FOREACH(list, trackVar) |
| #define | VL_LIST_FOREACH_REVERSE(list, trackVar) |
| #define | vlListFree(listPtr) vlPoolFree(&((listPtr)->nodePool)) |
| Frees the specified list instance. | |
| #define | vlListSize(listPtr) (vl_dsidx_t)((listPtr)->length) |
| Returns the total number of elements in the specified list. | |
| #define | vlListReserve(listPtr, n) vlFixedPoolReserve(&((listPtr)->nodePool)) |
| Reserves space for n-many elements in the specified list. | |
| #define | vlListClear(listPtr) |
| Clears the specified list so it can be used as if it was just initialized. | |
Typedefs | |
| typedef vl_pool_idx | vl_list_iter |
| List iterator type. Represents a location within a vl_linked_list. | |
Functions | |
| VL_API void | vlListInit (vl_linked_list *list, vl_uint16_t elementSize) |
| Initializes the specified list instance. | |
| VL_API vl_linked_list * | vlListNew (vl_uint16_t elementSize) |
| Allocates on the heap, initializes, and returns a new list instance. | |
| VL_API void | vlListDelete (vl_linked_list *list) |
| Deletes the specified list instance and its internal pool. | |
| VL_API vl_list_iter | vlListPushFront (vl_linked_list *list, const void *elem) |
| Adds a new element to the front of the list. | |
| VL_API void | vlListPopFront (vl_linked_list *list) |
| Removes whatever element is at the front of the list. | |
| VL_API vl_list_iter | vlListPushBack (vl_linked_list *list, const void *elem) |
| Adds a new element to the end of the list. | |
| VL_API void | vlListPopBack (vl_linked_list *list) |
| Removes whatever element is at the end of the list. | |
| VL_API vl_list_iter | vlListInsertAfter (vl_linked_list *list, vl_list_iter target, const void *elem) |
| Inserts an element immediately after the specified target. | |
| VL_API vl_list_iter | vlListInsertBefore (vl_linked_list *list, vl_list_iter target, const void *elem) |
| Inserts an element immediately before the specified target. | |
| VL_API vl_linked_list * | vlListClone (const vl_linked_list *src, vl_linked_list *dest) |
| Clones the specified list to another. | |
| VL_API int | vlListCopy (vl_linked_list *src, vl_list_iter begin, vl_list_iter end, vl_linked_list *dest, vl_list_iter after) |
| Copies a range of elements from one list to another. | |
| VL_API void | vlListSort (vl_linked_list *src, vl_compare_function cmp) |
| Sorts the specified list in-place using the given comparator. | |
| VL_API vl_list_iter | vlListFind (vl_linked_list *src, const void *element) |
| Performs an iterative search on the specified list. | |
| VL_API void | vlListRemove (vl_linked_list *list, vl_list_iter iter) |
| Removes the specified element from the list. | |
| VL_API vl_list_iter | vlListNext (vl_linked_list *list, vl_list_iter iter) |
| Returns next adjacent iterator, or VL_LIST_ITER_INVALID if no such element exists. | |
| VL_API vl_list_iter | vlListPrev (vl_linked_list *list, vl_list_iter iter) |
| Returns the previous adjacent iterator, or VL_LIST_ITER_INVALID if no such element exists. | |
| VL_API void * | vlListSample (vl_linked_list *list, vl_list_iter iter) |
| Returns a pointer to the element data for the specified iterator. | |
| struct vl_linked_list |
A doubly-linked list with pool-based memory management.
A doubly-linked list implementation that uses a fixed-size memory pool for efficient node allocation and deallocation. Each node contains both the element data and bidirectional links to adjacent nodes.
Key features:
Memory management:
Collaboration diagram for vl_linked_list:| Data Fields | ||
|---|---|---|
| vl_uint16_t | elementSize | |
| vl_list_iter | head | |
| vl_dsidx_t | length | |
| vl_pool | nodePool | |
| vl_list_iter | tail | |
| #define VL_LIST_FOREACH | ( | list, | |
| trackVar | |||
| ) |
This is a simple macro for iterating a list.
| list | pointer vl_list pointer |
| trackVar | identifier of the iterator. Always of type vl_list_iter. |
| #define VL_LIST_FOREACH_REVERSE | ( | list, | |
| trackVar | |||
| ) |
This is a simple macro for iterating a list, in reverse.
| list | pointer vl_list pointer |
| trackVar | identifier of the iterator. Always of type vl_list_iter. |
| #define VL_LIST_ITER_INVALID VL_POOL_INVALID_IDX |
██ ██ ██ █████ ███████ █████ ██████ ███ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ███████ ██ ██ ███████ ██ ██ ██████ ██ ████ ██ ██ ====—: A Data Structure and Algorithms library for C11. :—====
Copyright 2026 Jesse Walker, released under the MIT license. Git Repository: https://github.com/walkerje/veritable_lasagna
| #define vlListClear | ( | listPtr | ) |
Clears the specified list so it can be used as if it was just initialized.
This function does not touch any information in the underlying buffer, but rather resets some book-keeping variables.
| list | pointer |
| #define vlListFree | ( | listPtr | ) | vlPoolFree(&((listPtr)->nodePool)) |
Frees the specified list instance.
The specified list should be initialized via vlListInit.
| list | pointer |
| #define vlListReserve | ( | listPtr, | |
| n | |||
| ) | vlFixedPoolReserve(&((listPtr)->nodePool)) |
Reserves space for n-many elements in the specified list.
| list | pointer |
| n | number of elements to reserve space for. |
| #define vlListSize | ( | listPtr | ) | (vl_dsidx_t)((listPtr)->length) |
Returns the total number of elements in the specified list.
| list | pointer |
| typedef vl_pool_idx vl_list_iter |
List iterator type. Represents a location within a vl_linked_list.
| VL_API vl_linked_list * vlListClone | ( | const vl_linked_list * | src, |
| vl_linked_list * | dest | ||
| ) |
Clones the specified list to another.
Clones the entirety of the src list to the dest list, including all element data and order.
The 'src' list pointer must be non-null and initialized. The 'dest' list pointer may be null, but if it is not null it must be initialized.
If the 'dest' list pointer is null, a new list is created via vlListNew. Otherwise, its element size is set to the source's and all of its existing data is replaced.
dest is NULL, the caller owns the returned vl_linked_list. If dest is provided, ownership remains with the caller.src must not be NULL. dest can be NULL.NULL if allocation fails.dest is NULL) and multiple nodes.NULL on failure.| src | |
| dest |
Here is the call graph for this function:| VL_API int vlListCopy | ( | vl_linked_list * | src, |
| vl_list_iter | begin, | ||
| vl_list_iter | end, | ||
| vl_linked_list * | dest, | ||
| vl_list_iter | after | ||
| ) |
Copies a range of elements from one list to another.
Both the src list and the dest list must have equivalent element sizes, otherwise this is a no-op.
This is an inclusive range, and as such, the elements referred to by the begin and end iterators are also copied to the target list.
The begin and end iterators are expected to be in logical iterative order, meaning that if iterating through the entire src list, begin would be found before end.
dest maintains copies of the elements.src and dest must not be NULL.dest.| src | source list pointer |
| begin | iterator to start the copy at, or VL_LIST_ITER_INVALID for the beginning of the list. |
| end | iterator to end the copy after, or VL_LIST_ITER_INVALID for the end of the list. |
| dest | destination buffer pointer |
| after | the iterator to insert elements after, or VL_LIST_ITER_INVALID for the end of the destination. |
Here is the call graph for this function:| VL_API void vlListDelete | ( | vl_linked_list * | list | ) |
Deletes the specified list instance and its internal pool.
The specified list should be created via vlListNew.
vl_linked_list struct.list is NULL.| list | pointer |
| VL_API vl_list_iter vlListFind | ( | vl_linked_list * | src, |
| const void * | element | ||
| ) |
Performs an iterative search on the specified list.
This will return an iterator to the first instance of the specified element that was found using the default comparator.
src must not be NULL. element must not be NULL.VL_LIST_ITER_INVALID if the element is not found.vl_list_iter to the found element, or VL_LIST_ITER_INVALID.| src | source list pointer |
| element | pointer to the element to compare against |
Here is the call graph for this function:| VL_API void vlListInit | ( | vl_linked_list * | list, |
| vl_uint16_t | elementSize | ||
| ) |
Initializes the specified list instance.
The initialized list should be freed via vlListFree.
list struct. The function initializes the internal node pool.vlListFree or vlListDelete.list must not be NULL.vlListFree (causes memory leak).vl_pool which allocates management structures.| list | pointer |
| elementSize | size of a single list element, in bytes. |
Here is the caller graph for this function:| VL_API vl_list_iter vlListInsertAfter | ( | vl_linked_list * | list, |
| vl_list_iter | target, | ||
| const void * | elem | ||
| ) |
Inserts an element immediately after the specified target.
Element data is copied to the internal pool allocator.
list must not be NULL. target must not be VL_LIST_ITER_INVALID. elem can be NULL.VL_LIST_ITER_INVALID if allocation fails.vl_list_iter handle to the new element, or VL_LIST_ITER_INVALID.| list | pointer |
| target | iterator to element that will have something inserted after it. |
| elem | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_list_iter vlListInsertBefore | ( | vl_linked_list * | list, |
| vl_list_iter | target, | ||
| const void * | elem | ||
| ) |
Inserts an element immediately before the specified target.
Element data is copied to the internal pool allocator.
vlListInsertAfter.vlListInsertAfter.vlListInsertAfter.vl_list_iter handle to the new element, or VL_LIST_ITER_INVALID.| list | pointer |
| target | iterator to element that will have something inserted before it. |
| elem |
Here is the call graph for this function:| VL_API vl_linked_list * vlListNew | ( | vl_uint16_t | elementSize | ) |
Allocates on the heap, initializes, and returns a new list instance.
vl_linked_list pointer and is responsible for calling vlListDelete.vlListDelete.NULL if heap allocation for the list struct fails.NULL on allocation failure.vl_linked_list struct and its internal pool.NULL.| elementSize | size of a single list element, in bytes. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_list_iter vlListNext | ( | vl_linked_list * | list, |
| vl_list_iter | iter | ||
| ) |
Returns next adjacent iterator, or VL_LIST_ITER_INVALID if no such element exists.
list must not be NULL.VL_LIST_ITER_INVALID if no next element.vl_list_iter in the sequence.| list | pointer |
| iter | node iterator |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlListPopBack | ( | vl_linked_list * | list | ) |
Removes whatever element is at the end of the list.
This is a no-op if the list is empty.
list must not be NULL.| list | pointer |
Here is the call graph for this function:| VL_API void vlListPopFront | ( | vl_linked_list * | list | ) |
Removes whatever element is at the front of the list.
This is a no-op if the list is empty.
list must not be NULL.| list | pointer |
Here is the call graph for this function:| VL_API vl_list_iter vlListPrev | ( | vl_linked_list * | list, |
| vl_list_iter | iter | ||
| ) |
Returns the previous adjacent iterator, or VL_LIST_ITER_INVALID if no such element exists.
vlListNext.vlListNext.vlListNext.VL_LIST_ITER_INVALID if no previous element.vlListNext.vl_list_iter in the sequence.| list | pointer |
| iter | node iterator |
Here is the call graph for this function:| VL_API vl_list_iter vlListPushBack | ( | vl_linked_list * | list, |
| const void * | elem | ||
| ) |
Adds a new element to the end of the list.
Element data is copied to the internal pool allocator.
list must not be NULL. elem can be NULL.VL_LIST_ITER_INVALID if allocation fails.vl_list_iter handle to the new element, or VL_LIST_ITER_INVALID.| list | pointer |
| elem | pointer to element data |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_list_iter vlListPushFront | ( | vl_linked_list * | list, |
| const void * | elem | ||
| ) |
Adds a new element to the front of the list.
Element data is copied to the internal pool allocator.
elem. The list maintains a copy.list must not be NULL. elem can be NULL (initializes with zero/garbage depending on pool implementation).VL_LIST_ITER_INVALID if node allocation fails.vl_list_iter handle to the new element, or VL_LIST_ITER_INVALID on failure.| list | pointer |
| elem | pointer to element data |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlListRemove | ( | vl_linked_list * | list, |
| vl_list_iter | iter | ||
| ) |
Removes the specified element from the list.
The underlying node is returned to the underlying node pool for reuse, without modifying its discarded data.
list must not be NULL. iter should not be VL_LIST_ITER_INVALID.| list | pointer |
| iter | node iterator. |
Here is the call graph for this function:| VL_API void * vlListSample | ( | vl_linked_list * | list, |
| vl_list_iter | iter | ||
| ) |
Returns a pointer to the element data for the specified iterator.
NULL if iter is VL_LIST_ITER_INVALID.| list | pointer |
| iter | node iterator |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlListSort | ( | vl_linked_list * | src, |
| vl_compare_function | cmp | ||
| ) |
Sorts the specified list in-place using the given comparator.
This function implements an iterative merge sort. Elements are not copied in this operation, but rather the links between them are modified.
The list is split into a "forest" in the underlying node pool, briefly holding a variety of sub-lists which are later merged back together.
list and cmp must not be NULL.NULL comparator or an uninitialized list.| src | source list pointer |
| cmp | comparator function |
Here is the call graph for this function: