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

The Realtime Ordered Map Interface. More...

#include "impl/impl_realtime_ordered_map.h"
#include "types.h"
Include dependency graph for realtime_ordered_map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Initialization Interface

Initialize the container with memory, callbacks, and permissions.

#define ccc_rom_init(rom_name, struct_name, rom_elem_field, key_elem_field, alloc_fn, key_cmp_fn, aux_data)
 Initializes the ordered map at runtime or compile time.
 

Entry Interface

Obtain and operate on container entries for efficient queries when non-trivial control flow is needed.

#define ccc_rom_insert_r(realtime_ordered_map_ptr, key_val_handle_ptr, tmp_ptr)
 Invariantly inserts the key value wrapping key_val_handle_ptr.
 
#define ccc_rom_try_insert_r(realtime_ordered_map_ptr, key_val_handle_ptr)
 Attempts to insert the key value wrapping key_val_handle.
 
#define ccc_rom_try_insert_w(realtime_ordered_map_ptr, key, lazy_value...)
 lazily insert lazy_value into the map at key if key is absent.
 
#define ccc_rom_insert_or_assign_w(realtime_ordered_map_ptr, key, lazy_value...)
 Inserts a new key value pair or overwrites the existing entry.
 
#define ccc_rom_remove_r(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_ptr provided by the user.
 
#define ccc_rom_entry_r(realtime_ordered_map_ptr, key_ptr)
 Obtains an entry for the provided key in the map for future use.
 
#define ccc_rom_and_modify_w(realtime_ordered_map_entry_ptr, type_name, closure_over_T...)
 Modify an Occupied entry with a closure over user type T.
 
#define ccc_rom_or_insert_w(realtime_ordered_map_entry_ptr, lazy_key_value...)    ccc_impl_rom_or_insert_w(realtime_ordered_map_entry_ptr, lazy_key_value)
 Lazily insert the desired key value into the entry if it is Vacant.
 
#define ccc_rom_insert_entry_w(realtime_ordered_map_entry_ptr, lazy_key_value...)    ccc_impl_rom_insert_entry_w(realtime_ordered_map_entry_ptr, lazy_key_value)
 Write the contents of the compound literal lazy_key_value to a node.
 
#define ccc_rom_remove_entry_r(realtime_ordered_map_entry_ptr)
 Remove the entry from the map if Occupied.
 
ccc_entry ccc_rom_insert (ccc_realtime_ordered_map *rom, ccc_romap_elem *key_val_handle, ccc_romap_elem *tmp)
 Invariantly inserts the key value wrapping key_val_handle.
 
ccc_entry ccc_rom_try_insert (ccc_realtime_ordered_map *rom, ccc_romap_elem *key_val_handle)
 Attempts to insert the key value wrapping key_val_handle.
 
ccc_entry ccc_rom_insert_or_assign (ccc_realtime_ordered_map *rom, ccc_romap_elem *key_val_handle)
 Invariantly inserts or overwrites a user struct into the map.
 
ccc_entry ccc_rom_remove (ccc_realtime_ordered_map *rom, ccc_romap_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_romap_entry ccc_rom_entry (ccc_realtime_ordered_map const *rom, void const *key)
 Obtains an entry for the provided key in the map for future use.
 
ccc_romap_entryccc_rom_and_modify (ccc_romap_entry *e, ccc_update_fn *fn)
 Modifies the provided entry if it is Occupied.
 
ccc_romap_entryccc_rom_and_modify_aux (ccc_romap_entry *e, ccc_update_fn *fn, void *aux)
 Modifies the provided entry if it is Occupied.
 
void * ccc_rom_or_insert (ccc_romap_entry const *e, ccc_romap_elem *elem)
 Inserts the struct with handle elem if the entry is Vacant.
 
void * ccc_rom_insert_entry (ccc_romap_entry const *e, ccc_romap_elem *elem)
 Inserts the provided entry invariantly.
 
ccc_entry ccc_rom_remove_entry (ccc_romap_entry const *e)
 Remove the entry from the map if Occupied.
 
void * ccc_rom_unwrap (ccc_romap_entry const *e)
 Unwraps the provided entry to obtain a view into the map element.
 
bool ccc_rom_insert_error (ccc_romap_entry const *e)
 Returns the Vacant or Occupied status of the entry.
 
bool ccc_rom_occupied (ccc_romap_entry const *e)
 Provides the status of the entry should an insertion follow.
 
ccc_entry_status ccc_rom_entry_status (ccc_romap_entry const *e)
 Obtain the entry status from a container entry.
 

Iterator Interface

Obtain and manage iterators over the container.

#define ccc_rom_equal_range_r(realtime_ordered_map_ptr, begin_and_end_key_ptrs...)
 Returns a compound literal reference to the desired range. Amortized O(lg N).
 
#define ccc_rom_equal_rrange_r(realtime_ordered_map_ptr, rbegin_and_rend_key_ptrs...)
 Returns a compound literal reference to the desired rrange. Amortized O(lg N).
 
ccc_range ccc_rom_equal_range (ccc_realtime_ordered_map const *rom, void const *begin_key, void const *end_key)
 Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).
 
ccc_rrange ccc_rom_equal_rrange (ccc_realtime_ordered_map const *rom, void const *rbegin_key, void const *rend_key)
 Return an iterable rrange of values from [begin_key, end_key). Amortized O(lg N).
 
void * ccc_rom_begin (ccc_realtime_ordered_map const *rom)
 Return the start of an inorder traversal of the map. Amortized O(lg N).
 
void * ccc_rom_rbegin (ccc_realtime_ordered_map const *rom)
 Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
 
void * ccc_rom_next (ccc_realtime_ordered_map const *rom, ccc_romap_elem const *iter_handle)
 Return the next element in an inorder traversal of the map. O(1).
 
void * ccc_rom_rnext (ccc_realtime_ordered_map const *rom, ccc_romap_elem const *iter_handle)
 Return the rnext element in a reverse inorder traversal of the map. O(1).
 
void * ccc_rom_end (ccc_realtime_ordered_map const *rom)
 Return the end of an inorder traversal of the map. O(1).
 
void * ccc_rom_rend (ccc_realtime_ordered_map const *rom)
 Return the rend of a reverse inorder traversal of the map. O(1).
 

Container Types

Types available in the container interface.

typedef struct ccc_romap_ ccc_realtime_ordered_map
 A container for amortized O(lg N) search, insert, erase, ranges, and pointer stability.
 
typedef struct ccc_romap_elem_ ccc_romap_elem
 The intrusive element of the user defined struct being stored in the map.
 
typedef union ccc_romap_entry_ ccc_romap_entry
 A container specific entry used to implement the Entry Interface.
 

Membership Interface

Test membership or obtain references to stored user types directly.

bool ccc_rom_contains (ccc_realtime_ordered_map const *rom, void const *key)
 Searches the map for the presence of key.
 
void * ccc_rom_get_key_val (ccc_realtime_ordered_map const *rom, void const *key)
 Returns a reference into the map at entry key.
 

Deallocation Interface

Deallocate the container.

ccc_result ccc_rom_clear (ccc_realtime_ordered_map *rom, ccc_destructor_fn *destructor)
 Pops every element from the map calling destructor if destructor is non-NULL. O(N).
 

State Interface

Obtain the container state.

size_t ccc_rom_size (ccc_realtime_ordered_map const *rom)
 Returns the size of the map.
 
bool ccc_rom_is_empty (ccc_realtime_ordered_map const *rom)
 Returns the size status of the map.
 
bool ccc_rom_validate (ccc_realtime_ordered_map const *rom)
 Validation of invariants for the map.
 

Detailed Description

The Realtime Ordered Map Interface.

A realtime ordered map offers storage and retrieval by key. This map offers pointer stability and a strict runtime bound of O(lg N) which is helpful in realtime environments. Also, searching is a thread-safe read-only operation. Balancing modifications only occur upon insertion or removal.

To shorten names in the interface, define the following preprocessor directive at the top of your file.

#define REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC

All types and functions can then be written without the ccc_ prefix.

Macro Definition Documentation

◆ ccc_rom_and_modify_w

#define ccc_rom_and_modify_w (   realtime_ordered_map_entry_ptr,
  type_name,
  closure_over_T... 
)
Value:
{ \
ccc_impl_rom_and_modify_w(realtime_ordered_map_entry_ptr, type_name, \
closure_over_T) \
}
union ccc_romap_entry_ ccc_romap_entry
A container specific entry used to implement the Entry Interface.
Definition: realtime_ordered_map.h:54

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

Parameters
[in]realtime_ordered_map_entry_ptra pointer to the obtained entry.
[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 entry if it was occupied or a vacant entry if it was vacant.
Note
T is a reference to the user type stored in the entry guaranteed to be non-NULL if the closure executes.
#define REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC
// Increment the key k if found otherwise do nothing.
rom_entry *e = rom_and_modify_w(entry_r(&rom, &k), word, T->cnt++;);
// Increment the key k if found otherwise insert a default value.
word *w = rom_or_insert_w(rom_and_modify_w(entry_r(&rom, &k), word,
{ T->cnt++; }),
(word){.key = k, .cnt = 1});

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.

◆ ccc_rom_entry_r

#define ccc_rom_entry_r (   realtime_ordered_map_ptr,
  key_ptr 
)
Value:
{ \
ccc_rom_entry((realtime_ordered_map_ptr), (key_ptr)).impl_ \
}

Obtains an entry for the provided key in the map for future use.

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

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_rom_equal_range_r

#define ccc_rom_equal_range_r (   realtime_ordered_map_ptr,
  begin_and_end_key_ptrs... 
)
Value:
&(ccc_range) \
{ \
ccc_rom_equal_range((realtime_ordered_map_ptr), \
(begin_and_end_key_ptrs)) \
.impl_ \
}
union ccc_range_ ccc_range
The result of a range query on iterable containers.
Definition: types.h:30

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

Parameters
[in]realtime_ordered_map_ptra pointer to the map.
[in]begin_and_end_key_ptrstwo 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_rom_equal_rrange_r

#define ccc_rom_equal_rrange_r (   realtime_ordered_map_ptr,
  rbegin_and_rend_key_ptrs... 
)
Value:
{ \
ccc_rom_equal_rrange((realtime_ordered_map_ptr), \
(rbegin_and_rend_key_ptrs)) \
.impl_ \
}
union ccc_rrange_ ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:38

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

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

◆ ccc_rom_init

#define ccc_rom_init (   rom_name,
  struct_name,
  rom_elem_field,
  key_elem_field,
  alloc_fn,
  key_cmp_fn,
  aux_data 
)
Value:
ccc_impl_rom_init(rom_name, struct_name, rom_elem_field, key_elem_field, \
alloc_fn, key_cmp_fn, aux_data)

Initializes the ordered map at runtime or compile time.

Parameters
[in]rom_namethe name of the ordered map being initialized.
[in]struct_namethe user type wrapping the intrusive element.
[in]rom_elem_fieldthe name of the intrusive map elem field.
[in]key_elem_fieldthe name of the field in user type used as key.
[in]alloc_fnthe allocation function or NULL if allocation is banned.
[in]key_cmp_fnthe key comparison function (see types.h).
[in]aux_dataa pointer to any auxiliary data for comparison or destruction.
Returns
the struct initialized ordered map for direct assignment (i.e. ccc_realtime_ordered_map m = ccc_rom_init(...);).

◆ ccc_rom_insert_entry_w

#define ccc_rom_insert_entry_w (   realtime_ordered_map_entry_ptr,
  lazy_key_value... 
)     ccc_impl_rom_insert_entry_w(realtime_ordered_map_entry_ptr, lazy_key_value)

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

Parameters
[in]realtime_ordered_map_entry_ptra pointer to the obtained entry.
[in]lazy_key_valuethe 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_rom_insert_or_assign_w

#define ccc_rom_insert_or_assign_w (   realtime_ordered_map_ptr,
  key,
  lazy_value... 
)
Value:
&(ccc_entry) \
{ \
ccc_impl_rom_insert_or_assign_w(realtime_ordered_map_ptr, key, \
lazy_value) \
}
#define ccc_entry(container_ptr, key_ptr...)
Obtain a container specific entry for the Entry Interface.
Definition: traits.h:108

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

Parameters
[in]realtime_ordered_map_ptrthe pointer to the flat hash map.
[in]keythe key to be searched in the map.
[in]lazy_valuethe compound literal to insert or use for overwrite.
Returns
a compound literal reference to the entry of the existing or newly inserted value. Occupied indicates the key existed, Vacant indicates the key was absent. Unwrapping 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_rom_insert_r

#define ccc_rom_insert_r (   realtime_ordered_map_ptr,
  key_val_handle_ptr,
  tmp_ptr 
)
Value:
&(ccc_entry) \
{ \
ccc_rom_insert((realtime_ordered_map_ptr), (key_val_handle_ptr), \
(tmp_ptr)) \
.impl_ \
}

Invariantly inserts the key value wrapping key_val_handle_ptr.

Parameters
[in]realtime_ordered_map_ptrthe pointer to the ordered map.
[in]key_val_handle_ptrthe handle to the user type wrapping map elem.
[in]tmp_ptrhandle to space for swapping in the old value, if present. The same user type stored in the map should wrap tmp_ptr.
Returns
a compound literal reference to an entry. If Vacant, no prior element with key existed and the type wrapping tmp_ptr remains unchanged. If Occupied the old value is written to the type wrapping tmp_ptr and may be unwrapped to view. 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 struct containing tmp_ptr and wraps it in an entry to provide information about the old value.

◆ ccc_rom_or_insert_w

#define ccc_rom_or_insert_w (   realtime_ordered_map_entry_ptr,
  lazy_key_value... 
)     ccc_impl_rom_or_insert_w(realtime_ordered_map_entry_ptr, lazy_key_value)

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

Parameters
[in]realtime_ordered_map_entry_ptra pointer to the obtained entry.
[in]lazy_key_valuethe compound literal to construct in place if the entry is Vacant.
Returns
a reference to the unwrapped user type in the entry, either the unmodified reference if the entry was Occupied or the newly inserted element if the entry 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 entry is Occupied.

◆ ccc_rom_remove_entry_r

#define ccc_rom_remove_entry_r (   realtime_ordered_map_entry_ptr)
Value:
&(ccc_entry) \
{ \
ccc_rom_remove_entry((realtime_ordered_map_entry_ptr)).impl_ \
}

Remove the entry from the map if Occupied.

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

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_rom_remove_r

#define ccc_rom_remove_r (   realtime_ordered_map_ptr,
  out_handle_ptr 
)
Value:
&(ccc_entry) \
{ \
ccc_rom_remove((realtime_ordered_map_ptr), (out_handle_ptr)).impl_ \
}

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

Parameters
[in]realtime_ordered_map_ptrthe pointer to the ordered map.
[out]out_handle_ptrthe handle to the user type wrapping map elem.
Returns
a compound literal reference to the removed entry. If Occupied it may be unwrapped to obtain 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 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 out_handle_ptr. It is then the user's responsibility to manage their previously stored memory as they see fit.

◆ ccc_rom_try_insert_r

#define ccc_rom_try_insert_r (   realtime_ordered_map_ptr,
  key_val_handle_ptr 
)
Value:
&(ccc_entry) \
{ \
ccc_rom_try_insert((realtime_ordered_map_ptr), (key_val_handle_ptr)) \
.impl_ \
}

Attempts to insert the key value wrapping key_val_handle.

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

◆ ccc_rom_try_insert_w

#define ccc_rom_try_insert_w (   realtime_ordered_map_ptr,
  key,
  lazy_value... 
)
Value:
&(ccc_entry) \
{ \
ccc_impl_rom_try_insert_w(realtime_ordered_map_ptr, key, lazy_value) \
}

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

Parameters
[in]realtime_ordered_map_ptra pointer to the map.
[in]keythe direct key r-value.
[in]lazy_valuethe compound literal specifying the value.
Returns
a compound literal reference to the entry of the existing or newly inserted value. Occupied indicates the key existed, Vacant indicates the key was absent. Unwrapping 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.

Typedef Documentation

◆ ccc_realtime_ordered_map

typedef struct ccc_romap_ ccc_realtime_ordered_map

A container for amortized O(lg N) search, insert, erase, ranges, and pointer stability.

Warning
it is undefined behavior to access an uninitialized container.

A realtime ordered map can be initialized on the stack, heap, or data segment at runtime or compile time.

◆ ccc_romap_elem

typedef struct ccc_romap_elem_ ccc_romap_elem

The intrusive element of the user defined struct being stored in the map.

It can be used in an allocating or non allocating container. If allocation is prohibited the container assumes the element is wrapped in pre-allocated memory with the appropriate lifetime and scope for the user's needs; the container does not allocate or free in this case. If allocation is allowed the container will handle copying the data wrapping the element to allocations and deallocating when necessary.

◆ ccc_romap_entry

typedef union ccc_romap_entry_ ccc_romap_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.

Function Documentation

◆ ccc_rom_and_modify()

ccc_romap_entry * ccc_rom_and_modify ( ccc_romap_entry e,
ccc_update_fn fn 
)

Modifies the provided entry if it is Occupied.

Parameters
[in]ethe entry obtained from an entry function or macro.
[in]fnan update function in which the auxiliary argument is unused.
Returns
the updated entry if it was Occupied or the unmodified vacant entry.

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 auxiliary argument a ccc_update_fn can provide.

◆ ccc_rom_and_modify_aux()

ccc_romap_entry * ccc_rom_and_modify_aux ( ccc_romap_entry e,
ccc_update_fn fn,
void *  aux 
)

Modifies the provided entry if it is Occupied.

Parameters
[in]ethe entry obtained from an entry function or macro.
[in]fnan update function that requires auxiliary data.
[in]auxauxiliary data required for the update.
Returns
the updated entry if it was Occupied or the unmodified vacant entry.

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.

◆ ccc_rom_begin()

void * ccc_rom_begin ( ccc_realtime_ordered_map const *  rom)

Return the start of an inorder traversal of the map. Amortized O(lg N).

Parameters
[in]roma pointer to the map.
Returns
the oldest minimum element of the map.

◆ ccc_rom_clear()

ccc_result ccc_rom_clear ( ccc_realtime_ordered_map rom,
ccc_destructor_fn destructor 
)

Pops every element from the map calling destructor if destructor is non-NULL. O(N).

Parameters
[in]roma pointer to the map.
[in]destructora destructor function if required. NULL if unneeded.
Returns
an input error if rom points to NULL otherwise OK.

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

bool ccc_rom_contains ( ccc_realtime_ordered_map const *  rom,
void const *  key 
)

Searches the map for the presence of key.

Parameters
[in]romthe 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.

◆ ccc_rom_end()

void * ccc_rom_end ( ccc_realtime_ordered_map const *  rom)

Return the end of an inorder traversal of the map. O(1).

Parameters
[in]roma pointer to the map.
Returns
the newest maximum element of the map.

◆ ccc_rom_entry()

ccc_romap_entry ccc_rom_entry ( ccc_realtime_ordered_map const *  rom,
void const *  key 
)

Obtains an entry for the provided key in the map for future use.

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

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

ccc_entry_status ccc_rom_entry_status ( ccc_romap_entry const *  e)

Obtain the entry status from a container entry.

Parameters
[in]ea pointer to the entry.
Returns
the status stored in the entry after the required action on the container completes. If e is NULL an entry 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_entry_status_msg() in ccc/types.h for more information on detailed entry statuses.

◆ ccc_rom_equal_range()

ccc_range ccc_rom_equal_range ( ccc_realtime_ordered_map const *  rom,
void const *  begin_key,
void const *  end_key 
)

Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).

Parameters
[in]roma 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 (struct val *i = range_begin(&range); i != end_range(&range); i = next(&omm, &i->elem)) {}

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

◆ ccc_rom_equal_rrange()

ccc_rrange ccc_rom_equal_rrange ( ccc_realtime_ordered_map const *  rom,
void const *  rbegin_key,
void const *  rend_key 
)

Return an iterable rrange of values from [begin_key, end_key). Amortized O(lg N).

Parameters
[in]roma pointer to the map.
[in]rbegin_keya pointer to the key intended as the start of the rrange.
[in]rend_keya pointer to the key intended as the end of the rrange.
Returns
a rrange containing the first element NOT GREATER than the begin_key and the first element LESS than rend_key.

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(&omm, &i->elem)) {}

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

◆ ccc_rom_get_key_val()

void * ccc_rom_get_key_val ( ccc_realtime_ordered_map const *  rom,
void const *  key 
)

Returns a reference into the map at entry key.

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

◆ ccc_rom_insert()

ccc_entry ccc_rom_insert ( ccc_realtime_ordered_map rom,
ccc_romap_elem key_val_handle,
ccc_romap_elem tmp 
)

Invariantly inserts the key value wrapping key_val_handle.

Parameters
[in]romthe pointer to the ordered map.
[in]key_val_handlethe handle to the user type wrapping map elem.
[in]tmphandle to space for swapping in the old value, if present. The same user type stored in the map should wrap tmp.
Returns
an entry. If Vacant, no prior element with key existed and the type wrapping tmp remains unchanged. If Occupied the old value is written to the type wrapping tmp and may be unwrapped to view. 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 struct containing tmp and wraps it in an entry to provide information about the old value.

◆ ccc_rom_insert_entry()

void * ccc_rom_insert_entry ( ccc_romap_entry const *  e,
ccc_romap_elem elem 
)

Inserts the provided entry invariantly.

Parameters
[in]ethe entry returned from a call obtaining an entry.
[in]elema handle to the 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_rom_insert_error()

bool ccc_rom_insert_error ( ccc_romap_entry const *  e)

Returns the Vacant or Occupied status of the entry.

Parameters
[in]ethe entry from a query to the map via function or macro.
Returns
true if the entry is occupied, false if not.

◆ ccc_rom_insert_or_assign()

ccc_entry ccc_rom_insert_or_assign ( ccc_realtime_ordered_map rom,
ccc_romap_elem key_val_handle 
)

Invariantly inserts or overwrites a user struct into the map.

Parameters
[in]roma pointer to the flat hash map.
[in]key_val_handlethe handle to the wrapping user struct key value.
Returns
an entry. If Occupied an entry was overwritten by the new key value. If Vacant no prior map entry 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_rom_is_empty()

bool ccc_rom_is_empty ( ccc_realtime_ordered_map const *  rom)

Returns the size status of the map.

Parameters
[in]romthe map.
Returns
true if empty else false.

◆ ccc_rom_next()

void * ccc_rom_next ( ccc_realtime_ordered_map const *  rom,
ccc_romap_elem const *  iter_handle 
)

Return the next element in an inorder traversal of the map. O(1).

Parameters
[in]roma pointer to the map.
[in]iter_handlea pointer to the intrusive map element of the current iterator.
Returns
the next user type stored in the map in an inorder traversal.

◆ ccc_rom_occupied()

bool ccc_rom_occupied ( ccc_romap_entry const *  e)

Provides the status of the entry should an insertion follow.

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

◆ ccc_rom_or_insert()

void * ccc_rom_or_insert ( ccc_romap_entry const *  e,
ccc_romap_elem elem 
)

Inserts the struct with handle elem if the entry is Vacant.

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

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 elem has been allocated with the appropriate lifetime and scope by the user.

◆ ccc_rom_rbegin()

void * ccc_rom_rbegin ( ccc_realtime_ordered_map const *  rom)

Return the start of a reverse inorder traversal of the map. Amortized O(lg N).

Parameters
[in]roma pointer to the map.
Returns
the oldest maximum element of the map.

◆ ccc_rom_remove()

ccc_entry ccc_rom_remove ( ccc_realtime_ordered_map rom,
ccc_romap_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.

Parameters
[in]romthe pointer to the ordered map.
[out]out_handlethe handle to the user type wrapping map elem.
Returns
the removed entry. If Occupied it may be unwrapped to obtain 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 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 out_handle. It is then the user's responsibility to manage their previously stored memory as they see fit.

◆ ccc_rom_remove_entry()

ccc_entry ccc_rom_remove_entry ( ccc_romap_entry const *  e)

Remove the entry from the map if Occupied.

Parameters
[in]ea pointer to the map entry.
Returns
an entry containing NULL or a reference to the old entry. If Occupied an entry in the map existed and was removed. If Vacant, no prior entry existed to be removed.

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

void * ccc_rom_rend ( ccc_realtime_ordered_map const *  rom)

Return the rend of a reverse inorder traversal of the map. O(1).

Parameters
[in]roma pointer to the map.
Returns
the newest minimum element of the map.

◆ ccc_rom_rnext()

void * ccc_rom_rnext ( ccc_realtime_ordered_map const *  rom,
ccc_romap_elem const *  iter_handle 
)

Return the rnext element in a reverse inorder traversal of the map. O(1).

Parameters
[in]roma pointer to the map.
[in]iter_handlea pointer to the intrusive map element of the current iterator.
Returns
the rnext user type stored in the map in a reverse inorder traversal.

◆ ccc_rom_size()

size_t ccc_rom_size ( ccc_realtime_ordered_map const *  rom)

Returns the size of the map.

Parameters
[in]romthe map.
Returns
the size_t size.

◆ ccc_rom_try_insert()

ccc_entry ccc_rom_try_insert ( ccc_realtime_ordered_map rom,
ccc_romap_elem key_val_handle 
)

Attempts to insert the key value wrapping key_val_handle.

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

◆ ccc_rom_unwrap()

void * ccc_rom_unwrap ( ccc_romap_entry const *  e)

Unwraps the provided entry to obtain a view into the map element.

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

◆ ccc_rom_validate()

bool ccc_rom_validate ( ccc_realtime_ordered_map const *  rom)

Validation of invariants for the map.

Parameters
[in]romthe map to validate.
Returns
true if all invariants hold, false if corruption occurs.