|
MULE 0.0.1
Multi-Use Library Essentials
|
A growable array of any element type.
Arr(T) is a struct with the same layout and rules as a Str, for any element type. The operations are macros, because only a macro can work for every T.
Macros | |
| #define | Arr(T) |
A growable array of T. | |
Growing | |
Add elements. Each call may move data. | |
| #define | arr_reserve(a, n) |
Make room for n more elements without another allocation. | |
| #define | arr_push(a, v) |
Append v. | |
| #define | arr_insert(a, i, v) |
Insert v before index i, shifting the rest up. | |
Shrinking | |
Remove elements. None of these allocate or move data. | |
| #define | arr_remove(a, i) |
Remove the element at index i, shifting the rest down. | |
| #define | arr_pop(a) |
| Remove and return the last element. | |
| #define | arr_clear(a) |
| Set the length to zero. | |
| #define | arr_free(a) |
| Free the elements' memory and reset to empty. | |
| #define Arr | ( | T | ) |
| #define arr_reserve | ( | a, | |
| n ) |
| #define arr_push | ( | a, | |
| v ) |
Append v.
v is evaluated after any growth and before len changes, so it may read the array itself, as in arr_push(&xs,
xs.data[0]) or arr_push(&xs, xs.len).
| #define arr_insert | ( | a, | |
| i, | |||
| v ) |
Insert v before index i, shifting the rest up.
i may equal len.
| #define arr_remove | ( | a, | |
| i ) |
| #define arr_pop | ( | a | ) |
| #define arr_clear | ( | a | ) |