|
C Container Collection (CCC)
|
The Array Tree Map Interface. More...


Go to the source code of this file.
The Array Tree Map Interface.
An array tree map offers insertion, removal, and searching with a strict bound of O(log(N)) time. This map is suitable for realtime applications if resizing can be well controlled. Insert operations may cause resizing if allocation is allowed changing the insertion runtime to amortized O(log(N)). Searching is a thread-safe read-only operation. Balancing modifications only occur upon insertion or removal.
This array variant of the tree map promises contiguous storage and random access if needed with handles. Handles are stable and the user can use them to refer to an element until that element is removed from the map. Handles remain valid even if resizing of the table, insertions of other elements, or removals of other elements occur. Active user elements may not be contiguous from index [0, N) where N is the size of map; there may be gaps between active elements in the array and it is only guaranteed that N elements are stored between index [0, Capacity).
All elements in the map track their relationships via indices in the buffer. Therefore, this data structure can be relocated, copied, serialized, or written to disk and all internal data structure references will remain valid. Insertion may invoke an O(N) operation if resizing occurs. Finally, if allocation is prohibited upon initialization, and the user provides a capacity of C upon initialization, one slot will be used for a sentinel node. The user available capacity is C - 1.
All interface functions accept void * references to either the key or the full type the user is storing in the map. Therefore, it is important for the user to be aware if they are passing a reference to the key or the full type depending on the function requirements.
To use the map as a set, when only keys are needed, wrap a type in a struct or union. For example a set of int could be represented by creating a type struct My_int {int key;};. All interface functions can then be used normally.
To shorten names in the interface, define the following preprocessor directive at the top of your file.
All types and functions can then be written without the CCC_ prefix.
Initialization Interface | |
Initialize the container with memory, callbacks, and permissions. | |
| #define | CCC_array_tree_map_storage_for( user_type_compound_literal_array, optional_storage_specifier...) |
| Create the underlying fixed size map storage from a user declared compound literal array of the type the user intends to store. | |
| #define | CCC_array_tree_map_default(type_name, type_key_field, comparator...) CCC_private_array_tree_map_default(type_name, type_key_field, comparator) |
| Initializes a default empty map at runtime or compile time. | |
| #define | CCC_array_tree_map_for( type_name, type_key_field, comparator, capacity, memory_pointer) |
| Initializes the map at runtime or compile time. | |
| #define | CCC_array_tree_map_from( type_key_field, comparator, allocator, optional_capacity, type_compound_literal_array...) |
| Initialize a dynamic map at runtime from an initializer list. | |
| #define | CCC_array_tree_map_with_capacity( type_name, type_key_field, comparator, allocator, capacity) |
| Initialize a dynamic map at runtime with at least the specified capacity. | |
| #define | CCC_array_tree_map_with_storage( type_key_field, comparator, compound_literal, optional_storage_specifier...) |
| Initialize a fixed map at compile or runtime from any user chosen type with no allocation permission or context. | |
| CCC_Result | CCC_array_tree_map_copy (CCC_Array_tree_map *destination, CCC_Array_tree_map const *source, CCC_Allocator const *allocator) |
| Copy the map at source to destination. | |
| CCC_Result | CCC_array_tree_map_reserve (CCC_Array_tree_map *map, size_t to_add, CCC_Allocator const *allocator) |
| Reserves space for at least to_add more elements. | |
Membership Interface | |
Test membership or obtain references to stored user types directly. | |
| #define | CCC_array_tree_map_as( array_tree_map_pointer, type_name, array_index...) |
| Returns a reference to the user type in the table at the handle. | |
| void * | CCC_array_tree_map_at (CCC_Array_tree_map const *handle, CCC_Handle_index index) |
| Returns a reference to the user data at the provided handle. | |
| CCC_Tribool | CCC_array_tree_map_contains (CCC_Array_tree_map const *map, void const *key) |
| Searches the map for the presence of key. | |
| CCC_Handle_index | CCC_array_tree_map_get_key_value (CCC_Array_tree_map const *map, void const *key) |
| Returns a reference into the map at handle key. | |
Handle Interface | |
Obtain and operate on container entries for efficient queries when non-trivial control flow is needed. | |
| #define | CCC_array_tree_map_swap_handle_wrap( array_tree_map_pointer, type_output_pointer, allocator_pointer...) |
| Invariantly inserts the key value in type_output_pointer. | |
| #define | CCC_array_tree_map_try_insert_wrap( array_tree_map_pointer, type_pointer, allocator_pointer...) |
| Attempts to insert the key value type_pointer. | |
| #define | CCC_array_tree_map_try_insert_with( array_tree_map_pointer, key, allocator_pointer, type_compound_literal...) |
| lazily insert type_compound_literal into the map at key if key is absent. | |
| #define | CCC_array_tree_map_insert_or_assign_wrap( map_pointer, type_pointer, allocator_pointer...) |
| Invariantly inserts or overwrites a user struct into the map. | |
| #define | CCC_array_tree_map_insert_or_assign_with( array_tree_map_pointer, key, allocator_pointer, type_compound_literal...) |
| Inserts a new key value pair or overwrites the existing handle. | |
| #define | CCC_array_tree_map_remove_key_value_wrap( array_tree_map_pointer, type_output_pointer) |
| Removes the key value in the map storing the old value, if present, in the key value type provided by the user. | |
| #define | CCC_array_tree_map_handle_wrap(array_tree_map_pointer, key_pointer) |
| Obtains a handle for the provided key in the map for future use. | |
| #define | CCC_array_tree_map_and_modify_with( map_array_pointer, closure_parameter, closure_over_closure_parameter...) |
| Modify an Occupied handle with a closure over user type T. | |
| #define | CCC_array_tree_map_or_insert_with( map_array_pointer, allocator_pointer, type_compound_literal...) |
| Lazily insert the desired key value into the handle if it is Vacant. | |
| #define | CCC_array_tree_map_insert_handle_with( map_array_pointer, allocator_pointer, type_compound_literal...) |
| Write the contents of the compound literal type_compound_literal to a node. | |
| #define | CCC_array_tree_map_remove_handle_wrap(map_array_pointer) |
| Remove the handle from the map if Occupied. | |
| CCC_Handle | CCC_array_tree_map_swap_handle (CCC_Array_tree_map *map, void *type_output, CCC_Allocator const *allocator) |
| Invariantly inserts the key value in type_output. | |
| CCC_Handle | CCC_array_tree_map_try_insert (CCC_Array_tree_map *map, void const *type, CCC_Allocator const *allocator) |
| Attempts to insert the key value in type. | |
| CCC_Handle | CCC_array_tree_map_insert_or_assign (CCC_Array_tree_map *map, void const *type, CCC_Allocator const *allocator) |
| Invariantly inserts or overwrites a user struct into the map. | |
| CCC_Handle | CCC_array_tree_map_remove_key_value (CCC_Array_tree_map *map, void *type_output) |
| Removes the key value in the map storing the old value, if present, in the type_output provided by the user. | |
| CCC_Array_tree_map_handle | CCC_array_tree_map_handle (CCC_Array_tree_map const *map, void const *key) |
| Obtains a handle for the provided key in the map for future use. | |
| CCC_Array_tree_map_handle * | CCC_array_tree_map_and_modify (CCC_Array_tree_map_handle *handle, CCC_Modifier const *modifier) |
| Modifies the provided handle if it is Occupied. | |
| CCC_Handle_index | CCC_array_tree_map_or_insert (CCC_Array_tree_map_handle const *handle, void const *type, CCC_Allocator const *allocator) |
| Inserts the provided user type if the handle is Vacant. | |
| CCC_Handle_index | CCC_array_tree_map_insert_handle (CCC_Array_tree_map_handle const *handle, void const *type, CCC_Allocator const *allocator) |
| Inserts the provided user type invariantly. | |
| CCC_Handle | CCC_array_tree_map_remove_handle (CCC_Array_tree_map_handle const *handle) |
| Remove the handle from the map if Occupied. | |
| CCC_Handle_index | CCC_array_tree_map_unwrap (CCC_Array_tree_map_handle const *handle) |
| Unwraps the provided handle to obtain a view into the map element. | |
| CCC_Tribool | CCC_array_tree_map_occupied (CCC_Array_tree_map_handle const *handle) |
| Returns the Vacant or Occupied status of the handle. | |
| CCC_Tribool | CCC_array_tree_map_insert_error (CCC_Array_tree_map_handle const *handle) |
| Provides the status of the handle should an insertion follow. | |
| CCC_Handle_status | CCC_array_tree_map_handle_status (CCC_Array_tree_map_handle const *handle) |
| Obtain the handle status from a container handle. | |
Iterator Interface | |
Obtain and manage iterators over the container. | |
| #define | CCC_array_tree_map_equal_range_wrap( array_tree_map_pointer, begin_and_end_key_pointers...) |
| Returns a compound literal reference to the desired range. O(lg N). | |
| #define | CCC_array_tree_map_equal_range_reverse_wrap( array_tree_map_pointer, reverse_begin_and_reverse_end_key_pointers...) |
| Returns a compound literal reference to the desired range_reverse. O(lg N). | |
| CCC_Handle_range | CCC_array_tree_map_equal_range (CCC_Array_tree_map const *map, void const *begin_key, void const *end_key) |
| Return an iterable range of values from [begin_key, end_key). O(lgN). | |
| CCC_Handle_range_reverse | CCC_array_tree_map_equal_range_reverse (CCC_Array_tree_map const *map, void const *reverse_begin_key, void const *reverse_end_key) |
| Return an iterable range_reverse of values from [begin_key, end_key). O(lg N). | |
| CCC_Handle_index | CCC_array_tree_map_begin (CCC_Array_tree_map const *map) |
| Return the start of an inorder traversal of the map. O(lg N). | |
| CCC_Handle_index | CCC_array_tree_map_reverse_begin (CCC_Array_tree_map const *map) |
| Return the start of a reverse inorder traversal of the map. O(lg N). | |
| CCC_Handle_index | CCC_array_tree_map_next (CCC_Array_tree_map const *map, CCC_Handle_index iterator) |
| Return the next element in an inorder traversal of the map. O(1). | |
| CCC_Handle_index | CCC_array_tree_map_reverse_next (CCC_Array_tree_map const *map, CCC_Handle_index iterator) |
| Return the reverse_next element in a reverse inorder traversal of the map. O(1). | |
| CCC_Handle_index | CCC_array_tree_map_end (CCC_Array_tree_map const *map) |
| Return the end of an inorder traversal of the map. O(1). | |
| CCC_Handle_index | CCC_array_tree_map_reverse_end (CCC_Array_tree_map const *map) |
| Return the reverse_end of a reverse inorder traversal of the map. O(1). | |
Container Types | |
Types available in the container interface. | |
| typedef struct CCC_Array_tree_map | CCC_Array_tree_map |
| An array tree map offers O(lg N) search and erase, and amortized O(lg N) insert. | |
| typedef struct CCC_Array_tree_map_handle | CCC_Array_tree_map_handle |
| A container specific handle used to implement the Handle Interface. | |
Deallocation Interface | |
Deallocate the container. | |
| CCC_Result | CCC_array_tree_map_clear (CCC_Array_tree_map *map, CCC_Destructor const *destructor) |
| Frees all slots in the map for use without affecting capacity. | |
| CCC_Result | CCC_array_tree_map_clear_and_free (CCC_Array_tree_map *map, CCC_Destructor const *destructor, CCC_Allocator const *allocator) |
| Frees all slots in the map and frees the underlying buffer. | |
State Interface | |
Obtain the container state. | |
| CCC_Tribool | CCC_array_tree_map_is_empty (CCC_Array_tree_map const *map) |
| Returns the size status of the map. | |
| CCC_Count | CCC_array_tree_map_count (CCC_Array_tree_map const *map) |
| Returns the count of map occupied slots. | |
| CCC_Count | CCC_array_tree_map_capacity (CCC_Array_tree_map const *map) |
| Returns the capacity of the map representing total available slots. | |
| CCC_Tribool | CCC_array_tree_map_validate (CCC_Array_tree_map const *map) |
| Validation of invariants for the map. | |
| #define CCC_array_tree_map_and_modify_with | ( | map_array_pointer, | |
| closure_parameter, | |||
| closure_over_closure_parameter... | |||
| ) |
Modify an Occupied handle with a closure over user type T.
| [in] | map_array_pointer | a pointer to the obtained handle. |
| [in] | closure_parameter | the named pointer type, for example My_type * e or My_type const * e with which to interpret an occupied handle. |
| [in] | closure_over_closure_parameter | the code to be run on the reference to user type, if Occupied. This may be a semicolon separated list of statements to execute on the named type or a section of code wrapped in braces {code here} which may be preferred for formatting. |
Note that any code written is only evaluated if the handle is Occupied and the container can deliver the user type. This means any function calls are lazily evaluated in the closure scope.
| #define CCC_array_tree_map_as | ( | array_tree_map_pointer, | |
| type_name, | |||
| array_index... | |||
| ) |
Returns a reference to the user type in the table at the handle.
| [in] | array_tree_map_pointer | a pointer to the map. |
| [in] | type_name | name of the user type stored in each slot of the map. |
| [in] | array_index | the index handle obtained from previous map operations. |
| #define CCC_array_tree_map_default | ( | type_name, | |
| type_key_field, | |||
| comparator... | |||
| ) | CCC_private_array_tree_map_default(type_name, type_key_field, comparator) |
Initializes a default empty map at runtime or compile time.
| [in] | type_name | the name of the user type stored in the map. |
| [in] | type_key_field | the name of the field in user type used as key. |
| [in] | comparator | the CCC_Key_comparator for key comparison. |
| #define CCC_array_tree_map_equal_range_reverse_wrap | ( | array_tree_map_pointer, | |
| reverse_begin_and_reverse_end_key_pointers... | |||
| ) |
Returns a compound literal reference to the desired range_reverse. O(lg N).
| [in] | array_tree_map_pointer | a pointer to the map. |
| [in] | reverse_begin_and_reverse_end_key_pointers | two pointers, the first to the start of the range_reverse the second to the end of the range_reverse. |
| #define CCC_array_tree_map_equal_range_wrap | ( | array_tree_map_pointer, | |
| begin_and_end_key_pointers... | |||
| ) |
Returns a compound literal reference to the desired range. O(lg N).
| [in] | array_tree_map_pointer | a pointer to the map. |
| [in] | begin_and_end_key_pointers | two pointers, the first to the start of the range the second to the end of the range. |
| #define CCC_array_tree_map_for | ( | type_name, | |
| type_key_field, | |||
| comparator, | |||
| capacity, | |||
| memory_pointer | |||
| ) |
Initializes the map at runtime or compile time.
| [in] | type_name | the name of the user type stored in the map. |
| [in] | type_key_field | the name of the field in user type used as key. |
| [in] | comparator | the CCC_Key_comparator for key comparison. |
| [in] | capacity | the capacity at data or 0. |
| [in] | memory_pointer | a pointer to the contiguous user types or NULL. |
| #define CCC_array_tree_map_from | ( | type_key_field, | |
| comparator, | |||
| allocator, | |||
| optional_capacity, | |||
| type_compound_literal_array... | |||
| ) |
Initialize a dynamic map at runtime from an initializer list.
| [in] | type_key_field | the field of the struct used for key storage. |
| [in] | comparator | the CCC_Key_comparator for key comparison. |
| [in] | allocator | the required CCC_Allocator for reservation. |
| [in] | optional_capacity | optionally specify the capacity of the map if different from the size of the compound literal array initializer. If the capacity is greater than the size of the compound literal array initializer, it is respected and the capacity is reserved. If the capacity is less than the size of the compound array initializer, the compound literal array initializer size is set as the capacity. Therefore, 0 is valid if one is not concerned with the size of the underlying reservation. |
| [in] | type_compound_literal_array | a list of key value pairs of the type intended to be stored in the map, using array compound literal initialization syntax (e.g (struct my_type[]){{.k = 0, .v 0}, {.k = 1, .v = 1}}). |
Initialize a dynamic map at run time.
Only dynamic maps may be initialized this way due the inability of the map map to protect its invariants from user error at compile time.
| #define CCC_array_tree_map_handle_wrap | ( | array_tree_map_pointer, | |
| key_pointer | |||
| ) |
Obtains a handle for the provided key in the map for future use.
| [in] | array_tree_map_pointer | the map to be searched. |
| [in] | key_pointer | the key used to search the map matching the stored key type. |
A handle is a search result that provides either an Occupied or Vacant handle in the map. An occupied handle signifies that the search was successful. A Vacant handle means the search was not successful but a handle is gained to where in the map such an element should be inserted.
A handle is rarely useful on its own. It should be passed in a functional style to subsequent calls in the Handle Interface.
| #define CCC_array_tree_map_insert_handle_with | ( | map_array_pointer, | |
| allocator_pointer, | |||
| type_compound_literal... | |||
| ) |
Write the contents of the compound literal type_compound_literal to a node.
| [in] | map_array_pointer | a pointer to the obtained handle. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
| [in] | type_compound_literal | the compound literal to write to a new slot. |
| #define CCC_array_tree_map_insert_or_assign_with | ( | array_tree_map_pointer, | |
| key, | |||
| allocator_pointer, | |||
| type_compound_literal... | |||
| ) |
Inserts a new key value pair or overwrites the existing handle.
| [in] | array_tree_map_pointer | the pointer to the handle map. |
| [in] | key | the key to be searched in the map. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
| [in] | type_compound_literal | the compound literal to insert or use for overwrite. |
| #define CCC_array_tree_map_insert_or_assign_wrap | ( | map_pointer, | |
| type_pointer, | |||
| allocator_pointer... | |||
| ) |
Invariantly inserts or overwrites a user struct into the map.
| [in] | map_pointer | a pointer to the handle map. |
| [in] | type_pointer | a pointer to the user struct key value type. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
Note that this function can be used when the old user type is not needed but the information regarding its presence is helpful.
| #define CCC_array_tree_map_or_insert_with | ( | map_array_pointer, | |
| allocator_pointer, | |||
| type_compound_literal... | |||
| ) |
Lazily insert the desired key value into the handle if it is Vacant.
| [in] | map_array_pointer | a pointer to the obtained handle. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
| [in] | type_compound_literal | the compound literal to construct in place if the handle is Vacant. |
Note that if the compound literal uses any function calls to generate values or other data, such functions will not be called if the handle is Occupied.
| #define CCC_array_tree_map_remove_handle_wrap | ( | map_array_pointer | ) |
Remove the handle from the map if Occupied.
| [in] | map_array_pointer | a pointer to the map handle. |
Note that the reference to the removed handle is invalidated upon any further insertions.
| #define CCC_array_tree_map_remove_key_value_wrap | ( | array_tree_map_pointer, | |
| type_output_pointer | |||
| ) |
Removes the key value in the map storing the old value, if present, in the key value type provided by the user.
| [in] | array_tree_map_pointer | the pointer to the tree map. |
| [out] | type_output_pointer | type user type map elem. |
Note that this function may write to the user type struct.
| #define CCC_array_tree_map_storage_for | ( | user_type_compound_literal_array, | |
| optional_storage_specifier... | |||
| ) |
Create the underlying fixed size map storage from a user declared compound literal array of the type the user intends to store.
| [in] | user_type_compound_literal_array | a compound literal array of the type around which the map will be built. |
| [in] | optional_storage_specifier | a storage specifier for the backing struct of array storage may be added on newer compilers such as static. |
This macro is required to support the edge case for the user allocating a fixed size map dynamically from an allocator at runtime. In this case, the user needs access to the compound literal struct of arrays map to know how many bytes to allocate. See the below example.
Usually, using a dynamic map and the reserve interface would be sufficient. However, the reserve interface only guarantees that at least the needed bytes are allocated. When the user must know the exact size of the backing object due to strict memory requirements, this is helpful. Such a use case may be rare, but must be supported by this container.
| #define CCC_array_tree_map_swap_handle_wrap | ( | array_tree_map_pointer, | |
| type_output_pointer, | |||
| allocator_pointer... | |||
| ) |
Invariantly inserts the key value in type_output_pointer.
| [in] | array_tree_map_pointer | the pointer to the tree map. |
| [out] | type_output_pointer | type user type map elem. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
Note that this function may write to the provided user type struct.
| #define CCC_array_tree_map_try_insert_with | ( | array_tree_map_pointer, | |
| key, | |||
| allocator_pointer, | |||
| type_compound_literal... | |||
| ) |
lazily insert type_compound_literal into the map at key if key is absent.
| [in] | array_tree_map_pointer | a pointer to the map. |
| [in] | key | the direct key r-value. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
| [in] | type_compound_literal | the compound literal specifying the value. |
Note that for brevity and convenience the user need not write the key to the lazy value compound literal as well. This function ensures the key in the compound literal matches the searched key.
| #define CCC_array_tree_map_try_insert_wrap | ( | array_tree_map_pointer, | |
| type_pointer, | |||
| allocator_pointer... | |||
| ) |
Attempts to insert the key value type_pointer.
| [in] | array_tree_map_pointer | the pointer to the map. |
| [in] | type_pointer | the type user type map elem. |
| [in] | allocator_pointer | CCC_Allocator for reserving memory if needed. |
| #define CCC_array_tree_map_with_capacity | ( | type_name, | |
| type_key_field, | |||
| comparator, | |||
| allocator, | |||
| capacity | |||
| ) |
Initialize a dynamic map at runtime with at least the specified capacity.
| [in] | type_name | the name of the type being stored in the map. |
| [in] | type_key_field | the field of the struct used for key storage. |
| [in] | comparator | the CCC_Key_comparator for key comparison. |
| [in] | allocator | the required CCC_Allocator for reservation. |
| [in] | capacity | the desired capacity for the map. A capacity of 0 results in an argument error and is a no-op after the map is initialized empty. |
Initialize a dynamic map at run time. This example requires no context data for initialization.
Only dynamic maps may be initialized this way as it simply combines the steps of initialization and reservation.
| #define CCC_array_tree_map_with_storage | ( | type_key_field, | |
| comparator, | |||
| compound_literal, | |||
| optional_storage_specifier... | |||
| ) |
Initialize a fixed map at compile or runtime from any user chosen type with no allocation permission or context.
| [in] | type_key_field | the field of the struct used for key storage. |
| [in] | comparator | the CCC_Key_comparator for key comparison. |
| [in] | compound_literal | the compound literal array of a type provided by the user around which the struct of array backing storage for the map will be built. |
| [in] | optional_storage_specifier | lifetime specifier of the backing struct of array storage, such as static, for the fixed size map in the scope at which it is allocated or declared. |
Initialize a fixed map.
This can help eliminate boilerplate in initializers.
| typedef struct CCC_Array_tree_map CCC_Array_tree_map |
An array tree map offers O(lg N) search and erase, and amortized O(lg N) insert.
An array tree map can be initialized on the stack, heap, or data segment at runtime or compile time.
| typedef struct CCC_Array_tree_map_handle CCC_Array_tree_map_handle |
A container specific handle used to implement the Handle Interface.
The Handle Interface offers efficient search and subsequent insertion, deletion, or value update based on the needs of the user. Handles obtained via the Handle Interface are stable until the user removes the element at the provided handle. Insertions and deletions of other elements do not affect handle stability. Resizing of the table does not affect handle stability.
| CCC_Array_tree_map_handle * CCC_array_tree_map_and_modify | ( | CCC_Array_tree_map_handle * | handle, |
| CCC_Modifier const * | modifier | ||
| ) |
Modifies the provided handle if it is Occupied.
| [in] | handle | the handle obtained from a handle function or macro. |
| [in] | modifier | a CCC_Modifer that operates on an occupied element. |
| void * CCC_array_tree_map_at | ( | CCC_Array_tree_map const * | handle, |
| CCC_Handle_index | index | ||
| ) |
Returns a reference to the user data at the provided handle.
| [in] | handle | a pointer to the map. |
| [in] | index | the stable handle obtained by the user. |
| CCC_Handle_index CCC_array_tree_map_begin | ( | CCC_Array_tree_map const * | map | ) |
Return the start of an inorder traversal of the map. O(lg N).
| [in] | map | a pointer to the map. |
| CCC_Count CCC_array_tree_map_capacity | ( | CCC_Array_tree_map const * | map | ) |
Returns the capacity of the map representing total available slots.
| [in] | map | the map. |
| CCC_Result CCC_array_tree_map_clear | ( | CCC_Array_tree_map * | map, |
| CCC_Destructor const * | destructor | ||
| ) |
Frees all slots in the map for use without affecting capacity.
| [in] | map | the map to be cleared. |
| [in] | destructor | the optional CCC_Destructor or &(CCC_Destructor){} if no maintenance is required on the elements in the map before their slots are forfeit. |
If the empty destructor is passed as the destructor function time is O(1), else O(size).
| CCC_Result CCC_array_tree_map_clear_and_free | ( | CCC_Array_tree_map * | map, |
| CCC_Destructor const * | destructor, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Frees all slots in the map and frees the underlying buffer.
| [in] | map | the map to be cleared. |
| [in] | destructor | the optional CCC_Destructor or &(CCC_Destructor){} if no maintenance is required on the elements in the map before their slots are forfeit. |
| [in] | allocator | CCC_Allocator for reserving memory if needed. |
If an empty destructor is passed as the destructor function time is O(1), else O(size).
| CCC_Tribool CCC_array_tree_map_contains | ( | CCC_Array_tree_map const * | map, |
| void const * | key | ||
| ) |
Searches the map for the presence of key.
| [in] | map | the map to be searched. |
| [in] | key | pointer to the key matching the key type of the user struct. |
| CCC_Result CCC_array_tree_map_copy | ( | CCC_Array_tree_map * | destination, |
| CCC_Array_tree_map const * | source, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Copy the map at source to destination.
| [in] | destination | the initialized destination for the copy of the source map. |
| [in] | source | the initialized source of the map. |
| [in] | allocator | CCC_Allocator for resizing or &(CCC_Allocator){}. |
Note that there are two ways to copy data from source to destination: provide sufficient memory and pass &(CCC_Allocator){} as allocator, or pass an allocator.
Manual memory management with no allocator provided.
The above requires destination capacity be greater than or equal to source capacity. Here is memory management handed over to the copy function.
These options allow users to stay consistent across containers with their memory management strategies.
| CCC_Count CCC_array_tree_map_count | ( | CCC_Array_tree_map const * | map | ) |
Returns the count of map occupied slots.
| [in] | map | the map. |
| CCC_Handle_index CCC_array_tree_map_end | ( | CCC_Array_tree_map const * | map | ) |
Return the end of an inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| CCC_Handle_range CCC_array_tree_map_equal_range | ( | CCC_Array_tree_map const * | map, |
| void const * | begin_key, | ||
| void const * | end_key | ||
| ) |
Return an iterable range of values from [begin_key, end_key). O(lgN).
| [in] | map | a pointer to the map. |
| [in] | begin_key | a pointer to the key intended as the start of the range. |
| [in] | end_key | a pointer to the key intended as the end of the range. |
Note that due to the variety of values that can be returned in the range, using the provided range iteration functions from types.h is recommended for example:
This avoids any possible errors in handling an end range element that is in the map versus the end map sentinel.
| CCC_Handle_range_reverse CCC_array_tree_map_equal_range_reverse | ( | CCC_Array_tree_map const * | map, |
| void const * | reverse_begin_key, | ||
| void const * | reverse_end_key | ||
| ) |
Return an iterable range_reverse of values from [begin_key, end_key). O(lg N).
| [in] | map | a pointer to the map. |
| [in] | reverse_begin_key | a pointer to the key intended as the start of the range_reverse. |
| [in] | reverse_end_key | a pointer to the key intended as the end of the range_reverse. |
Note that due to the variety of values that can be returned in the range_reverse, using the provided range_reverse iteration functions from types.h is recommended for example:
This avoids any possible errors in handling an reverse_end range_reverse element that is in the map versus the end map sentinel.
| CCC_Handle_index CCC_array_tree_map_get_key_value | ( | CCC_Array_tree_map const * | map, |
| void const * | key | ||
| ) |
Returns a reference into the map at handle key.
| [in] | map | the tree map to search. |
| [in] | key | the key to search matching stored key type. |
| CCC_Array_tree_map_handle CCC_array_tree_map_handle | ( | CCC_Array_tree_map const * | map, |
| void const * | key | ||
| ) |
Obtains a handle for the provided key in the map for future use.
| [in] | map | the map to be searched. |
| [in] | key | the key used to search the map matching the stored key type. |
A handle is a search result that provides either an Occupied or Vacant handle in the map. An occupied handle signifies that the search was successful. A Vacant handle means the search was not successful but a handle is gained to where in the map such an element should be inserted.
A handle is rarely useful on its own. It should be passed in a functional style to subsequent calls in the Handle Interface.
| CCC_Handle_status CCC_array_tree_map_handle_status | ( | CCC_Array_tree_map_handle const * | handle | ) |
Obtain the handle status from a container handle.
| [in] | handle | a pointer to the handle. |
Note that this function can be useful for debugging or if more detailed messages are needed for logging purposes. See CCC_handle_status_message() in ccc/types.h for more information on detailed handle statuses.
| CCC_Tribool CCC_array_tree_map_insert_error | ( | CCC_Array_tree_map_handle const * | handle | ) |
Provides the status of the handle should an insertion follow.
| [in] | handle | the handle from a query to the table via function or macro. |
| CCC_Handle_index CCC_array_tree_map_insert_handle | ( | CCC_Array_tree_map_handle const * | handle, |
| void const * | type, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Inserts the provided user type invariantly.
| [in] | handle | the handle returned from a call obtaining a handle. |
| [in] | type | a type struct the user intends to insert. |
| [in] | allocator | CCC_Allocator for reserving memory if needed. |
This method can be used when the old value in the map does not need to be preserved. See the regular insert method if the old value is of interest.
| CCC_Handle CCC_array_tree_map_insert_or_assign | ( | CCC_Array_tree_map * | map, |
| void const * | type, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Invariantly inserts or overwrites a user struct into the map.
| [in] | map | a pointer to the handle map. |
| [in] | type | the type user struct key value. |
| [in] | allocator | CCC_Allocator for reserving memory if needed. |
Note that this function can be used when the old user type is not needed but the information regarding its presence is helpful.
| CCC_Tribool CCC_array_tree_map_is_empty | ( | CCC_Array_tree_map const * | map | ) |
Returns the size status of the map.
| [in] | map | the map. |
| CCC_Handle_index CCC_array_tree_map_next | ( | CCC_Array_tree_map const * | map, |
| CCC_Handle_index | iterator | ||
| ) |
Return the next element in an inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| [in] | iterator | a pointer to the intrusive map element of the current iterator. |
| CCC_Tribool CCC_array_tree_map_occupied | ( | CCC_Array_tree_map_handle const * | handle | ) |
Returns the Vacant or Occupied status of the handle.
| [in] | handle | the handle from a query to the map via function or macro. |
| CCC_Handle_index CCC_array_tree_map_or_insert | ( | CCC_Array_tree_map_handle const * | handle, |
| void const * | type, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Inserts the provided user type if the handle is Vacant.
| [in] | handle | the handle obtained via function or macro call. |
| [in] | type | the type struct to be inserted to a Vacant handle. |
| [in] | allocator | CCC_Allocator for reserving memory if needed. |
Because this functions takes a handle and inserts if it is Vacant, the only reason NULL shall be returned is when an insertion error occurs, usually due to a user struct allocation failure.
If no allocation is permitted, this function assumes the user struct wrapping elem has been allocated with the appropriate lifetime and scope by the user.
| CCC_Handle CCC_array_tree_map_remove_handle | ( | CCC_Array_tree_map_handle const * | handle | ) |
Remove the handle from the map if Occupied.
| [in] | handle | a pointer to the map handle. |
| CCC_Handle CCC_array_tree_map_remove_key_value | ( | CCC_Array_tree_map * | map, |
| void * | type_output | ||
| ) |
Removes the key value in the map storing the old value, if present, in the type_output provided by the user.
| [in] | map | the pointer to the tree map. |
| [out] | type_output | the type user type map elem. |
Note that this function may write to the user type struct.
| CCC_Result CCC_array_tree_map_reserve | ( | CCC_Array_tree_map * | map, |
| size_t | to_add, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Reserves space for at least to_add more elements.
| [in] | map | a pointer to the array tree map. |
| [in] | to_add | the number of elements to add to the current size. |
| [in] | allocator | CCC_Allocator for reserving memory. |
| CCC_Handle_index CCC_array_tree_map_reverse_begin | ( | CCC_Array_tree_map const * | map | ) |
Return the start of a reverse inorder traversal of the map. O(lg N).
| [in] | map | a pointer to the map. |
| CCC_Handle_index CCC_array_tree_map_reverse_end | ( | CCC_Array_tree_map const * | map | ) |
Return the reverse_end of a reverse inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| CCC_Handle_index CCC_array_tree_map_reverse_next | ( | CCC_Array_tree_map const * | map, |
| CCC_Handle_index | iterator | ||
| ) |
Return the reverse_next element in a reverse inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| [in] | iterator | a pointer to the intrusive map element of the current iterator. |
| CCC_Handle CCC_array_tree_map_swap_handle | ( | CCC_Array_tree_map * | map, |
| void * | type_output, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Invariantly inserts the key value in type_output.
| [in] | map | the pointer to the tree map. |
| [out] | type_output | the type user type map elem. |
| [in] | allocator | CCC_Allocator for reserving memory if needed. |
Note that this function may write to the provided user type struct.
| CCC_Handle CCC_array_tree_map_try_insert | ( | CCC_Array_tree_map * | map, |
| void const * | type, | ||
| CCC_Allocator const * | allocator | ||
| ) |
Attempts to insert the key value in type.
| [in] | map | the pointer to the map. |
| [in] | type | the type user type map elem. |
| [in] | allocator | CCC_Allocator for reserving memory if needed. |
| CCC_Handle_index CCC_array_tree_map_unwrap | ( | CCC_Array_tree_map_handle const * | handle | ) |
Unwraps the provided handle to obtain a view into the map element.
| [in] | handle | the handle from a query to the map via function or macro. |
| CCC_Tribool CCC_array_tree_map_validate | ( | CCC_Array_tree_map const * | map | ) |
Validation of invariants for the map.
| [in] | map | the map to validate. |