C Container Collection (CCC)
|
The Handle Realtime Ordered Map Interface. More...
Go to the source code of this file.
Initialization Interface | |
Initialize the container with memory, callbacks, and permissions. | |
#define | ccc_hrm_init(memory_ptr, hrm_elem_field, key_elem_field, key_cmp_fn, alloc_fn, aux_data, capacity) |
Initializes the map at runtime or compile time. | |
ccc_result | ccc_hrm_copy (ccc_handle_realtime_ordered_map *dst, ccc_handle_realtime_ordered_map const *src, ccc_alloc_fn *fn) |
Copy the map at source to destination. | |
Membership Interface | |
Test membership or obtain references to stored user types directly. | |
#define | ccc_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i...) ccc_impl_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i) |
Returns a reference to the user type in the table at the handle. | |
void * | ccc_hrm_at (ccc_handle_realtime_ordered_map const *h, ccc_handle_i i) |
Returns a reference to the user data at the provided handle. | |
ccc_tribool | ccc_hrm_contains (ccc_handle_realtime_ordered_map const *hrm, void const *key) |
Searches the map for the presence of key. | |
ccc_handle_i | ccc_hrm_get_key_val (ccc_handle_realtime_ordered_map const *hrm, 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_hrm_swap_handle_r(handle_realtime_ordered_map_ptr, out_handle_ptr) |
Invariantly inserts the key value wrapping key_val_handle. | |
#define | ccc_hrm_try_insert_r(handle_realtime_ordered_map_ptr, key_val_handle_ptr) |
Attempts to insert the key value wrapping key_val_handle. | |
#define | ccc_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, lazy_value...) |
lazily insert lazy_value into the map at key if key is absent. | |
#define | ccc_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, lazy_value...) |
Inserts a new key value pair or overwrites the existing handle. | |
#define | ccc_hrm_remove_r(handle_realtime_ordered_map_ptr, out_handle_ptr) |
Removes the key value in the map storing the old value, if present, in the struct containing out_handle provided by the user. | |
#define | ccc_hrm_handle_r(handle_realtime_ordered_map_ptr, key_ptr) |
Obtains a handle for the provided key in the map for future use. | |
#define | ccc_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, type_name, closure_over_T...) |
Modify an Occupied handle with a closure over user type T. | |
#define | ccc_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, lazy_key_value...) |
Lazily insert the desired key value into the handle if it is Vacant. | |
#define | ccc_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, lazy_key_value...) |
Write the contents of the compound literal lazy_key_value to a node. | |
#define | ccc_hrm_remove_handle_r(handle_realtime_ordered_map_handle_ptr) |
Remove the handle from the map if Occupied. | |
ccc_handle | ccc_hrm_swap_handle (ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *out_handle) |
Invariantly inserts the key value wrapping key_val_handle. | |
ccc_handle | ccc_hrm_try_insert (ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *key_val_handle) |
Attempts to insert the key value wrapping key_val_handle. | |
ccc_handle | ccc_hrm_insert_or_assign (ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *key_val_handle) |
Invariantly inserts or overwrites a user struct into the map. | |
ccc_handle | ccc_hrm_remove (ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *out_handle) |
Removes the key value in the map storing the old value, if present, in the struct containing out_handle provided by the user. | |
ccc_hromap_handle | ccc_hrm_handle (ccc_handle_realtime_ordered_map const *hrm, void const *key) |
Obtains a handle for the provided key in the map for future use. | |
ccc_hromap_handle * | ccc_hrm_and_modify (ccc_hromap_handle *h, ccc_update_fn *fn) |
Modifies the provided handle if it is Occupied. | |
ccc_hromap_handle * | ccc_hrm_and_modify_aux (ccc_hromap_handle *h, ccc_update_fn *fn, void *aux) |
Modifies the provided handle if it is Occupied. | |
ccc_handle_i | ccc_hrm_or_insert (ccc_hromap_handle const *h, ccc_hromap_elem *elem) |
Inserts the struct with handle elem if the handle is Vacant. | |
ccc_handle_i | ccc_hrm_insert_handle (ccc_hromap_handle const *h, ccc_hromap_elem *elem) |
Inserts the provided handle invariantly. | |
ccc_handle | ccc_hrm_remove_handle (ccc_hromap_handle const *h) |
Remove the handle from the map if Occupied. | |
ccc_handle_i | ccc_hrm_unwrap (ccc_hromap_handle const *h) |
Unwraps the provided handle to obtain a view into the map element. | |
ccc_tribool | ccc_hrm_occupied (ccc_hromap_handle const *h) |
Returns the Vacant or Occupied status of the handle. | |
ccc_tribool | ccc_hrm_insert_error (ccc_hromap_handle const *h) |
Provides the status of the handle should an insertion follow. | |
ccc_handle_status | ccc_hrm_handle_status (ccc_hromap_handle const *h) |
Obtain the handle status from a container handle. | |
Iterator Interface | |
Obtain and manage iterators over the container. | |
#define | ccc_hrm_equal_range_r(handle_realtime_ordered_map_ptr, begin_and_end_key_ptrs...) |
Returns a compound literal reference to the desired range. O(lg N). | |
#define | ccc_hrm_equal_rrange_r(handle_realtime_ordered_map_ptr, rbegin_and_rend_key_ptrs...) |
Returns a compound literal reference to the desired rrange. O(lg N). | |
ccc_range | ccc_hrm_equal_range (ccc_handle_realtime_ordered_map const *hrm, void const *begin_key, void const *end_key) |
Return an iterable range of values from [begin_key, end_key). O(lg N). | |
ccc_rrange | ccc_hrm_equal_rrange (ccc_handle_realtime_ordered_map const *hrm, void const *rbegin_key, void const *rend_key) |
Return an iterable rrange of values from [begin_key, end_key). O(lg N). | |
void * | ccc_hrm_begin (ccc_handle_realtime_ordered_map const *hrm) |
Return the start of an inorder traversal of the map. O(lg N). | |
void * | ccc_hrm_rbegin (ccc_handle_realtime_ordered_map const *hrm) |
Return the start of a reverse inorder traversal of the map. O(lg N). | |
void * | ccc_hrm_next (ccc_handle_realtime_ordered_map const *hrm, ccc_hromap_elem const *iter_handle) |
Return the next element in an inorder traversal of the map. O(1). | |
void * | ccc_hrm_rnext (ccc_handle_realtime_ordered_map const *hrm, ccc_hromap_elem const *iter_handle) |
Return the rnext element in a reverse inorder traversal of the map. O(1). | |
void * | ccc_hrm_end (ccc_handle_realtime_ordered_map const *hrm) |
Return the end of an inorder traversal of the map. O(1). | |
void * | ccc_hrm_rend (ccc_handle_realtime_ordered_map const *hrm) |
Return the rend of a reverse inorder traversal of the map. O(1). | |
Container Types | |
Types available in the container interface. | |
typedef struct ccc_hromap_ | ccc_handle_realtime_ordered_map |
A handle realtime ordered map offers O(lg N) search and erase, and amortized O(lg N) insert. | |
typedef struct ccc_hromap_elem_ | ccc_hromap_elem |
The intrusive element for the user defined struct being stored in the map. | |
typedef union ccc_hromap_handle_ | ccc_hromap_handle |
A container specific handle used to implement the Handle Interface. | |
Deallocation Interface | |
Deallocate the container. | |
ccc_result | ccc_hrm_clear (ccc_handle_realtime_ordered_map *hrm, ccc_destructor_fn *fn) |
Frees all slots in the map for use without affecting capacity. | |
ccc_result | ccc_hrm_clear_and_free (ccc_handle_realtime_ordered_map *hrm, ccc_destructor_fn *fn) |
Frees all slots in the map and frees the underlying buffer. | |
State Interface | |
Obtain the container state. | |
ccc_tribool | ccc_hrm_is_empty (ccc_handle_realtime_ordered_map const *hrm) |
Returns the size status of the map. | |
ccc_ucount | ccc_hrm_size (ccc_handle_realtime_ordered_map const *hrm) |
Returns the size of the map representing active slots. | |
ccc_ucount | ccc_hrm_capacity (ccc_handle_realtime_ordered_map const *hrm) |
Returns the capacity of the map representing total available slots. | |
void * | ccc_hrm_data (ccc_handle_realtime_ordered_map const *hrm) |
Return a reference to the base of backing array. O(1). | |
ccc_tribool | ccc_hrm_validate (ccc_handle_realtime_ordered_map const *hrm) |
Validation of invariants for the map. | |
The Handle Realtime Ordered Map Interface.
A handle realtime ordered map offers storage and retrieval by key. This map is suitable for realtime applications if resizing can be well controlled. Insert operations may cause resizing if allocation is allowed.
The handle variant of the ordered 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 buffer and it is only guaranteed that N elements are stored between index [0, Capacity). Also, 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 intends to store a fixed size N nodes in the map N + 1 capacity is needed for the sentinel node in the buffer.
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.
#define ccc_hrm_and_modify_w | ( | handle_realtime_ordered_map_handle_ptr, | |
type_name, | |||
closure_over_T... | |||
) |
Modify an Occupied handle with a closure over user type T.
[in] | handle_realtime_ordered_map_handle_ptr | a pointer to the obtained handle. |
[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 handle 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_hrm_as | ( | handle_realtime_ordered_map_ptr, | |
type_name, | |||
handle_i... | |||
) | ccc_impl_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i) |
Returns a reference to the user type in the table at the handle.
[in] | handle_realtime_ordered_map_ptr | a pointer to the map. |
[in] | type_name | name of the user type stored in each slot of the map. |
[in] | handle_i | the index handle obtained from previous map operations. |
#define ccc_hrm_equal_range_r | ( | handle_realtime_ordered_map_ptr, | |
begin_and_end_key_ptrs... | |||
) |
Returns a compound literal reference to the desired range. O(lg N).
[in] | handle_realtime_ordered_map_ptr | a pointer to the map. |
[in] | begin_and_end_key_ptrs | two pointers, the first to the start of the range the second to the end of the range. |
#define ccc_hrm_equal_rrange_r | ( | handle_realtime_ordered_map_ptr, | |
rbegin_and_rend_key_ptrs... | |||
) |
Returns a compound literal reference to the desired rrange. O(lg N).
[in] | handle_realtime_ordered_map_ptr | a pointer to the map. |
[in] | rbegin_and_rend_key_ptrs | two pointers, the first to the start of the rrange the second to the end of the rrange. |
#define ccc_hrm_handle_r | ( | handle_realtime_ordered_map_ptr, | |
key_ptr | |||
) |
Obtains a handle for the provided key in the map for future use.
[in] | handle_realtime_ordered_map_ptr | the map to be searched. |
[in] | key_ptr | 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_hrm_init | ( | memory_ptr, | |
hrm_elem_field, | |||
key_elem_field, | |||
key_cmp_fn, | |||
alloc_fn, | |||
aux_data, | |||
capacity | |||
) |
Initializes the map at runtime or compile time.
[in] | memory_ptr | a pointer to the contiguous user types or ((T *)NULL). |
[in] | hrm_elem_field | the name of the intrusive map elem field. |
[in] | key_elem_field | the name of the field in user type used as key. |
[in] | key_cmp_fn | the key comparison function (see types.h). |
[in] | alloc_fn | the allocation function or NULL if allocation is banned. |
[in] | aux_data | a pointer to any auxiliary data for comparison or destruction. |
[in] | capacity | the capacity at mem_ptr or 0 if ((T *)NULL). |
#define ccc_hrm_insert_handle_w | ( | handle_realtime_ordered_map_handle_ptr, | |
lazy_key_value... | |||
) |
Write the contents of the compound literal lazy_key_value to a node.
[in] | handle_realtime_ordered_map_handle_ptr | a pointer to the obtained handle. |
[in] | lazy_key_value | the compound literal to write to a new slot. |
#define ccc_hrm_insert_or_assign_w | ( | handle_realtime_ordered_map_ptr, | |
key, | |||
lazy_value... | |||
) |
Inserts a new key value pair or overwrites the existing handle.
[in] | handle_realtime_ordered_map_ptr | the pointer to the handle hash map. |
[in] | key | the key to be searched in the map. |
[in] | lazy_value | 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_hrm_or_insert_w | ( | handle_realtime_ordered_map_handle_ptr, | |
lazy_key_value... | |||
) |
Lazily insert the desired key value into the handle if it is Vacant.
[in] | handle_realtime_ordered_map_handle_ptr | a pointer to the obtained handle. |
[in] | lazy_key_value | 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_hrm_remove_handle_r | ( | handle_realtime_ordered_map_handle_ptr | ) |
Remove the handle from the map if Occupied.
[in] | handle_realtime_ordered_map_handle_ptr | a pointer to the map handle. |
Note that the reference to the removed handle is invalidated upon any further insertions.
#define ccc_hrm_remove_r | ( | handle_realtime_ordered_map_ptr, | |
out_handle_ptr | |||
) |
Removes the key value in the map storing the old value, if present, in the struct containing out_handle provided by the user.
[in] | handle_realtime_ordered_map_ptr | the pointer to the ordered map. |
[out] | out_handle_ptr | the handle to the user type wrapping map elem. |
Note that this function may write to the struct containing the second parameter and wraps it in a handle to provide information about the old value.
#define ccc_hrm_swap_handle_r | ( | handle_realtime_ordered_map_ptr, | |
out_handle_ptr | |||
) |
Invariantly inserts the key value wrapping key_val_handle.
[in] | handle_realtime_ordered_map_ptr | the pointer to the ordered map. |
[out] | out_handle_ptr | the handle to the user type wrapping map elem. |
Note that this function may write to the struct containing out_handle and wraps it in a handle to provide information about the old value.
#define ccc_hrm_try_insert_r | ( | handle_realtime_ordered_map_ptr, | |
key_val_handle_ptr | |||
) |
Attempts to insert the key value wrapping key_val_handle.
[in] | handle_realtime_ordered_map_ptr | the pointer to the map. |
[in] | key_val_handle_ptr | the handle to the user type wrapping map elem. |
#define ccc_hrm_try_insert_w | ( | handle_realtime_ordered_map_ptr, | |
key, | |||
lazy_value... | |||
) |
lazily insert lazy_value into the map at key if key is absent.
[in] | handle_realtime_ordered_map_ptr | a pointer to the map. |
[in] | key | the direct key r-value. |
[in] | lazy_value | 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.
typedef struct ccc_hromap_ ccc_handle_realtime_ordered_map |
A handle realtime ordered map offers O(lg N) search and erase, and amortized O(lg N) insert.
A handle realtime ordered map can be initialized on the stack, heap, or data segment at runtime or compile time.
typedef struct ccc_hromap_elem_ ccc_hromap_elem |
The intrusive element for the user defined struct being stored in the map.
Because the map is handle data is always copied from the user type to map.
typedef union ccc_hromap_handle_ ccc_hromap_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_hromap_handle * ccc_hrm_and_modify | ( | ccc_hromap_handle * | h, |
ccc_update_fn * | fn | ||
) |
Modifies the provided handle if it is Occupied.
[in] | h | the handle obtained from a handle function or macro. |
[in] | fn | an update function in which the auxiliary argument is unused. |
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 auxiliary argument a ccc_update_fn can provide.
ccc_hromap_handle * ccc_hrm_and_modify_aux | ( | ccc_hromap_handle * | h, |
ccc_update_fn * | fn, | ||
void * | aux | ||
) |
Modifies the provided handle if it is Occupied.
[in] | h | the handle obtained from a handle function or macro. |
[in] | fn | an update function that requires auxiliary data. |
[in] | aux | auxiliary data required for the update. |
This function makes full use of a ccc_update_fn capability, meaning a complete ccc_update object will be passed to the update function callback.
void * ccc_hrm_at | ( | ccc_handle_realtime_ordered_map const * | h, |
ccc_handle_i | i | ||
) |
Returns a reference to the user data at the provided handle.
[in] | h | a pointer to the map. |
[in] | i | the stable handle obtained by the user. |
void * ccc_hrm_begin | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Return the start of an inorder traversal of the map. O(lg N).
[in] | hrm | a pointer to the map. |
ccc_ucount ccc_hrm_capacity | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Returns the capacity of the map representing total available slots.
[in] | hrm | the map. |
ccc_result ccc_hrm_clear | ( | ccc_handle_realtime_ordered_map * | hrm, |
ccc_destructor_fn * | fn | ||
) |
Frees all slots in the map for use without affecting capacity.
[in] | hrm | the map to be cleared. |
[in] | fn | the 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_result ccc_hrm_clear_and_free | ( | ccc_handle_realtime_ordered_map * | hrm, |
ccc_destructor_fn * | fn | ||
) |
Frees all slots in the map and frees the underlying buffer.
[in] | hrm | the map to be cleared. |
[in] | fn | the 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_tribool ccc_hrm_contains | ( | ccc_handle_realtime_ordered_map const * | hrm, |
void const * | key | ||
) |
Searches the map for the presence of key.
[in] | hrm | the map to be searched. |
[in] | key | pointer to the key matching the key type of the user struct. |
ccc_result ccc_hrm_copy | ( | ccc_handle_realtime_ordered_map * | dst, |
ccc_handle_realtime_ordered_map const * | src, | ||
ccc_alloc_fn * | fn | ||
) |
Copy the map at source to destination.
[in] | dst | the initialized destination for the copy of the src map. |
[in] | src | the initialized source of the map. |
[in] | fn | the allocation function to resize dst or NULL. |
Note that there are two ways to copy data from source to destination: provide sufficient memory and pass NULL as fn, or allow the copy function to take care of allocation for the copy.
Manual memory management with no allocation function provided.
The above requires dst capacity be greater than or equal to src capacity. Here is memory management handed over to the copy function.
The above allows dst to have a capacity less than that of the src as long as copy has been provided an allocation function to resize dst. Note that this would still work if copying to a destination that the user wants as a fixed size map.
The above sets up dst with fixed size while src is a dynamic map. Because an allocation function is provided, the dst 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 dst 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.
void * ccc_hrm_data | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Return a reference to the base of backing array. O(1).
[in] | hrm | a pointer to the map. |
void * ccc_hrm_end | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Return the end of an inorder traversal of the map. O(1).
[in] | hrm | a pointer to the map. |
ccc_range ccc_hrm_equal_range | ( | ccc_handle_realtime_ordered_map const * | hrm, |
void const * | begin_key, | ||
void const * | end_key | ||
) |
Return an iterable range of values from [begin_key, end_key). O(lg N).
[in] | hrm | 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:
for (struct val *i = range_begin(&range); i != end_range(&range); i = next(&hrm, &i->elem)) {}
This avoids any possible errors in handling an end range element that is in the map versus the end map sentinel.
ccc_rrange ccc_hrm_equal_rrange | ( | ccc_handle_realtime_ordered_map const * | hrm, |
void const * | rbegin_key, | ||
void const * | rend_key | ||
) |
Return an iterable rrange of values from [begin_key, end_key). O(lg N).
[in] | hrm | a pointer to the map. |
[in] | rbegin_key | a pointer to the key intended as the start of the rrange. |
[in] | rend_key | a pointer to the key intended as the end of the rrange. |
Note that due to the variety of values that can be returned in the rrange, using the provided rrange iteration functions from types.h is recommended for example:
for (struct val *i = rrange_begin(&rrange); i != rend_rrange(&rrange); i = rnext(&fom, &i->elem)) {}
This avoids any possible errors in handling an rend rrange element that is in the map versus the end map sentinel.
ccc_handle_i ccc_hrm_get_key_val | ( | ccc_handle_realtime_ordered_map const * | hrm, |
void const * | key | ||
) |
Returns a reference into the map at handle key.
[in] | hrm | the ordered map to search. |
[in] | key | the key to search matching stored key type. |
ccc_hromap_handle ccc_hrm_handle | ( | ccc_handle_realtime_ordered_map const * | hrm, |
void const * | key | ||
) |
Obtains a handle for the provided key in the map for future use.
[in] | hrm | 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_hrm_handle_status | ( | ccc_hromap_handle const * | h | ) |
Obtain the handle status from a container handle.
[in] | h | 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_msg() in ccc/types.h for more information on detailed handle statuses.
ccc_tribool ccc_hrm_insert_error | ( | ccc_hromap_handle const * | h | ) |
Provides the status of the handle should an insertion follow.
[in] | h | the handle from a query to the table via function or macro. |
ccc_handle_i ccc_hrm_insert_handle | ( | ccc_hromap_handle const * | h, |
ccc_hromap_elem * | elem | ||
) |
Inserts the provided handle invariantly.
[in] | h | the handle returned from a call obtaining a handle. |
[in] | elem | 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_handle ccc_hrm_insert_or_assign | ( | ccc_handle_realtime_ordered_map * | hrm, |
ccc_hromap_elem * | key_val_handle | ||
) |
Invariantly inserts or overwrites a user struct into the map.
[in] | hrm | a pointer to the handle hash map. |
[in] | key_val_handle | 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_hrm_is_empty | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Returns the size status of the map.
[in] | hrm | the map. |
void * ccc_hrm_next | ( | ccc_handle_realtime_ordered_map const * | hrm, |
ccc_hromap_elem const * | iter_handle | ||
) |
Return the next element in an inorder traversal of the map. O(1).
[in] | hrm | a pointer to the map. |
[in] | iter_handle | a pointer to the intrusive map element of the current iterator. |
ccc_tribool ccc_hrm_occupied | ( | ccc_hromap_handle const * | h | ) |
Returns the Vacant or Occupied status of the handle.
[in] | h | the handle from a query to the map via function or macro. |
ccc_handle_i ccc_hrm_or_insert | ( | ccc_hromap_handle const * | h, |
ccc_hromap_elem * | elem | ||
) |
Inserts the struct with handle elem if the handle is Vacant.
[in] | h | the handle obtained via function or macro call. |
[in] | elem | the handle to the struct to be inserted to a Vacant handle. |
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.
void * ccc_hrm_rbegin | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Return the start of a reverse inorder traversal of the map. O(lg N).
[in] | hrm | a pointer to the map. |
ccc_handle ccc_hrm_remove | ( | ccc_handle_realtime_ordered_map * | hrm, |
ccc_hromap_elem * | out_handle | ||
) |
Removes the key value in the map storing the old value, if present, in the struct containing out_handle provided by the user.
[in] | hrm | the pointer to the ordered map. |
[out] | out_handle | the handle to the user type wrapping map elem. |
Note that this function may write to the struct containing the second parameter and wraps it in a handle to provide information about the old value.
ccc_handle ccc_hrm_remove_handle | ( | ccc_hromap_handle const * | h | ) |
Remove the handle from the map if Occupied.
[in] | h | a pointer to the map handle. |
void * ccc_hrm_rend | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Return the rend of a reverse inorder traversal of the map. O(1).
[in] | hrm | a pointer to the map. |
void * ccc_hrm_rnext | ( | ccc_handle_realtime_ordered_map const * | hrm, |
ccc_hromap_elem const * | iter_handle | ||
) |
Return the rnext element in a reverse inorder traversal of the map. O(1).
[in] | hrm | a pointer to the map. |
[in] | iter_handle | a pointer to the intrusive map element of the current iterator. |
ccc_ucount ccc_hrm_size | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Returns the size of the map representing active slots.
[in] | hrm | the map. |
ccc_handle ccc_hrm_swap_handle | ( | ccc_handle_realtime_ordered_map * | hrm, |
ccc_hromap_elem * | out_handle | ||
) |
Invariantly inserts the key value wrapping key_val_handle.
[in] | hrm | the pointer to the ordered map. |
[out] | out_handle | the handle to the user type wrapping map elem. |
Note that this function may write to the struct containing out_handle and wraps it in a handle to provide information about the old value.
ccc_handle ccc_hrm_try_insert | ( | ccc_handle_realtime_ordered_map * | hrm, |
ccc_hromap_elem * | key_val_handle | ||
) |
Attempts to insert the key value wrapping key_val_handle.
[in] | hrm | the pointer to the map. |
[in] | key_val_handle | the handle to the user type wrapping map elem. |
ccc_handle_i ccc_hrm_unwrap | ( | ccc_hromap_handle const * | h | ) |
Unwraps the provided handle to obtain a view into the map element.
[in] | h | the handle from a query to the map via function or macro. |
ccc_tribool ccc_hrm_validate | ( | ccc_handle_realtime_ordered_map const * | hrm | ) |
Validation of invariants for the map.
[in] | hrm | the map to validate. |