C Container Collection (CCC)
Loading...
Searching...
No Matches
array_tree_map.h File Reference

The Array Tree Map Interface. More...

#include "private/private_array_tree_map.h"
#include "types.h"
Include dependency graph for array_tree_map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Detailed Description

The Array Tree Map Interface.

A 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. Searching is a thread-safe read-only operation. Balancing modifications only occur upon insertion or removal.

The handle variant of the tree map promises contiguous storage and random access if needed. 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 N upon initialization, one slot will be used for a sentinel node. The user available capacity is N - 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 shorten names in the interface, define the following preprocessor directive at the top of your file.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC

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_declare_fixed(fixed_map_type_name, type_name, capacity)
 Declare a fixed size map type for use in the stack, heap, or data segment. Does not return a value.
 
#define CCC_array_tree_map_fixed_capacity(fixed_map_type_name)    CCC_private_array_tree_map_fixed_capacity(fixed_map_type_name)
 Obtain the capacity previously chosen for the fixed size map type.
 
#define CCC_array_tree_map_initialize(memory_pointer, type_name, type_key_field, compare, allocate, context_data, capacity)
 Initializes the map at runtime or compile time.
 
#define CCC_array_tree_map_from(type_key_field, compare, allocate, context_data, 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, compare, allocate, context_data, capacity)
 Initialize a dynamic map at runtime with at least the specified capacity.
 
#define CCC_array_tree_map_with_compound_literal(type_key_field, compare, compound_literal)
 Initialize a fixed map at compile or runtime from a previously declared fixed map type with no allocation permission or context.
 
#define CCC_array_tree_map_with_context_compound_literal( type_key_field, compare, context, compound_literal)
 Initialize a fixed map at compile or runtime from a previously declared fixed map type with no allocation permission.
 
CCC_Result CCC_array_tree_map_copy (CCC_Array_tree_map *destination, CCC_Array_tree_map const *source, CCC_Allocator *allocate)
 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 *allocate)
 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)
 Invariantly inserts the key value in type_output_pointer.
 
#define CCC_array_tree_map_try_insert_wrap(array_tree_map_pointer, type_pointer)
 Attempts to insert the key value type_pointer.
 
#define CCC_array_tree_map_try_insert_with(array_tree_map_pointer, key, 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_with(array_tree_map_pointer, key, 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 struct containing 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, type_name, closure_over_T...)
 Modify an Occupied handle with a closure over user type T.
 
#define CCC_array_tree_map_or_insert_with(map_array_pointer, type_compound_literal...)
 Lazily insert the desired key value into the handle if it is Vacant.
 
#define CCC_array_tree_map_insert_array_with(map_array_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)
 Invariantly inserts the key value in type_output.
 
CCC_Handle CCC_array_tree_map_try_insert (CCC_Array_tree_map *map, void const *type)
 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)
 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 struct containing 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_handleCCC_array_tree_map_and_modify (CCC_Array_tree_map_handle *handle, CCC_Type_modifier *modify)
 Modifies the provided handle if it is Occupied.
 
CCC_Array_tree_map_handleCCC_array_tree_map_and_modify_context (CCC_Array_tree_map_handle *handle, CCC_Type_modifier *modify, void *context)
 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)
 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)
 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 union CCC_Array_tree_map_handle_wrap 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_Type_destructor *destroy)
 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_Type_destructor *destroy)
 Frees all slots in the map and frees the underlying buffer.
 
CCC_Result CCC_array_tree_map_clear_and_free_reserve (CCC_Array_tree_map *map, CCC_Type_destructor *destroy, CCC_Allocator *allocate)
 Frees all slots in the map and frees the underlying Buffer that was previously dynamically reserved with the reserve function.
 

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.
 

Macro Definition Documentation

◆ CCC_array_tree_map_and_modify_with

#define CCC_array_tree_map_and_modify_with (   map_array_pointer,
  type_name,
  closure_over_T... 
)
Value:
{ \
CCC_private_array_tree_map_and_modify_with(map_array_pointer, \
type_name, closure_over_T) \
}
union CCC_Array_tree_map_handle_wrap CCC_Array_tree_map_handle
A container specific handle used to implement the Handle Interface.
Definition: array_tree_map.h:85

Modify an Occupied handle with a closure over user type T.

Parameters
[in]map_array_pointera pointer to the obtained handle.
[in]type_namethe name of the user type stored in the container.
[in]closure_over_Tthe code to be run on the reference to user type T, if Occupied. This may be a semicolon separated list of statements to execute on T or a section of code wrapped in braces {code here} which may be preferred for formatting.
Returns
a compound literal reference to the modified handle if it was occupied or a vacant handle if it was vacant.
Note
T is a reference to the user type stored in the handle guaranteed to be non-NULL if the closure executes.
#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
// Increment the count if found otherwise do nothing.
Array_tree_map_handle *h =
array_tree_map_and_modify_with(
handle_wrap(&array_tree_map, &k),
Word,
T->cnt++;
);
// Increment the count if found otherwise insert a default value.
Handle_index w =
array_tree_map_or_insert_with(
array_tree_map_and_modify_with(
handle_wrap(&array_tree_map, &k),
Word,
{ T->cnt++; }
),
(Word){.key = k, .cnt = 1}
);

Note that any code written is only evaluated if the handle is Occupied and the container can deliver the user type T. This means any function calls are lazily evaluated in the closure scope.

◆ CCC_array_tree_map_as

#define CCC_array_tree_map_as (   array_tree_map_pointer,
  type_name,
  array_index... 
)
Value:
CCC_private_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.

Parameters
[in]array_tree_map_pointera pointer to the map.
[in]type_namename of the user type stored in each slot of the map.
[in]array_indexthe index handle obtained from previous map operations.
Returns
a reference to the handle at handle in the map as the type the user has stored in the map.

◆ CCC_array_tree_map_declare_fixed

#define CCC_array_tree_map_declare_fixed (   fixed_map_type_name,
  type_name,
  capacity 
)
Value:
CCC_private_array_tree_map_declare_fixed(fixed_map_type_name, type_name, \
capacity)

Declare a fixed size map type for use in the stack, heap, or data segment. Does not return a value.

Parameters
[in]fixed_map_type_namethe user chosen name of the fixed sized map.
[in]type_namethe type the user plans to store in the map. It may have a key and value field as well as any additional fields. For set-like behavior, wrap a field in a struct/union (e.g. union int_node {int e;};).
[in]capacitythe desired number of user accessible nodes.
Warning
the map will use one slot of the specified capacity for a sentinel node. This is not important to the user unless an exact allocation count is needed in which case 1 should be added to desired capacity.

Once the location for the fixed size map is chosen–stack, heap, or data segment–provide a pointer to the map for the initialization macro.

struct Val
{
int key;
int val;
};
CCC_array_tree_map_declare_fixed(Small_fixed_map, struct Val,
64); static map static_map =
array_tree_map_initialize(
&(static Small_fixed_map){},
struct Val,
key,
array_tree_map_key_order,
NULL,
NULL,
array_tree_map_fixed_capacity(Small_fixed_map)
);
#define CCC_array_tree_map_declare_fixed(fixed_map_type_name, type_name, capacity)
Declare a fixed size map type for use in the stack, heap, or data segment. Does not return a value.
Definition: array_tree_map.h:160

Similarly, a fixed size map can be used on the stack.

struct Val
{
int key;
int val;
};
CCC_array_tree_map_declare_fixed(Small_fixed_map, struct Val,
64); int main(void)
{
map static_map =
array_tree_map_initialize(
&(Small_fixed_map){},
struct Val,
key,
array_tree_map_key_order,
NULL,
NULL,
array_tree_map_fixed_capacity(Small_fixed_map)
);
return 0;
}

The CCC_array_tree_map_fixed_capacity macro can be used to obtain the previously provided capacity when declaring the fixed map type. Finally, one could allocate a fixed size map on the heap; however, it is usually better to initialize a dynamic map and use the CCC_array_tree_map_reserve function for such a use case.

This macro is not needed when a dynamic resizing map is needed. For dynamic maps, simply pass NULL and 0 capacity to the initialization macro along with the desired allocation function.

◆ CCC_array_tree_map_equal_range_reverse_wrap

#define CCC_array_tree_map_equal_range_reverse_wrap (   array_tree_map_pointer,
  reverse_begin_and_reverse_end_key_pointers... 
)
Value:
{ \
CCC_array_tree_map_equal_range_reverse( \
(array_tree_map_pointer), \
(reverse_begin_and_reverse_end_key_pointers)) \
.private \
}
union CCC_Handle_range_reverse_wrap CCC_Handle_range_reverse
The result of a range_reverse query on iterable containers.
Definition: types.h:68

Returns a compound literal reference to the desired range_reverse. O(lg N).

Parameters
[in]array_tree_map_pointera pointer to the map.
[in]reverse_begin_and_reverse_end_key_pointerstwo pointers, the first to the start of the range_reverse the second to the end of the range_reverse.
Returns
a compound literal reference to the produced range_reverse associated with the enclosing scope. This reference is always non-NULL.

◆ CCC_array_tree_map_equal_range_wrap

#define CCC_array_tree_map_equal_range_wrap (   array_tree_map_pointer,
  begin_and_end_key_pointers... 
)
Value:
{ \
CCC_array_tree_map_equal_range((array_tree_map_pointer), \
(begin_and_end_key_pointers)) \
.private \
}
Definition: private_types.h:173

Returns a compound literal reference to the desired range. O(lg N).

Parameters
[in]array_tree_map_pointera pointer to the map.
[in]begin_and_end_key_pointerstwo pointers, the first to the start of the range the second to the end of the range.
Returns
a compound literal reference to the produced range associated with the enclosing scope. This reference is always non-NULL.

◆ CCC_array_tree_map_fixed_capacity

#define CCC_array_tree_map_fixed_capacity (   fixed_map_type_name)     CCC_private_array_tree_map_fixed_capacity(fixed_map_type_name)

Obtain the capacity previously chosen for the fixed size map type.

Parameters
[in]fixed_map_type_namethe name of a previously declared map.
Returns
the size_t capacity previously specified for this type by user.

◆ CCC_array_tree_map_from

#define CCC_array_tree_map_from (   type_key_field,
  compare,
  allocate,
  context_data,
  optional_capacity,
  type_compound_literal_array... 
)
Value:
CCC_private_array_tree_map_from(type_key_field, compare, allocate, \
context_data, optional_capacity, \
type_compound_literal_array)

Initialize a dynamic map at runtime from an initializer list.

Parameters
[in]type_key_fieldthe field of the struct used for key storage.
[in]comparethe CCC_Key_comparator the user intends to use.
[in]allocatethe required allocation function.
[in]context_datacontext data that is needed for hashing or comparison.
[in]optional_capacityoptionally 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_arraya 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}}).
Returns
the map directly initialized on the right hand side of the equality operator (i.e. CCC_Array_tree_map map = CCC_array_tree_map_from(...);)
Warning
An allocation function is required. This initializer is only available for dynamic maps.
When duplicate keys appear in the initializer list, the last occurrence replaces earlier ones by value (all fields are overwritten).
If initialization fails all subsequent queries, insertions, or removals will indicate the error: either memory related or lack of an allocation function provided.

Initialize a dynamic map at run time. This example requires no context data for initialization.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
int
main(void)
{
Array_tree_map static_map = array_tree_map_from(
key,
array_tree_map_key_order,
std_allocate,
NULL,
0,
(struct Val[]) {
{.key = 1, .val = 1},
{.key = 2, .val = 2},
{.key = 3, .val = 3},
},
);
return 0;
}

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.

◆ CCC_array_tree_map_handle_wrap

#define CCC_array_tree_map_handle_wrap (   array_tree_map_pointer,
  key_pointer 
)
Value:
{ \
CCC_array_tree_map_handle((array_tree_map_pointer), (key_pointer)) \
.private \
}

Obtains a handle for the provided key in the map for future use.

Parameters
[in]array_tree_map_pointerthe map to be searched.
[in]key_pointerthe key used to search the map matching the stored key type.
Returns
a compound literal reference to a specialized handle for use with other functions in the Handle Interface.
Warning
the contents of a handle should not be examined or modified. Use the provided functions, only.

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_array_tree_map_initialize

#define CCC_array_tree_map_initialize (   memory_pointer,
  type_name,
  type_key_field,
  compare,
  allocate,
  context_data,
  capacity 
)
Value:
CCC_private_array_tree_map_initialize(memory_pointer, type_name, \
type_key_field, compare, allocate, \
context_data, capacity)

Initializes the map at runtime or compile time.

Parameters
[in]memory_pointera pointer to the contiguous user types or ((T )NULL).
[in]type_namethe name of the user type stored in the map.
[in]type_key_fieldthe name of the field in user type used as key.
[in]comparethe key comparison function (see types.h).
[in]allocatethe allocation function or NULL if allocation is banned.
[in]context_dataa pointer to any context data for comparison or destruction.
[in]capacitythe capacity at data_pointer or 0.
Returns
the struct initialized tree map for direct assignment (i.e. CCC_Array_tree_map m = CCC_array_tree_map_initialize(...);).

◆ CCC_array_tree_map_insert_array_with

#define CCC_array_tree_map_insert_array_with (   map_array_pointer,
  type_compound_literal... 
)
Value:
CCC_private_array_tree_map_insert_array_with(map_array_pointer, \
type_compound_literal)

Write the contents of the compound literal type_compound_literal to a node.

Parameters
[in]map_array_pointera pointer to the obtained handle.
[in]type_compound_literalthe compound literal to write to a new slot.
Returns
a reference to the newly inserted or overwritten user type. NULL is returned if allocation failed or is not allowed when required.

◆ CCC_array_tree_map_insert_or_assign_with

#define CCC_array_tree_map_insert_or_assign_with (   array_tree_map_pointer,
  key,
  type_compound_literal... 
)
Value:
{ \
CCC_private_array_tree_map_insert_or_assign_with( \
array_tree_map_pointer, key, type_compound_literal) \
}
Definition: private_types.h:80

Inserts a new key value pair or overwrites the existing handle.

Parameters
[in]array_tree_map_pointerthe pointer to the handle hash map.
[in]keythe key to be searched in the map.
[in]type_compound_literalthe compound literal to insert or use for overwrite.
Returns
a compound literal reference to the handle of the existing or newly inserted value. Occupied indicates the key existed, Vacant indicates the key was absent. Unin any case provides the current value unless an error occurs that prevents insertion. An insertion error will flag such a case.

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.

◆ CCC_array_tree_map_or_insert_with

#define CCC_array_tree_map_or_insert_with (   map_array_pointer,
  type_compound_literal... 
)
Value:
CCC_private_array_tree_map_or_insert_with(map_array_pointer, \
type_compound_literal)

Lazily insert the desired key value into the handle if it is Vacant.

Parameters
[in]map_array_pointera pointer to the obtained handle.
[in]type_compound_literalthe compound literal to construct in place if the handle is Vacant.
Returns
a reference to the unwrapped user type in the handle, either the unmodified reference if the handle was Occupied or the newly inserted element if the handle was Vacant. NULL is returned if resizing is required but fails or is not allowed.

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.

◆ CCC_array_tree_map_remove_handle_wrap

#define CCC_array_tree_map_remove_handle_wrap (   map_array_pointer)
Value:
{ \
CCC_array_tree_map_remove_handle((map_array_pointer)).private \
}

Remove the handle from the map if Occupied.

Parameters
[in]map_array_pointera pointer to the map handle.
Returns
a compound literal reference to a handle containing NULL or a reference to the old handle. If Occupied a handle in the map existed and was removed. If Vacant, no prior handle existed to be removed.

Note that the reference to the removed handle is invalidated upon any further insertions.

◆ CCC_array_tree_map_remove_key_value_wrap

#define CCC_array_tree_map_remove_key_value_wrap (   array_tree_map_pointer,
  type_output_pointer 
)
Value:
{ \
CCC_array_tree_map_remove_key_value((array_tree_map_pointer), \
(type_output_pointer)) \
.private \
}

Removes the key value in the map storing the old value, if present, in the struct containing key value type provided by the user.

Parameters
[in]array_tree_map_pointerthe pointer to the tree map.
[out]type_output_pointertype user type map elem.
Returns
a compound literal reference to the removed handle. If Occupied type_output_pointer holds the old key value pair.. If Vacant the key value pair was not stored in the map. If bad input is provided an input error is set.

Note that this function may write to the user type struct.

◆ CCC_array_tree_map_swap_handle_wrap

#define CCC_array_tree_map_swap_handle_wrap (   array_tree_map_pointer,
  type_output_pointer 
)
Value:
{ \
CCC_array_tree_map_swap_handle((array_tree_map_pointer), \
(type_output_pointer)) \
.private \
}

Invariantly inserts the key value in type_output_pointer.

Parameters
[in]array_tree_map_pointerthe pointer to the tree map.
[out]type_output_pointertype user type map elem.
Returns
a compound literal reference to a type element in the table. If Vacant, no prior element with key existed and the type key value type remains unchanged. If Occupied the old value is written to the type wrapping key value type. If more space is needed but allocation fails or has been forbidden, an insert error is set.

Note that this function may write to the provided user type struct.

◆ CCC_array_tree_map_try_insert_with

#define CCC_array_tree_map_try_insert_with (   array_tree_map_pointer,
  key,
  type_compound_literal... 
)
Value:
{ \
CCC_private_array_tree_map_try_insert_with(array_tree_map_pointer, \
key, type_compound_literal) \
}

lazily insert type_compound_literal into the map at key if key is absent.

Parameters
[in]array_tree_map_pointera pointer to the map.
[in]keythe direct key r-value.
[in]type_compound_literalthe compound literal specifying the value.
Returns
a compound literal reference to the handle of the existing or newly inserted value. Occupied indicates the key existed, Vacant indicates the key was absent. Behavior in any case provides the current value unless an error occurs that prevents insertion. An insertion error will flag such a case.

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.

◆ CCC_array_tree_map_try_insert_wrap

#define CCC_array_tree_map_try_insert_wrap (   array_tree_map_pointer,
  type_pointer 
)
Value:
{ \
CCC_array_tree_map_try_insert((array_tree_map_pointer), \
(type_pointer)) \
.private \
}

Attempts to insert the key value type_pointer.

Parameters
[in]array_tree_map_pointerthe pointer to the map.
[in]type_pointerthe type user type map elem.
Returns
a compound literal reference to a handle. If Occupied, the handle contains a reference to the key value user type in the map and may be unwrapped. If Vacant the handle contains a reference to the newly inserted handle in the map. If more space is needed but allocation fails an insert error is set.

◆ CCC_array_tree_map_with_capacity

#define CCC_array_tree_map_with_capacity (   type_name,
  type_key_field,
  compare,
  allocate,
  context_data,
  capacity 
)
Value:
CCC_private_array_tree_map_with_capacity( \
type_name, type_key_field, compare, allocate, context_data, capacity)

Initialize a dynamic map at runtime with at least the specified capacity.

Parameters
[in]type_namethe name of the type being stored in the map.
[in]type_key_fieldthe field of the struct used for key storage.
[in]comparethe CCC_Key_comparator the user intends to use.
[in]allocatethe required allocation function.
[in]context_datacontext data that is needed for comparison.
[in]capacitythe 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.
Returns
the map directly initialized on the right hand side of the equality operator (i.e. CCC_Array_tree_map map = CCC_array_tree_map_with_capacity(...);)
Warning
An allocation function is required. This initializer is only available for dynamic maps.
If initialization fails all subsequent queries, insertions, or removals will indicate the error: either memory related or lack of an allocation function provided.

Initialize a dynamic map at run time. This example requires no context data for initialization.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
int
main(void)
{
Array_tree_map map = array_tree_map_with_capacity(
struct Val,
key,
array_tree_map_key_order,
std_allocate,
NULL,
4096
);
return 0;
}

Only dynamic maps may be initialized this way as it simply combines the steps of initialization and reservation.

◆ CCC_array_tree_map_with_compound_literal

#define CCC_array_tree_map_with_compound_literal (   type_key_field,
  compare,
  compound_literal 
)
Value:
CCC_private_array_tree_map_with_compound_literal(type_key_field, compare, \
compound_literal)

Initialize a fixed map at compile or runtime from a previously declared fixed map type with no allocation permission or context.

Parameters
[in]type_key_fieldthe field of the struct used for key storage.
[in]comparethe CCC_Key_comparator the user intends to use.
[in]compound_literalthe previously declared fixed map compound literal.
Returns
the map directly initialized on the right hand side of the equality operator (e.g. CCC_Array_tree_map map = CCC_array_tree_map_with_compound_literal(...);)

Initialize a fixed map.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
CCC_array_tree_map_declare_fixed(Small_fixed_map, struct Val, 64);
static Array_tree_map map = array_tree_map_with_compound_literal(
key,
array_tree_map_key_order,
(Small_fixed_map){},
);

This can help eliminate boilerplate in initializers.

◆ CCC_array_tree_map_with_context_compound_literal

#define CCC_array_tree_map_with_context_compound_literal (   type_key_field,
  compare,
  context,
  compound_literal 
)
Value:
CCC_private_array_tree_map_with_context_compound_literal( \
type_key_field, compare, context, compound_literal)

Initialize a fixed map at compile or runtime from a previously declared fixed map type with no allocation permission.

Parameters
[in]type_key_fieldthe field of the struct used for key storage.
[in]comparethe CCC_Key_comparator the user intends to use.
[in]contextcontext for the map.
[in]compound_literalthe previously declared fixed map compound literal.
Returns
the map directly initialized on the right hand side of the equality operator (e.g. CCC_Array_tree_map map = CCC_array_tree_map_with_compound_literal(...);)

Initialize a fixed map.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
CCC_array_tree_map_declare_fixed(Small_fixed_map, struct Val, 64);
static Array_tree_map map = array_tree_map_with_compound_literal(
key,
array_tree_map_key_order,
&module_context,
(Small_fixed_map){},
);

This can help eliminate boilerplate in initializers.

Typedef Documentation

◆ CCC_Array_tree_map

An array tree map offers O(lg N) search and erase, and amortized O(lg N) insert.

Warning
it is undefined behavior to access an uninitialized container.

An array tree map can be initialized on the stack, heap, or data segment at runtime or compile time.

◆ CCC_Array_tree_map_handle

A container specific handle used to implement the Handle Interface.

Warning
it is undefined behavior to access an uninitialized container.

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.

Function Documentation

◆ CCC_array_tree_map_and_modify()

CCC_Array_tree_map_handle * CCC_array_tree_map_and_modify ( CCC_Array_tree_map_handle handle,
CCC_Type_modifier modify 
)

Modifies the provided handle if it is Occupied.

Parameters
[in]handlethe handle obtained from a handle function or macro.
[in]modifyan update function in which the context argument is unused.
Returns
the updated handle if it was Occupied or the unmodified vacant handle.

This function is intended to make the function chaining in the Handle Interface more succinct if the handle will be modified in place based on its own value without the need of the context argument a CCC_Type_modifier can provide.

◆ CCC_array_tree_map_and_modify_context()

CCC_Array_tree_map_handle * CCC_array_tree_map_and_modify_context ( CCC_Array_tree_map_handle handle,
CCC_Type_modifier modify,
void *  context 
)

Modifies the provided handle if it is Occupied.

Parameters
[in]handlethe handle obtained from a handle function or macro.
[in]modifyan update function that requires context data.
[in]contextcontext data required for the update.
Returns
the updated handle if it was Occupied or the unmodified vacant handle.

This function makes full use of a CCC_Type_modifier capability, meaning a complete CCC_update object will be passed to the update function callback.

◆ CCC_array_tree_map_at()

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.

Parameters
[in]handlea pointer to the map.
[in]indexthe stable handle obtained by the user.
Returns
a pointer to the user type stored at the specified handle or NULL if an out of range handle or handle representing no data is provided.
Warning
this function can only check if the handle value is in range. If a handle represents a slot that has been taken by a new element because the old one has been removed that new element data will be returned.
do not try to access data in the table manually with a handle. Always use this provided interface function when a reference to data is needed.

◆ CCC_array_tree_map_begin()

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).

Parameters
[in]mapa pointer to the map.
Returns
a handle for the minimum element of the map.

◆ CCC_array_tree_map_capacity()

CCC_Count CCC_array_tree_map_capacity ( CCC_Array_tree_map const *  map)

Returns the capacity of the map representing total available slots.

Parameters
[in]mapthe map.
Returns
the capacity or an argument error is set if array_tree_map is NULL.

◆ CCC_array_tree_map_clear()

CCC_Result CCC_array_tree_map_clear ( CCC_Array_tree_map map,
CCC_Type_destructor destroy 
)

Frees all slots in the map for use without affecting capacity.

Parameters
[in]mapthe map to be cleared.
[in]destroythe destructor for each element. NULL can be passed if no maintenance is required on the elements in the map before their slots are forfeit.

If NULL is passed as the destructor function time is O(1), else O(size).

◆ CCC_array_tree_map_clear_and_free()

CCC_Result CCC_array_tree_map_clear_and_free ( CCC_Array_tree_map map,
CCC_Type_destructor destroy 
)

Frees all slots in the map and frees the underlying buffer.

Parameters
[in]mapthe map to be cleared.
[in]destroythe destructor for each element. NULL can be passed if no maintenance is required on the elements in the map before their slots are forfeit.
Returns
the result of free operation. If no allocate function is provided it is an error to attempt to free the Buffer and a memory error is returned. Otherwise, an OK result is returned.

If NULL is passed as the destructor function time is O(1), else O(size).

◆ CCC_array_tree_map_clear_and_free_reserve()

CCC_Result CCC_array_tree_map_clear_and_free_reserve ( CCC_Array_tree_map map,
CCC_Type_destructor destroy,
CCC_Allocator allocate 
)

Frees all slots in the map and frees the underlying Buffer that was previously dynamically reserved with the reserve function.

Parameters
[in]mapthe map to be cleared.
[in]destroythe destructor for each element. NULL can be passed if no maintenance is required on the elements in the array_tree_map before their slots are dropped.
[in]allocatethe required allocation function to provide to a dynamically reserved array_tree_map. Any context data provided upon initialization will be passed to the allocation function when called.
Returns
the result of free operation. OK if success, or an error status to indicate the error.
Warning
It is an error to call this function on a array_tree_map that was not reserved with the provided CCC_Allocator. The array_tree_map must have existing memory to free.

This function covers the edge case of reserving a dynamic capacity for a array_tree_map at runtime but denying the array_tree_map allocation permission to resize. This can help prevent a map from growing untree. The user in this case knows the map does not have allocation permission and therefore no further memory will be dedicated to the array_tree_map.

However, to free the map in such a case this function must be used because the map has no ability to free itself. Just as the allocation function is required to reserve memory so to is it required to free memory.

This function will work normally if called on a map with allocation permission however the normal CCC_array_tree_map_clear_and_free is sufficient for that use case.

◆ CCC_array_tree_map_contains()

CCC_Tribool CCC_array_tree_map_contains ( CCC_Array_tree_map const *  map,
void const *  key 
)

Searches the map for the presence of key.

Parameters
[in]mapthe map to be searched.
[in]keypointer to the key matching the key type of the user struct.
Returns
true if the struct containing key is stored, false if not. Error if array_tree_map or key is NULL.

◆ CCC_array_tree_map_copy()

CCC_Result CCC_array_tree_map_copy ( CCC_Array_tree_map destination,
CCC_Array_tree_map const *  source,
CCC_Allocator allocate 
)

Copy the map at source to destination.

Parameters
[in]destinationthe initialized destination for the copy of the source map.
[in]sourcethe initialized source of the map.
[in]allocatethe allocation function to resize destination or NULL.
Returns
the result of the copy operation. If the destination capacity is less than the source capacity and no allocation function is provided an input error is returned. If resizing is required and resizing of destination fails a memory error is returned.
Note
destination must have capacity greater than or equal to source. If destination capacity is less than source, an allocation function must be provided with the allocate argument.

Note that there are two ways to copy data from source to destination: provide sufficient memory and pass NULL as allocate, or allow the copy function to take care of allocation for the copy.

Manual memory management with no allocation function provided.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
CCC_array_tree_map_declare_fixed(Small_fixed_map, struct Val,
64); static map source =
array_tree_map_initialize(
&(static Small_fixed_map){},
struct Val,
key,
array_tree_map_key_order,
NULL,
NULL,
array_tree_map_fixed_capacity(Small_fixed_map)
);
insert_rand_vals(&source);
static map destination = array_tree_map_initialize(
&(static Small_fixed_map){},
struct Val,
key,
array_tree_map_key_order,
NULL,
NULL,
array_tree_map_fixed_capacity(Small_fixed_map)
);
CCC_Result res = array_tree_map_copy(&destination, &source, NULL);
CCC_Result
A result of actions on containers.
Definition: types.h:148

The above requires destination capacity be greater than or equal to source capacity. Here is memory management handed over to the copy function.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
static Array_adaptive_map source = array_tree_map_initialize(
NULL,
struct Val,
key,
key_order,
std_allocate,
NULL,
0
);
insert_rand_vals(&source);
static Array_adaptive_map destination = array_tree_map_initialize(
NULL,
struct Val,
key,
key_order,
std_allocate,
NULL,
0
);
CCC_Result res = array_tree_map_copy(&destination, &source, std_allocate);

The above allows destination to have a capacity less than that of the source as long as copy has been provided an allocation function to resize destination. Note that this would still work if copying to a destination that the user wants as a fixed size map.

#define ARRAY_TREE_MAP_USING_NAMESPACE_CCC
struct Val
{
int key;
int val;
};
static Array_adaptive_map source = array_tree_map_initialize(
NULL,
struct Val,
key,
key_order,
std_allocate,
NULL,
0
);
insert_rand_vals(&source);
static Array_adaptive_map destination = array_tree_map_initialize(
NULL,
struct Val,
key,
key_order,
NULL,
NULL,
0
);
CCC_Result res = array_tree_map_copy(&destination, &source, std_allocate);

The above sets up destination with fixed size while source is a dynamic map. Because an allocation function is provided, the destination is resized once for the copy and retains its fixed size after the copy is complete. This would require the user to manually free the underlying Buffer at destination eventually if this method is used. Usually it is better to allocate the memory explicitly before the copy if copying between maps without allocation permission.

These options allow users to stay consistent across containers with their memory management strategies.

◆ CCC_array_tree_map_count()

CCC_Count CCC_array_tree_map_count ( CCC_Array_tree_map const *  map)

Returns the count of map occupied slots.

Parameters
[in]mapthe map.
Returns
the size of the map or an argument error is set if array_tree_map is NULL.

◆ CCC_array_tree_map_end()

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).

Parameters
[in]mapa pointer to the map.
Returns
a handle for the maximum element of the map.

◆ CCC_array_tree_map_equal_range()

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).

Parameters
[in]mapa pointer to the map.
[in]begin_keya pointer to the key intended as the start of the range.
[in]end_keya pointer to the key intended as the end of the range.
Returns
a range containing the first element NOT LESS than the begin_key and the first element GREATER than end_key.

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:

for (CCC_Handle_index index = range_begin(&range);
index != range_end(&range);
index = next(&map, index))
{}
size_t CCC_Handle_index
A stable index to user data in a container that uses a flat array as the underlying storage method.
Definition: types.h:109

This avoids any possible errors in handling an end range element that is in the map versus the end map sentinel.

◆ CCC_array_tree_map_equal_range_reverse()

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).

Parameters
[in]mapa pointer to the map.
[in]reverse_begin_keya pointer to the key intended as the start of the range_reverse.
[in]reverse_end_keya pointer to the key intended as the end of the range_reverse.
Returns
a range_reverse containing the first element NOT GREATER than the begin_key and the first element LESS than reverse_end_key.

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:

for (CCC_Handle_index index = range_reverse_begin(&range);
index != range_reverse_end(&range);
index = next(&map, index))
{}

This avoids any possible errors in handling an reverse_end range_reverse element that is in the map versus the end map sentinel.

◆ CCC_array_tree_map_get_key_value()

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.

Parameters
[in]mapthe tree map to search.
[in]keythe key to search matching stored key type.
Returns
a view of the map handle if it is present, else NULL.

◆ CCC_array_tree_map_handle()

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.

Parameters
[in]mapthe map to be searched.
[in]keythe key used to search the map matching the stored key type.
Returns
a specialized handle for use with other functions in the Handle Interface.
Warning
the contents of a handle should not be examined or modified. Use the provided functions, only.

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_array_tree_map_handle_status()

CCC_Handle_status CCC_array_tree_map_handle_status ( CCC_Array_tree_map_handle const *  handle)

Obtain the handle status from a container handle.

Parameters
[in]handlea pointer to the handle.
Returns
the status stored in the handle after the required action on the container completes. If handle is NULL a handle input error is returned so ensure e is non-NULL to avoid an inaccurate status returned.

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_array_tree_map_insert_error()

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.

Parameters
[in]handlethe handle from a query to the table via function or macro.
Returns
true if a handle obtained from an insertion attempt failed to insert due to an allocation failure when allocation success was expected. Error if handle is NULL.

◆ CCC_array_tree_map_insert_handle()

CCC_Handle_index CCC_array_tree_map_insert_handle ( CCC_Array_tree_map_handle const *  handle,
void const *  type 
)

Inserts the provided user type invariantly.

Parameters
[in]handlethe handle returned from a call obtaining a handle.
[in]typea type struct the user intends to insert.
Returns
a pointer to the inserted element or NULL upon allocation failure.

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_array_tree_map_insert_or_assign()

CCC_Handle CCC_array_tree_map_insert_or_assign ( CCC_Array_tree_map map,
void const *  type 
)

Invariantly inserts or overwrites a user struct into the map.

Parameters
[in]mapa pointer to the handle hash map.
[in]typethe type user struct key value.
Returns
a handle. If Occupied a handle was overwritten by the new key value. If Vacant no prior map handle existed.

Note that this function can be used when the old user type is not needed but the information regarding its presence is helpful.

◆ CCC_array_tree_map_is_empty()

CCC_Tribool CCC_array_tree_map_is_empty ( CCC_Array_tree_map const *  map)

Returns the size status of the map.

Parameters
[in]mapthe map.
Returns
true if empty else false. Error if map is NULL.

◆ CCC_array_tree_map_next()

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).

Parameters
[in]mapa pointer to the map.
[in]iteratora pointer to the intrusive map element of the current iterator.
Returns
a handle for the next user type stored in the map in an inorder traversal.

◆ CCC_array_tree_map_occupied()

CCC_Tribool CCC_array_tree_map_occupied ( CCC_Array_tree_map_handle const *  handle)

Returns the Vacant or Occupied status of the handle.

Parameters
[in]handlethe handle from a query to the map via function or macro.
Returns
true if the handle is occupied, false if not. Error if handle is NULL.

◆ CCC_array_tree_map_or_insert()

CCC_Handle_index CCC_array_tree_map_or_insert ( CCC_Array_tree_map_handle const *  handle,
void const *  type 
)

Inserts the provided user type if the handle is Vacant.

Parameters
[in]handlethe handle obtained via function or macro call.
[in]typethe type struct to be inserted to a Vacant handle.
Returns
a pointer to handle in the map invariantly. NULL on error.

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_array_tree_map_remove_handle()

CCC_Handle CCC_array_tree_map_remove_handle ( CCC_Array_tree_map_handle const *  handle)

Remove the handle from the map if Occupied.

Parameters
[in]handlea pointer to the map handle.
Returns
a handle containing NULL or a reference to the old handle. If Occupied a handle in the map existed and was removed. If Vacant, no prior handle existed to be removed.
Warning
the reference to the removed handle is invalidated upon any further insertions.

◆ CCC_array_tree_map_remove_key_value()

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 struct containing type_output provided by the user.

Parameters
[in]mapthe pointer to the tree map.
[out]type_outputthe type user type map elem.
Returns
the removed handle. If Occupied key value type holds the old key value pair. If Vacant the key value pair was not stored in the map. If bad input is provided an input error is set.

Note that this function may write to the user type struct.

◆ CCC_array_tree_map_reserve()

CCC_Result CCC_array_tree_map_reserve ( CCC_Array_tree_map map,
size_t  to_add,
CCC_Allocator allocate 
)

Reserves space for at least to_add more elements.

Parameters
[in]mapa pointer to the array tree map.
[in]to_addthe number of elements to add to the current size.
[in]allocatethe allocation function to use to reserve memory.
Returns
the result of the reservation. OK if successful, otherwise an error status is returned.
Note
see the CCC_array_tree_map_clear_and_free_reserve function if this function is being used for a one-time dynamic reservation.

This function can be used for a dynamic map with or without allocation permission. If the map has allocation permission, it will reserve the required space and later resize if more space is needed.

If the map has been initialized with no allocation permission and no memory this function can serve as a one-time reservation. This is helpful when a fixed size is needed but that size is only known dynamically at runtime. To free the map in such a case see the CCC_array_tree_map_clear_and_free_reserve function.

◆ CCC_array_tree_map_reverse_begin()

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).

Parameters
[in]mapa pointer to the map.
Returns
a handle for the maximum element of the map.

◆ CCC_array_tree_map_reverse_end()

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).

Parameters
[in]mapa pointer to the map.
Returns
a handle for the minimum element of the map.

◆ CCC_array_tree_map_reverse_next()

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).

Parameters
[in]mapa pointer to the map.
[in]iteratora pointer to the intrusive map element of the current iterator.
Returns
a handle for the reverse_next user type stored in the map in a reverse inorder traversal.

◆ CCC_array_tree_map_swap_handle()

CCC_Handle CCC_array_tree_map_swap_handle ( CCC_Array_tree_map map,
void *  type_output 
)

Invariantly inserts the key value in type_output.

Parameters
[in]mapthe pointer to the tree map.
[out]type_outputthe type user type map elem.
Returns
a type element in the table. If Vacant, no prior element with key existed and the type key value type remains unchanged. If Occupied the old value is written to the type key value type. If more space is needed but allocation fails or has been forbidden, an insert error is set.

Note that this function may write to the provided user type struct.

◆ CCC_array_tree_map_try_insert()

CCC_Handle CCC_array_tree_map_try_insert ( CCC_Array_tree_map map,
void const *  type 
)

Attempts to insert the key value in type.

Parameters
[in]mapthe pointer to the map.
[in]typethe type user type map elem.
Returns
a handle. If Occupied, the handle contains a reference to the key value user type in the map and may be unwrapped. If Vacant the handle contains a reference to the newly inserted handle in the map. If more space is needed but allocation fails, an insert error is set.

◆ CCC_array_tree_map_unwrap()

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.

Parameters
[in]handlethe handle from a query to the map via function or macro.
Returns
a view into the table handle if one is present, or NULL.

◆ CCC_array_tree_map_validate()

CCC_Tribool CCC_array_tree_map_validate ( CCC_Array_tree_map const *  map)

Validation of invariants for the map.

Parameters
[in]mapthe map to validate.
Returns
true if all invariants hold, false if corruption occurs. Error if array_tree_map is NULL.