cdsa
Arena allocators and friends
|
Data Structures | |
struct | Heap |
Represents a binary heap (min-heap by default) More... | |
struct | HeapItem |
Represents a single item in the heap. More... | |
Macros | |
#define | heap_for_each(item, self) for (auto(item) = (self)->begin; item; (item) = (item)->next) |
Iterate over all items of a heap. | |
Typedefs | |
typedef int | HeapDataCompare(const void *, const void *, void *) |
Data comparison function. | |
typedef void * | HeapDataCopy(Arena *, void *, const void *, long) |
Data copy function. | |
Functions | |
static Heap | heap_create (Arena *arena, long size, HeapDataCompare *compare) |
Create a new heap. | |
static void | heap_push (Heap *self, void *data, void *context) |
Insert a new item into a heap. | |
static void * | heap_pop (Heap *self, void *context) |
Remove the root item from the heap. | |
static void * | heap_peek (const Heap *self) |
Retrieve the root item of the heap. | |
static Heap | heap_clone (const Heap *self, void *context, Arena *arena) |
Create a clone of a heap. | |
static HeapItem * | heap_items (const Heap *self, Arena *arena) |
Retrieve an array of heap items. | |
#define heap_for_each | ( | item, | |
self | |||
) | for (auto(item) = (self)->begin; item; (item) = (item)->next) |
Iterate over all items of a heap.
item | Current heap item |
self | Pointer to a heap |
|
static |
Create a new heap.
arena | Pointer to an arena allocator |
size | Size of item data in bytes (optional) |
compare | Pointer to a data comparison function |
size == 0
, the data pointers will be directly assigned rather than copied
|
static |
Insert a new item into a heap.
self | Pointer to a heap |
data | Pointer to the item data |
context | Pointer to a user-provided context for the comparison function (optional) |
|
static |
Remove the root item from the heap.
self | Pointer to a heap |
context | Pointer to a user-provided context for the comparison function (optional) |
nullptr
if the heap is empty
|
static |
Retrieve the root item of the heap.
self | Pointer to a heap |
nullptr
if the heap is empty Create a clone of a heap.
self | Pointer to a heap |
context | Pointer to a user-provided context for the comparison function (optional) |
arena | Pointer to an arena allocator (optional) |