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


Go to the source code of this file.
The Adaptive Map Interface.
An adaptive map offers storage and retrieval of elements sorted on the user specified key. Once allocated, this container will not move elements in memory making this container assume pointer stability. Because the data structure is self-optimizing it is not a suitable map when strict sub-linear runtime bounds are needed. Also, searching the map is not a const thread-safe operation as indicated by the function signatures. The map is optimized upon every new search, attempting to adapt to the usage pattern. In many cases the self-optimizing structure of the map can be beneficial when considering non-uniform access patterns. In the best case, repeated searches of the same value yield an O(1) access and many other frequently searched values will be obtained in constant time.
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_adaptive_map_initialize(struct_name, type_intruder_field_name, type_key_field_name, key_order, allocate, context) |
| Initializes the adaptive map at runtime or compile time. | |
| #define | CCC_adaptive_map_from(type_intruder_field_name, type_key_field_name, compare, allocate, destroy, context_data, compound_literal_array...) |
| Initializes a dynamic adaptive map at runtime. | |
Entry Interface | |
Obtain and operate on container entries for efficient queries when non-trivial control flow is needed. | |
| #define | CCC_adaptive_map_swap_entry_wrap(map_pointer, type_intruder_pointer, temp_intruder_pointer) |
| Invariantly inserts the key value wrapping the provided intruder. | |
| #define | CCC_adaptive_map_try_insert_wrap(map_pointer, type_intruder_pointer) |
| Attempts to insert the key value wrapping type_intruder. | |
| #define | CCC_adaptive_map_try_insert_with(map_pointer, key, compound_literal_type...) |
| lazily insert compound_literal_type into the map at key if key is absent. | |
| #define | CCC_adaptive_map_insert_or_assign_with(map_pointer, key, compound_literal_type...) |
| Inserts a new key value pair or overwrites the existing entry. | |
| #define | CCC_adaptive_map_remove_key_value_wrap(map_pointer, type_output_intruder_pointer) |
| Removes the key value in the map storing the old value, if present, in the struct containing type_output_intruder provided by the user. | |
| #define | CCC_adaptive_map_entry_wrap(map_pointer, key_pointer) |
| Obtains an entry for the provided key in the map for future use. | |
| #define | CCC_adaptive_map_and_modify_with(adaptive_map_entry_pointer, type_name, closure_over_T...) |
| Modify an Occupied entry with a closure over user type T. | |
| #define | CCC_adaptive_map_or_insert_with(adaptive_map_entry_pointer, type_compound_literal...) |
| Lazily insert the desired key value into the entry if it is Vacant. | |
| #define | CCC_adaptive_map_insert_entry_with(adaptive_map_entry_pointer, type_compound_literal...) |
| Write the contents of the compound literal type_compound_literal to a node. | |
| #define | CCC_adaptive_map_remove_entry_wrap(adaptive_map_entry_pointer) |
| Remove the entry from the map if Occupied. | |
| CCC_Entry | CCC_adaptive_map_swap_entry (CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_intruder, CCC_Adaptive_map_node *temp_intruder) |
| Invariantly inserts the key value wrapping type_intruder. | |
| CCC_Entry | CCC_adaptive_map_try_insert (CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_intruder) |
| Attempts to insert the key value wrapping type_intruder. | |
| CCC_Entry | CCC_adaptive_map_insert_or_assign (CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_intruder) |
| Invariantly inserts or overwrites a user struct into the map. | |
| CCC_Entry | CCC_adaptive_map_remove_key_value (CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_output_intruder) |
| Removes the key value in the map storing the old value, if present, in the struct containing type_output_intruder provided by the user. | |
| CCC_Adaptive_map_entry | CCC_adaptive_map_entry (CCC_Adaptive_map *map, void const *key) |
| Obtains an entry for the provided key in the map for future use. | |
| CCC_Adaptive_map_entry * | CCC_adaptive_map_and_modify (CCC_Adaptive_map_entry *entry, CCC_Type_modifier *modify) |
| Modifies the provided entry if it is Occupied. | |
| CCC_Adaptive_map_entry * | CCC_adaptive_map_and_modify_context (CCC_Adaptive_map_entry *entry, CCC_Type_modifier *modify, void *context) |
| Modifies the provided entry if it is Occupied. | |
| void * | CCC_adaptive_map_or_insert (CCC_Adaptive_map_entry const *entry, CCC_Adaptive_map_node *type_intruder) |
| Inserts the struct with handle type_intruder if the entry is Vacant. | |
| void * | CCC_adaptive_map_insert_entry (CCC_Adaptive_map_entry const *entry, CCC_Adaptive_map_node *type_intruder) |
| Inserts the provided entry invariantly. | |
| CCC_Entry | CCC_adaptive_map_remove_entry (CCC_Adaptive_map_entry *entry) |
| Remove the entry from the map if Occupied. | |
| void * | CCC_adaptive_map_unwrap (CCC_Adaptive_map_entry const *entry) |
| Unwraps the provided entry to obtain a view into the map element. | |
| CCC_Tribool | CCC_adaptive_map_occupied (CCC_Adaptive_map_entry const *entry) |
| Returns the Vacant or Occupied status of the entry. | |
| CCC_Tribool | CCC_adaptive_map_insert_error (CCC_Adaptive_map_entry const *entry) |
| Provides the status of the entry should an insertion follow. | |
| CCC_Entry_status | CCC_adaptive_map_entry_status (CCC_Adaptive_map_entry const *entry) |
| Obtain the entry status from a container entry. | |
Iterator Interface | |
Obtain and manage iterators over the container. | |
| #define | CCC_adaptive_map_equal_range_wrap(map_pointer, begin_and_end_key_pointers...) |
| Returns a compound literal reference to the desired range. Amortized O(lg N). | |
| #define | CCC_adaptive_map_equal_range_reverse_wrap( map_pointer, reverse_begin_and_reverse_end_key_pointers...) |
| Returns a compound literal reference to the desired range_reverse. Amortized O(lg N). | |
| CCC_Range | CCC_adaptive_map_equal_range (CCC_Adaptive_map *map, void const *begin_key, void const *end_key) |
| Return an iterable range of values from [begin_key, end_key). Amortized O(lg N). | |
| CCC_Range_reverse | CCC_adaptive_map_equal_range_reverse (CCC_Adaptive_map *map, void const *reverse_begin_key, void const *reverse_end_key) |
| Return an iterable range_reverse of values from [begin_key, end_key). Amortized O(lg N). | |
| void * | CCC_adaptive_map_begin (CCC_Adaptive_map const *map) |
| Return the start of an inorder traversal of the map. Amortized O(lg N). | |
| void * | CCC_adaptive_map_reverse_begin (CCC_Adaptive_map const *map) |
| Return the start of a reverse inorder traversal of the map. Amortized O(lg N). | |
| void * | CCC_adaptive_map_next (CCC_Adaptive_map const *map, CCC_Adaptive_map_node const *iterator_intruder) |
| Return the next element in an inorder traversal of the map. O(1). | |
| void * | CCC_adaptive_map_reverse_next (CCC_Adaptive_map const *map, CCC_Adaptive_map_node const *iterator_intruder) |
| Return the reverse_next element in a reverse inorder traversal of the map. O(1). | |
| void * | CCC_adaptive_map_end (CCC_Adaptive_map const *map) |
| Return the end of an inorder traversal of the map. O(1). | |
| void * | CCC_adaptive_map_reverse_end (CCC_Adaptive_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_Adaptive_map | CCC_Adaptive_map |
| A self-optimizing data structure offering amortized O(lg N) search, insert, and erase and pointer stability. | |
| typedef struct CCC_Adaptive_map_node | CCC_Adaptive_map_node |
| The intrusive element for the user defined struct being stored in the map. | |
| typedef union CCC_Adaptive_map_entry_wrap | CCC_Adaptive_map_entry |
| A container specific entry used to implement the Entry Interface. | |
Membership Interface | |
Test membership or obtain references to stored user types directly. | |
| CCC_Tribool | CCC_adaptive_map_contains (CCC_Adaptive_map *map, void const *key) |
| Searches the map for the presence of key. | |
| void * | CCC_adaptive_map_get_key_value (CCC_Adaptive_map *map, void const *key) |
| Returns a reference into the map at entry key. | |
Deallocation Interface | |
Destroy the container. | |
| CCC_Result | CCC_adaptive_map_clear (CCC_Adaptive_map *map, CCC_Type_destructor *destroy) |
| Pops every element from the map calling destructor if destructor is non-NULL. O(N). | |
State Interface | |
Obtain the container state. | |
| CCC_Tribool | CCC_adaptive_map_is_empty (CCC_Adaptive_map const *map) |
| Returns the size status of the map. | |
| CCC_Count | CCC_adaptive_map_count (CCC_Adaptive_map const *map) |
| Returns the count of occupied map nodes. | |
| CCC_Tribool | CCC_adaptive_map_validate (CCC_Adaptive_map const *map) |
| Validation of invariants for the map. | |
| #define CCC_adaptive_map_and_modify_with | ( | adaptive_map_entry_pointer, | |
| type_name, | |||
| closure_over_T... | |||
| ) |
Modify an Occupied entry with a closure over user type T.
| [in] | adaptive_map_entry_pointer | a pointer to the obtained entry. |
| [in] | type_name | the name of the user type stored in the container. |
| [in] | closure_over_T | the 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. |
Note that any code written is only evaluated if the entry is Occupied and the container can deliver the user type T. This means any function calls are lazily evaluated in the closure scope.
| #define CCC_adaptive_map_entry_wrap | ( | map_pointer, | |
| key_pointer | |||
| ) |
Obtains an entry for the provided key in the map for future use.
| [in] | map_pointer | the map to be searched. |
| [in] | key_pointer | the key used to search the map matching the stored key type. |
An entry is a search result that provides either an Occupied or Vacant entry in the map. An occupied entry signifies that the search was successful. A Vacant entry means the search was not successful but a handle is gained to where in the map such an element should be inserted.
An entry is rarely useful on its own. It should be passed in a functional style to subsequent calls in the Entry Interface.
| #define CCC_adaptive_map_equal_range_reverse_wrap | ( | map_pointer, | |
| reverse_begin_and_reverse_end_key_pointers... | |||
| ) |
Returns a compound literal reference to the desired range_reverse. Amortized O(lg N).
| [in] | map_pointer | a pointer to the map. |
| [in] | reverse_begin_and_reverse_end_key_pointers | two pointers, one to the start of the range_reverse and a second to the end of the range_reverse. |
| #define CCC_adaptive_map_equal_range_wrap | ( | map_pointer, | |
| begin_and_end_key_pointers... | |||
| ) |
Returns a compound literal reference to the desired range. Amortized O(lg N).
| [in] | map_pointer | a pointer to the map. |
| [in] | begin_and_end_key_pointers | two pointers, one to the start of the range and a second to the end of the range. |
| #define CCC_adaptive_map_from | ( | type_intruder_field_name, | |
| type_key_field_name, | |||
| compare, | |||
| allocate, | |||
| destroy, | |||
| context_data, | |||
| compound_literal_array... | |||
| ) |
Initializes a dynamic adaptive map at runtime.
| [in] | type_intruder_field_name | the name of the intrusive map elem field. |
| [in] | type_key_field_name | the name of the field in user type used as key. |
| [in] | compare | the key comparison function (see types.h). |
| [in] | allocate | the allocation function or NULL if allocation is banned. |
| [in] | destroy | the destructor function used to act on every node in case initialization of new nodes fails and map is emptied in a failure state. |
| [in] | context_data | a pointer to any context data for comparison or destruction. |
| [in] | compound_literal_array | the array of user types to insert into the map (e.g. (struct My_type[]){ {.key = 1, .val = 1}, {.key = 2, .val = 2}}). |
| #define CCC_adaptive_map_initialize | ( | struct_name, | |
| type_intruder_field_name, | |||
| type_key_field_name, | |||
| key_order, | |||
| allocate, | |||
| context | |||
| ) |
Initializes the adaptive map at runtime or compile time.
| [in] | struct_name | the user type wrapping the intrusive element. |
| [in] | type_intruder_field_name | the name of the intrusive map element field. |
| [in] | type_key_field_name | the name of the field in user type used as key. |
| [in] | key_order | the key comparison function (see types.h). |
| [in] | allocate | the allocation function or NULL if allocation is banned. |
| [in] | context | a pointer to any context data for comparison or destruction. |
| #define CCC_adaptive_map_insert_entry_with | ( | adaptive_map_entry_pointer, | |
| type_compound_literal... | |||
| ) |
Write the contents of the compound literal type_compound_literal to a node.
| [in] | adaptive_map_entry_pointer | a pointer to the obtained entry. |
| [in] | type_compound_literal | the compound literal to write to a new slot. |
| #define CCC_adaptive_map_insert_or_assign_with | ( | map_pointer, | |
| key, | |||
| compound_literal_type... | |||
| ) |
Inserts a new key value pair or overwrites the existing entry.
| [in] | map_pointer | the pointer to the flat hash map. |
| [in] | key | the key to be searched in the map. |
| [in] | compound_literal_type | the compound literal to insert or use for overwrite. |
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_adaptive_map_or_insert_with | ( | adaptive_map_entry_pointer, | |
| type_compound_literal... | |||
| ) |
Lazily insert the desired key value into the entry if it is Vacant.
| [in] | adaptive_map_entry_pointer | a pointer to the obtained entry. |
| [in] | type_compound_literal | the compound literal to construct in place if the entry 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 entry is Occupied.
| #define CCC_adaptive_map_remove_entry_wrap | ( | adaptive_map_entry_pointer | ) |
Remove the entry from the map if Occupied.
| [in] | adaptive_map_entry_pointer | a pointer to the map entry. |
Note that if allocation is permitted the old element is freed and the entry will contain a NULL reference. If allocation is prohibited the entry can be unwrapped to obtain the old user struct stored in the map and the user may free or use as needed.
| #define CCC_adaptive_map_remove_key_value_wrap | ( | map_pointer, | |
| type_output_intruder_pointer | |||
| ) |
Removes the key value in the map storing the old value, if present, in the struct containing type_output_intruder provided by the user.
| [in] | map_pointer | the pointer to the adaptive map. |
| [out] | type_output_intruder_pointer | the handle to the user type wrapping map node. |
Note that this function may write to the struct containing the second parameter and wraps it in an entry to provide information about the old value.
If allocation has been prohibited upon initialization then the entry returned contains the previously stored user type, if any, and nothing is written to the type_output_intruder. It is then the user's responsibility to manage their previously stored memory as they see fit.
| #define CCC_adaptive_map_swap_entry_wrap | ( | map_pointer, | |
| type_intruder_pointer, | |||
| temp_intruder_pointer | |||
| ) |
Invariantly inserts the key value wrapping the provided intruder.
| [in] | map_pointer | the pointer to the adaptive map. |
| [in] | type_intruder_pointer | the handle to the user type wrapping this handle. |
| [in] | temp_intruder_pointer | handle to space for swapping in the old value, if present. The same user type stored in the map should wrap temp_intruder. |
Note that this function may write to the struct containing temp_intruder and wraps it in an entry to provide information about the old value.
| #define CCC_adaptive_map_try_insert_with | ( | map_pointer, | |
| key, | |||
| compound_literal_type... | |||
| ) |
lazily insert compound_literal_type into the map at key if key is absent.
| [in] | map_pointer | a pointer to the map. |
| [in] | key | the direct key r-value. |
| [in] | compound_literal_type | 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_adaptive_map_try_insert_wrap | ( | map_pointer, | |
| type_intruder_pointer | |||
| ) |
Attempts to insert the key value wrapping type_intruder.
| [in] | map_pointer | the pointer to the map. |
| [in] | type_intruder_pointer | the handle to the user type wrapping map node. |
| typedef struct CCC_Adaptive_map CCC_Adaptive_map |
A self-optimizing data structure offering amortized O(lg N) search, insert, and erase and pointer stability.
An adaptive map can be initialized on the stack, heap, or data segment at runtime or compile time.
| typedef union CCC_Adaptive_map_entry_wrap CCC_Adaptive_map_entry |
A container specific entry used to implement the Entry Interface.
The Entry Interface offers efficient search and subsequent insertion, deletion, or value update based on the needs of the user.
| typedef struct CCC_Adaptive_map_node CCC_Adaptive_map_node |
The intrusive element for the user defined struct being stored in the map.
Note that if allocation is not permitted, insertions functions accepting this type as an argument assume it to exist in pre-allocated memory that will exist with the appropriate lifetime and scope for the user's needs; the container does not allocate or free in this case.
| CCC_Adaptive_map_entry * CCC_adaptive_map_and_modify | ( | CCC_Adaptive_map_entry * | entry, |
| CCC_Type_modifier * | modify | ||
| ) |
Modifies the provided entry if it is Occupied.
| [in] | entry | the entry obtained from an entry function or macro. |
| [in] | modify | an update function in which the context argument is unused. |
This function is intended to make the function chaining in the Entry Interface more succinct if the entry will be modified in place based on its own value without the need of the context argument a CCC_Type_modifier can provide.
| CCC_Adaptive_map_entry * CCC_adaptive_map_and_modify_context | ( | CCC_Adaptive_map_entry * | entry, |
| CCC_Type_modifier * | modify, | ||
| void * | context | ||
| ) |
Modifies the provided entry if it is Occupied.
| [in] | entry | the entry obtained from an entry function or macro. |
| [in] | modify | an update function that requires context data. |
| [in] | context | context data required for the update. |
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.
| void * CCC_adaptive_map_begin | ( | CCC_Adaptive_map const * | map | ) |
Return the start of an inorder traversal of the map. Amortized O(lg N).
| [in] | map | a pointer to the map. |
| CCC_Result CCC_adaptive_map_clear | ( | CCC_Adaptive_map * | map, |
| CCC_Type_destructor * | destroy | ||
| ) |
Pops every element from the map calling destructor if destructor is non-NULL. O(N).
| [in] | map | a pointer to the map. |
| [in] | destroy | a destructor function if required. NULL if unneeded. |
Note that if the map has been given permission to allocate, the destructor will be called on each element before it uses the provided allocator to free the element. Therefore, the destructor should not free the element or a double free will occur.
If the container has not been given allocation permission, then the destructor may free elements or not depending on how and when the user wishes to free elements of the map according to their own memory management schemes.
| CCC_Tribool CCC_adaptive_map_contains | ( | CCC_Adaptive_map * | 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_Count CCC_adaptive_map_count | ( | CCC_Adaptive_map const * | map | ) |
Returns the count of occupied map nodes.
| [in] | map | the map. |
| void * CCC_adaptive_map_end | ( | CCC_Adaptive_map const * | map | ) |
Return the end of an inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| CCC_Adaptive_map_entry CCC_adaptive_map_entry | ( | CCC_Adaptive_map * | map, |
| void const * | key | ||
| ) |
Obtains an entry 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. |
An entry is a search result that provides either an Occupied or Vacant entry in the map. An occupied entry signifies that the search was successful. A Vacant entry means the search was not successful but a handle is gained to where in the map such an element should be inserted.
An entry is rarely useful on its own. It should be passed in a functional style to subsequent calls in the Entry Interface.
| CCC_Entry_status CCC_adaptive_map_entry_status | ( | CCC_Adaptive_map_entry const * | entry | ) |
Obtain the entry status from a container entry.
| [in] | entry | a pointer to the entry. |
Note that this function can be useful for debugging or if more detailed messages are needed for logging purposes. See CCC_entry_status_message() in ccc/types.h for more information on detailed entry statuses.
| CCC_Range CCC_adaptive_map_equal_range | ( | CCC_Adaptive_map * | map, |
| void const * | begin_key, | ||
| void const * | end_key | ||
| ) |
Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).
| [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_Range_reverse CCC_adaptive_map_equal_range_reverse | ( | CCC_Adaptive_map * | map, |
| void const * | reverse_begin_key, | ||
| void const * | reverse_end_key | ||
| ) |
Return an iterable range_reverse of values from [begin_key, end_key). Amortized 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.
| void * CCC_adaptive_map_get_key_value | ( | CCC_Adaptive_map * | map, |
| void const * | key | ||
| ) |
Returns a reference into the map at entry key.
| [in] | map | the adaptive map to search. |
| [in] | key | the key to search matching stored key type. |
| void * CCC_adaptive_map_insert_entry | ( | CCC_Adaptive_map_entry const * | entry, |
| CCC_Adaptive_map_node * | type_intruder | ||
| ) |
Inserts the provided entry invariantly.
| [in] | entry | the entry returned from a call obtaining an entry. |
| [in] | type_intruder | a handle to the struct the user intends to insert. |
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_Tribool CCC_adaptive_map_insert_error | ( | CCC_Adaptive_map_entry const * | entry | ) |
Provides the status of the entry should an insertion follow.
| [in] | entry | the entry from a query to the table via function or macro. |
| CCC_Entry CCC_adaptive_map_insert_or_assign | ( | CCC_Adaptive_map * | map, |
| CCC_Adaptive_map_node * | type_intruder | ||
| ) |
Invariantly inserts or overwrites a user struct into the map.
| [in] | map | a pointer to the flat hash map. |
| [in] | type_intruder | the handle to the wrapping user struct key value. |
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_adaptive_map_is_empty | ( | CCC_Adaptive_map const * | map | ) |
Returns the size status of the map.
| [in] | map | the map. |
| void * CCC_adaptive_map_next | ( | CCC_Adaptive_map const * | map, |
| CCC_Adaptive_map_node const * | iterator_intruder | ||
| ) |
Return the next element in an inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| [in] | iterator_intruder | a pointer to the intrusive map element of the current iterator. |
| CCC_Tribool CCC_adaptive_map_occupied | ( | CCC_Adaptive_map_entry const * | entry | ) |
Returns the Vacant or Occupied status of the entry.
| [in] | entry | the entry from a query to the map via function or macro. |
| void * CCC_adaptive_map_or_insert | ( | CCC_Adaptive_map_entry const * | entry, |
| CCC_Adaptive_map_node * | type_intruder | ||
| ) |
Inserts the struct with handle type_intruder if the entry is Vacant.
| [in] | entry | the entry obtained via function or macro call. |
| [in] | type_intruder | the handle to the struct to be inserted to a Vacant entry. |
Because this functions takes an entry 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 type_intruder has been allocated with the appropriate lifetime and scope by the user.
| CCC_Entry CCC_adaptive_map_remove_entry | ( | CCC_Adaptive_map_entry * | entry | ) |
Remove the entry from the map if Occupied.
| [in] | entry | a pointer to the map entry. |
Note that if allocation is permitted the old element is freed and the entry will contain a NULL reference. If allocation is prohibited the entry can be unwrapped to obtain the old user struct stored in the map and the user may free or use as needed.
| CCC_Entry CCC_adaptive_map_remove_key_value | ( | CCC_Adaptive_map * | map, |
| CCC_Adaptive_map_node * | type_output_intruder | ||
| ) |
Removes the key value in the map storing the old value, if present, in the struct containing type_output_intruder provided by the user.
| [in] | map | the pointer to the adaptive map. |
| [out] | type_output_intruder | the handle to the user type wrapping map node. |
Note that this function may write to the struct containing the second parameter and wraps it in an entry to provide information about the old value.
If allocation has been prohibited upon initialization then the entry returned contains the previously stored user type, if any, and nothing is written to the type_output_intruder. It is then the user's responsibility to manage their previously stored memory as they see fit.
| void * CCC_adaptive_map_reverse_begin | ( | CCC_Adaptive_map const * | map | ) |
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
| [in] | map | a pointer to the map. |
| void * CCC_adaptive_map_reverse_end | ( | CCC_Adaptive_map const * | map | ) |
Return the reverse_end of a reverse inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| void * CCC_adaptive_map_reverse_next | ( | CCC_Adaptive_map const * | map, |
| CCC_Adaptive_map_node const * | iterator_intruder | ||
| ) |
Return the reverse_next element in a reverse inorder traversal of the map. O(1).
| [in] | map | a pointer to the map. |
| [in] | iterator_intruder | a pointer to the intrusive map element of the current iterator. |
| CCC_Entry CCC_adaptive_map_swap_entry | ( | CCC_Adaptive_map * | map, |
| CCC_Adaptive_map_node * | type_intruder, | ||
| CCC_Adaptive_map_node * | temp_intruder | ||
| ) |
Invariantly inserts the key value wrapping type_intruder.
| [in] | map | the pointer to the adaptive map. |
| [in] | type_intruder | the handle to the user type wrapping map node. |
| [in] | temp_intruder | handle to space for swapping in the old value, if present. The user must provide this additional type (e.g. &(my_type){}). |
Note that this function may write to the struct containing temp_intruder and wraps it in an entry to provide information about the old value.
| CCC_Entry CCC_adaptive_map_try_insert | ( | CCC_Adaptive_map * | map, |
| CCC_Adaptive_map_node * | type_intruder | ||
| ) |
Attempts to insert the key value wrapping type_intruder.
| [in] | map | the pointer to the map. |
| [in] | type_intruder | the handle to the user type wrapping map node. |
| void * CCC_adaptive_map_unwrap | ( | CCC_Adaptive_map_entry const * | entry | ) |
Unwraps the provided entry to obtain a view into the map element.
| [in] | entry | the entry from a query to the map via function or macro. |
| CCC_Tribool CCC_adaptive_map_validate | ( | CCC_Adaptive_map const * | map | ) |
Validation of invariants for the map.
| [in] | map | the map to validate. |