|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
Include dependency graph for vl_set.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | vl_set |
| An ordered set. More... | |
Macros | |
| #define | VL_SET_ITER_INVALID VL_STRUCTURE_INDEX_MAX |
| #define | VL_SET_FOREACH(set, trackVar) |
| #define | VL_SET_FOREACH_REVERSE(set, trackVar) |
| #define | vlSetSize(set) (size_t)((set)->nodePool.totalTaken) |
| Returns the size of the specified set. | |
Typedefs | |
| typedef vl_pool_idx | vl_set_iter |
Functions | |
| VL_API void | vlSetInit (vl_set *set, vl_memsize_t elementSize, vl_compare_function compFunc) |
| VL_API void | vlSetFree (vl_set *set) |
| VL_API vl_set * | vlSetNew (vl_memsize_t elementSize, vl_compare_function compFunc) |
| VL_API void | vlSetDelete (vl_set *set) |
| VL_API vl_set_iter | vlSetFront (vl_set *set) |
| VL_API vl_set_iter | vlSetBack (vl_set *set) |
| VL_API vl_set_iter | vlSetInsert (vl_set *set, const void *elem) |
| VL_API void * | vlSetSample (vl_set *set, vl_set_iter iter) |
| VL_API vl_set_iter | vlSetNext (vl_set *set, vl_set_iter iter) |
| VL_API vl_set_iter | vlSetPrev (vl_set *set, vl_set_iter iter) |
| VL_API void | vlSetRemove (vl_set *set, vl_set_iter iter) |
| VL_API void | vlSetRemoveElem (vl_set *set, const void *elem) |
| VL_API void | vlSetClear (vl_set *set) |
| VL_API vl_set * | vlSetClone (const vl_set *src, vl_set *dest) |
| Clones the specified set to another. | |
| VL_API int | vlSetCopy (vl_set *src, vl_set_iter begin, vl_set_iter end, vl_set *dest) |
| Copies a range of elements from one set to another. | |
| VL_API vl_set_iter | vlSetFind (vl_set *set, const void *elem) |
| VL_API vl_set * | vlSetUnion (vl_set *a, vl_set *b, vl_set *dest) |
| Computes the union between sets A and B, stored in set dest. | |
| VL_API vl_set * | vlSetIntersection (vl_set *a, vl_set *b, vl_set *dest) |
| Computes the intersection between sets A and B, stored in set dest. | |
| VL_API vl_set * | vlSetDifference (vl_set *a, vl_set *b, vl_set *dest) |
| Compute the difference between sets A and B, stored in set dest. | |
| struct vl_set |
An ordered set.
The vl_set structure represents an ordered, unique set of values sorted according to a supplied comparator. This is implemented using a red/black binary tree, a separate self-balancing structure which guarantees worse-case search, removal, and insertion complexity of O(log(n)).
Elements of the set are sorted according to a key, but can also hold supplementary data for each element that is stored in the same block of memory.
Collaboration diagram for vl_set:| Data Fields | ||
|---|---|---|
| vl_compare_function | comparator | |
| vl_uint16_t | elementSize | |
| vl_pool | nodePool | |
| vl_set_iter | root | |
| vl_dsidx_t | totalElements | |
| #define VL_SET_FOREACH | ( | set, | |
| trackVar | |||
| ) |
Convenience macro for forward iterating over the entirety of a set. Implements a for-loop code structure with some of the boilerplate hidden away.
| set | pointer |
| trackVar | name of the tracking variable used as the set iterator |
| #define VL_SET_FOREACH_REVERSE | ( | set, | |
| trackVar | |||
| ) |
Convenience macro for reverse iterating over the entirety of a set. Implements a for-loop code structure with some of the boilerplate hidden away.
| set | pointer |
| trackVar | name of the tracking variable used as the set iterator |
| #define VL_SET_ITER_INVALID VL_STRUCTURE_INDEX_MAX |
██ ██ ██ █████ ███████ █████ ██████ ███ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ███████ ██ ██ ███████ ██ ██ ██████ ██ ████ ██ ██ ====—: 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 vlSetSize | ( | set | ) | (size_t)((set)->nodePool.totalTaken) |
Returns the size of the specified set.
This macro looks at total taken from the internal node pool.
| set | pointer |
| typedef vl_pool_idx vl_set_iter |
| VL_API vl_set_iter vlSetBack | ( | vl_set * | set | ) |
Returns an iterator to the last element in the set (the one with the maximum key).
VL_SET_ITER_INVALID if the set is empty.vl_set_iter handle to the last element.| set | set pointer |
Here is the caller graph for this function:| VL_API void vlSetClear | ( | vl_set * | set | ) |
Clears the specified set. Does not modify buffer memory associated with the set, but rather resets some variables used to track state.
set must not be NULL.| set | pointer to set |
Here is the call graph for this function:
Here is the caller graph for this function:Clones the specified set to another.
Clones the entirety of the src set to the dest set, including all elements and their order.
The 'src' set pointer must be non-null and initialized. The 'dest' set pointer may be null, but if it is not null it must be initialized.
If the 'dest' set pointer is null, a new set is created via vlSetNew. 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_set. If dest is provided, ownership remains with the caller.src must not be NULL. dest can be NULL.NULL if allocation fails.NULL on failure.| src | pointer |
| dest | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API int vlSetCopy | ( | vl_set * | src, |
| vl_set_iter | begin, | ||
| vl_set_iter | end, | ||
| vl_set * | dest | ||
| ) |
Copies a range of elements from one set to another.
Both the src set and the dest set must have equivalent element sizes, otherwise this is a no-op. Similarly, both sets must also have matching comparators.
This is an inclusive range, and as such, the elements referred to by the begin and end iterators are also copied to the target set.
The begin and end iterators are expected to be in logical iterative order, meaning that if iterating through the entire src set, begin would be found before end.
dest maintains copies of the elements.src and dest must not be NULL.dest.| src | source buffer pointer |
| begin | iterator to start the copy at, or VL_SET_ITER_INVALID for the beginning of the list. |
| end | iterator to end the copy after, or VL_SET_ITER_INVALID for the end of the list. |
| dest | destination buffer pointer |
Here is the call graph for this function:| VL_API void vlSetDelete | ( | vl_set * | set | ) |
Deletes the specified set from the heap. Frees the underlying storage buffers for the specified set. Should only be used by sets initialized via vlSetNew.
vl_set struct.set is NULL.| set | set pointer |
Here is the call graph for this function:Compute the difference between sets A and B, stored in set dest.
Differences consist of all elements that reside in either A and B, but NOT elements that exist in both A and B. Consider this equivalent to bitwise XOR.
This function has computational relevance to set theory.
Both A and B sets must have identical element sizes and comparators. Otherwise, this is a no-op and will return null.
The 'dest' set pointer may be null, but if it is not null it must be initialized. If the 'dest' set pointer is null, a new set is created via vlSetNew.
The set notation for this operation is: A - B
vlSetUnion.vlSetUnion.vlSetUnion.vlSetUnion.NULL.| a | first set |
| b | second set |
| dest | destination set |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_set_iter vlSetFind | ( | vl_set * | set, |
| const void * | elem | ||
| ) |
Searches for the specified element in the set. Returns VL_SET_ITER_INVALID if element is not found.
set must not be NULL. elem must not be NULL.VL_SET_ITER_INVALID if not found.vl_set_iter handle to the element, or VL_SET_ITER_INVALID.| set | pointer to set |
| elem | pointer to element |
Here is the caller graph for this function:| VL_API void vlSetFree | ( | vl_set * | set | ) |
Frees the underlying storage buffers for the specified set. Should only be used on sets initialized via vlSetInit.
set struct itself.set must not be NULL.| set | set pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_set_iter vlSetFront | ( | vl_set * | set | ) |
Returns an iterator to the first element in the set (the one with the minimum key).
VL_SET_ITER_INVALID if the set is empty.vl_set_iter handle to the first element.| set | set pointer |
Here is the caller graph for this function:| VL_API void vlSetInit | ( | vl_set * | set, |
| vl_memsize_t | elementSize, | ||
| vl_compare_function | compFunc | ||
| ) |
Initializes the specified set pointer to hold elements of the specified size. This set should be freed via vlSetFree.
set struct. The function initializes the internal node pool.vlSetFree or vlSetDelete.set must not be NULL. compFunc must not be NULL.vlSetFree (causes memory leak).vl_pool which allocates management structures.| set | set pointer |
| elementSize | element size, in bytes. |
| compFunc | comparator function; 0 = same, >0 = greater, <0 = lesser. |
Here is the caller graph for this function:| VL_API vl_set_iter vlSetInsert | ( | vl_set * | set, |
| const void * | elem | ||
| ) |
Inserts the specified element into the set. If the element already exists in the set, the existing iterator is returned. Insertion does not invalidate existing iterators in the set.
set must not be NULL. elem should not be NULL.VL_SET_ITER_INVALID if node allocation fails.vl_set_iter handle to the element (either the newly inserted or the existing equivalent one), or VL_SET_ITER_INVALID.| set | set pointer |
| elem | element pointer |
Here is the call graph for this function:
Here is the caller graph for this function:Computes the intersection between sets A and B, stored in set dest.
Intersections consist of all elements that reside in both A and B, and ONLY elements that exist in both A and B. Consider this equivalent to bitwise AND.
This function has computational relevance to set theory.
Both A and B sets must have identical element sizes and comparators. Otherwise, this is a no-op and will return null.
The 'dest' set pointer may be null, but if it is not null it must be initialized. If the 'dest' set pointer is null, a new set is created via vlSetNew.
The set notation for this operation is: A n B
vlSetUnion.vlSetUnion.vlSetUnion.vlSetUnion.NULL.| a | first set |
| b | second set |
| dest | destination set |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_set * vlSetNew | ( | vl_memsize_t | elementSize, |
| vl_compare_function | compFunc | ||
| ) |
Allocates a new set on the heap. Initializes the specified set pointer to hold elements of the specified size. This set should be freed via vlSetDelete.
vl_set pointer and is responsible for calling vlSetDelete.vlSetDelete.NULL if heap allocation for the set struct fails.NULL on allocation failure.vl_set struct and its internal node pool.NULL.| elementSize | element size, in bytes |
| compFunc | comparator function; 0 = same, >0 = greater, <0 = lesser. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_set_iter vlSetNext | ( | vl_set * | set, |
| vl_set_iter | iter | ||
| ) |
Returns the iterator to the next element in the set relative to the specified iterator, as if the set tree is being iterated by inorder traversal. If there is no next element, this will return VL_SET_ITER_INVALID.
VL_SET_ITER_INVALID if no more elements exist.vl_set_iter in the sequence.| set | set pointer |
| iter | set iterator |
Here is the caller graph for this function:| VL_API vl_set_iter vlSetPrev | ( | vl_set * | set, |
| vl_set_iter | iter | ||
| ) |
Returns the iterator to the previous element in the set relative to the specified iterator, as if the set tree is being iterated by reverse inorder traversal. If there is no previous element, this will return VL_SET_ITER_INVALID.
VL_SET_ITER_INVALID if no previous element exists.vl_set_iter in the sequence.| set | set pointer |
| iter | set iterator |
| VL_API void vlSetRemove | ( | vl_set * | set, |
| vl_set_iter | iter | ||
| ) |
Removes the specified iterator from the set. Undefined behavior if element does not exist in the set. Removal of an element does not invalidate other iterators in the set.
set must not be NULL. iter should not be VL_SET_ITER_INVALID.| set | pointer to set |
| iter | set iterator |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlSetRemoveElem | ( | vl_set * | set, |
| const void * | elem | ||
| ) |
Removes the specified element from the set. Undefined behavior if element does not exist in the set. Removal of an element does not invalidate other iterators in the set.
set must not be NULL. elem must not be NULL.| set | pointer to set |
| elem | pointer to element. |
Here is the call graph for this function:| VL_API void * vlSetSample | ( | vl_set * | set, |
| vl_set_iter | iter | ||
| ) |
Returns the pointer to the element at the specified iterator in the set. Undefined behavior occurs when iterator does not exist in the set, or is VL_SET_ITER_INVALID.
The pointer is returned as non-const based on the trust that the key by which the set is ordered is not modified. Any supplemental information in the element may be freely modified.
NULL if iter is VL_SET_ITER_INVALID.| set | set pointer |
| iter | element iterator |
Here is the call graph for this function:
Here is the caller graph for this function:Computes the union between sets A and B, stored in set dest.
Unions consist of all elements that reside in either A and B. Consider this equivalent to bitwise OR.
This function has computational relevance to set theory.
Both A and B sets must have identical element sizes and comparators. Otherwise, this is a no-op and will return null.
The 'dest' set pointer may be null, but if it is not null it must be initialized. If the 'dest' set pointer is null, a new set is created via vlSetNew.
The set notation for this operation is: A u B
vlSetClone for dest.a and b must not be NULL. dest can be NULL.NULL if element sizes or comparators do not match, or if allocation fails.dest or a new instance), or NULL.| a | first set |
| b | second set |
| dest | destination set |
Here is the call graph for this function:
Here is the caller graph for this function: