|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
A bit-partitioned trie with a tail buffer, used as a growable indexed sequence in the runtime. More...
Go to the source code of this file.
Data Structures | |
| struct | array_list_maybe_element_t |
| struct | array_list_node_t |
| We have two type of node that both are implemented using the same data structure. More... | |
| struct | array_list_t |
Macros | |
| #define | AL_BR 32U |
| branching factor (power of two) | |
| #define | AL_SHIFT 5U |
| log2(AL_BR) | |
| #define | AL_MASK (AL_BR - 1u) |
| #define | AL_MAX_DEPTH 11 |
| Maximum trie depth, meaning the level of the root. | |
| #define | AL_MAX_ELEMENTS (((size_t)1 << (AL_SHIFT * (AL_MAX_DEPTH + 1))) + AL_BR) |
| Maximum number of elements an array list can hold: a full trie at AL_MAX_DEPTH plus a full tail. | |
Typedefs | |
| typedef size_t | array_list_index_t |
| typedef void * | array_list_elem_t |
| We use generic pointers to refer to internal nodes, leaf nodes and even elements. | |
| typedef struct array_list_maybe_element_t | array_list_maybe_element_t |
| typedef struct array_list_node_t | array_list_node_t |
| We have two type of node that both are implemented using the same data structure. | |
| typedef struct array_list_t | array_list_t |
Functions | |
| array_list_t | array_list_empty (const srn_context_t *ctx) |
| Create an empty array list in the given context ctx. | |
| srn_error_t * | array_list_push (array_list_t *al, array_list_elem_t x) |
| Push the given element x to the end of array_list al. | |
| srn_error_t * | array_list_update (array_list_t *al, array_list_index_t n, array_list_elem_t x) |
| Update the given index n of the array list al with the new element x. | |
| array_list_maybe_element_t | array_list_get (const array_list_t *al, array_list_index_t n) |
| Look up the element at the given index n in the given array list al. | |
| srn_error_t * | array_list_remove (array_list_t *al, array_list_index_t n) |
| Remove the element at the given index n from the array list al, shifting every later element down one to keep the sequence contiguous. | |
A bit-partitioned trie with a tail buffer, used as a growable indexed sequence in the runtime.
It has the same shape as the persistent seq (see seq.h and the Ideal hash trees paper), but this one is mutable.
TL;DR
Definition in file array_list.h.
| #define AL_BR 32U |
branching factor (power of two)
Definition at line 103 of file array_list.h.
| #define AL_MASK (AL_BR - 1u) |
Definition at line 107 of file array_list.h.
| #define AL_MAX_DEPTH 11 |
Maximum trie depth, meaning the level of the root.
At this depth the trie holds AL_BR^(AL_MAX_DEPTH + 1) = 32^12 = 1,152,921,504,606,846,976 elements, which is the hard capacity ceiling of an array list. The bound also keeps the level shift (depth + 1) * AL_SHIFT below the width of size_t, so the index math never shifts by 64 or more.
Definition at line 116 of file array_list.h.
| #define AL_MAX_ELEMENTS (((size_t)1 << (AL_SHIFT * (AL_MAX_DEPTH + 1))) + AL_BR) |
Maximum number of elements an array list can hold: a full trie at AL_MAX_DEPTH plus a full tail.
Definition at line 121 of file array_list.h.
| #define AL_SHIFT 5U |
log2(AL_BR)
Definition at line 106 of file array_list.h.
| typedef void* array_list_elem_t |
We use generic pointers to refer to internal nodes, leaf nodes and even elements.
It makes the calculation cruical to determining what type of data we are looking at, in each node. array_list_elem_t will be pointing to actual user data when the node is a leaf node (depth == 0) and it will be pointing to the next node in the trie if the node is an inner node (depth != 0).
Definition at line 138 of file array_list.h.
| typedef size_t array_list_index_t |
Definition at line 96 of file array_list.h.
| typedef struct array_list_maybe_element_t array_list_maybe_element_t |
| typedef struct array_list_node_t array_list_node_t |
We have two type of node that both are implemented using the same data structure.
Inner nodes that point to other inner nodes or leaf nodes, and leaf nodes which points to actual elements of the sequence.
The main factor in determining the nature of the node is the depth of the trie. Depth zero, means a leaf node and an inner node otherwise.
| typedef struct array_list_t array_list_t |
|
nodiscard |
Create an empty array list in the given context ctx.
Definition at line 101 of file array_list.c.
|
nodiscard |
Look up the element at the given index n in the given array list al.
Look up the element at the given index n in the given array list al.
Definition at line 235 of file array_list.c.
|
nodiscard |
Push the given element x to the end of array_list al.
Definition at line 114 of file array_list.c.
|
nodiscard |
Remove the element at the given index n from the array list al, shifting every later element down one to keep the sequence contiguous.
Returns null on success, or an error when n is out of bounds.
Definition at line 301 of file array_list.c.
|
nodiscard |
Update the given index n of the array list al with the new element x.
Returns null on success, or an error when n is out of bounds.
Definition at line 246 of file array_list.c.