|
C Container Collection (CCC)
|
#include <private_array_adaptive_map.h>

A handle ordered map is a modified struct of arrays layout with the modification being that we may have the arrays as pointer offsets in a contiguous allocation if the user desires a dynamic map.
The user data array comes first allowing the user to store any type they wish in the container contiguously with no intrusive element padding, saving space.
The nodes array is next. These nodes track the indices of the child and parent nodes in the WAVL tree.
Here is the layout in one contiguous array.
(D = Data Array, N = Nodes Array, _N = Capacity - 1)
┌───┬───┬───┬───┬───┬───┬───┬───┐ │D_0│D_1│...│D_N│N_0│N_1│...│N_N│ └───┴───┴───┴───┴───┴───┴───┴───┘
This layout costs us in consulting both the data and nodes array during the top down splay operation. However, the benefit of space saving and no wasted padding bytes between element fields or multiple elements in an array is the goal of this implementation. Speed is a secondary goal to space for these implementations as the space savings can be significant.
Data Fields | |
| void * | data |
| struct CCC_Array_adaptive_map_node * | nodes |
| size_t | capacity |
| size_t | count |
| size_t | root |
| size_t | free_list |
| size_t | sizeof_type |
| size_t | key_offset |
| CCC_Key_comparator * | order |
| CCC_Allocator * | allocate |
| void * | context |
| CCC_Allocator* CCC_Array_adaptive_map::allocate |
The provided allocation function, if any.
| size_t CCC_Array_adaptive_map::capacity |
The current capacity.
| void* CCC_Array_adaptive_map::context |
The provided context data, if any.
| size_t CCC_Array_adaptive_map::count |
The current size.
| void* CCC_Array_adaptive_map::data |
The contiguous array of user data.
| size_t CCC_Array_adaptive_map::free_list |
The start of the free singly linked list.
| size_t CCC_Array_adaptive_map::key_offset |
Where user key can be found in type.
| struct CCC_Array_adaptive_map_node* CCC_Array_adaptive_map::nodes |
The contiguous array of WAVL tree meta data.
| CCC_Key_comparator* CCC_Array_adaptive_map::order |
The provided key comparison function.
| size_t CCC_Array_adaptive_map::root |
The root node of the Splay Tree.
| size_t CCC_Array_adaptive_map::sizeof_type |
The size of the type stored in the map.