|
htils 1
A small set of utilities for C programming.
|
Go to the source code of this file.
Data Structures | |
| struct | da_header |
| The header of a dynamic array. More... | |
Macros | |
| #define | DA_HEADER_SIZE |
| #define | da_len(darray) |
| #define | da_cap(darray) |
| #define | da_new(arena, darray, initial_capacity) |
| Initialize a dynamic array. | |
| #define | da_append(arena, darray, item) |
| Append an item to a dynamic array. | |
| #define | da_pop(darray) |
| Pop an item from a dynamic array. | |
| #define | da_last(darray) |
| Get the last item of a dynamic array. | |
| #define | da_clear(darray) |
| Clears a dynamic array. | |
Typedefs | |
| typedef struct da_header | da_header_t |
| The header of a dynamic array. | |
Functions | |
| static da_header_t * | da__hdr (void *da) |
| Get a dynamic array's header. | |
| #define da_append | ( | arena, | |
| darray, | |||
| item ) |
Append an item to a dynamic array.
Appends item, growing the capacity (a new arena allocation holding the existing elements) when the array is full.
| arena | The arena to allocate the dynamic array from. |
| darray | The dynamic array to append to. |
| item | The item to append to the dynamic array. |
arena, darray, and item must be valid and cannot be null.| #define da_cap | ( | darray | ) |
| #define da_clear | ( | darray | ) |
Clears a dynamic array.
By setting its length to 0, if the dynamic array is null, nothing happens.
| darray | The dynamic array to clear. |
| #define DA_HEADER_SIZE |
The size of the header of a dynamic array.
| #define da_last | ( | darray | ) |
Get the last item of a dynamic array.
Asserts that the length of the dynamic array is larger than 0, then simply gets the last entry.
| darray | The dynamic array to get the last item from. |
| #define da_len | ( | darray | ) |
| #define da_new | ( | arena, | |
| darray, | |||
| initial_capacity ) |
Initialize a dynamic array.
Caluclates the size for the header with DA_HEADER_SIZE, and the capacity; Allocates the header with initial_capacity, using arena_alloc(), then sets the dynamic array to be the header + 1 offsetting the header.
| arena | The arena to allocate the dynamic array from. |
| darray | The dynamic array to initialize. |
| initial_capacity | The initial capacity of the dynamic array. |
arena, and darray must be valid and cannot be null.initial_capacity must be greater than 0.| #define da_pop | ( | darray | ) |
Pop an item from a dynamic array.
By simply decrementing its length, if the dynamic array is empty, nothing happens.
| darray | The dynamic array to pop from. |
| typedef struct da_header da_header_t |
The header of a dynamic array.
| cap | The capacity of the dynamic array. |
| len | The length of the dynamic array. |
|
inlinestatic |