C Container Collection (CCC)
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ordered_multimap.h
Go to the documentation of this file.
1
47#ifndef CCC_ORDERED_MULTIMAP_H
48#define CCC_ORDERED_MULTIMAP_H
49
51#include <stddef.h>
54#include "impl/impl_ordered_multimap.h"
55#include "types.h"
56
67typedef struct ccc_ommap ccc_ordered_multimap;
68
78
86
106#define ccc_omm_init(omm_name, any_struct_name, ommap_elem_field, key_field, \
107 key_cmp_fn, alloc_fn, aux) \
108 ccc_impl_omm_init(omm_name, any_struct_name, ommap_elem_field, key_field, \
109 key_cmp_fn, alloc_fn, aux)
110
123 void const *key);
124
131 void const *key);
132
155 ccc_ommap_elem *key_val_handle);
156
170 ccc_ommap_elem *key_val_handle);
171
185#define ccc_omm_try_insert_w(ordered_multimap_ptr, key, lazy_value...) \
186 &(ccc_entry) \
187 { \
188 ccc_impl_omm_try_insert_w(ordered_multimap_ptr, key, lazy_value) \
189 }
190
204[[nodiscard]] ccc_entry
206 ccc_ommap_elem *key_val_handle);
207
223#define ccc_omm_insert_or_assign_w(ordered_multimap_ptr, key, lazy_value...) \
224 &(ccc_entry) \
225 { \
226 ccc_impl_omm_insert_or_assign_w(ordered_multimap_ptr, key, lazy_value) \
227 }
228
241 ccc_ommap_elem *out_handle);
242
251 void const *key);
252
264#define ccc_omm_entry_r(ordered_multimap_ptr, key_ptr) \
265 &(ccc_ommap_entry) \
266 { \
267 ccc_omm_entry((ordered_multimap_ptr), (key_ptr)).impl \
268 }
269
280
290[[nodiscard]] ccc_ommap_entry *
292 void *aux);
293
321#define ccc_omm_and_modify_w(ordered_multimap_entry_ptr, type_name, \
322 closure_over_T...) \
323 &(ccc_ommap_entry) \
324 { \
325 ccc_impl_omm_and_modify_w(ordered_multimap_entry_ptr, type_name, \
326 closure_over_T) \
327 }
328
341[[nodiscard]] void *ccc_omm_or_insert(ccc_ommap_entry const *e,
342 ccc_ommap_elem *key_val_handle);
343
357#define ccc_omm_or_insert_w(ordered_multimap_entry_ptr, lazy_key_value...) \
358 ccc_impl_omm_or_insert_w(ordered_multimap_entry_ptr, lazy_key_value)
359
372[[nodiscard]] void *ccc_omm_insert_entry(ccc_ommap_entry const *e,
373 ccc_ommap_elem *key_val_handle);
374
388#define ccc_omm_insert_entry_w(ordered_multimap_entry_ptr, lazy_key_value...) \
389 ccc_impl_omm_insert_entry_w(ordered_multimap_entry_ptr, lazy_key_value)
390
400
406
411[[nodiscard]] void *ccc_omm_unwrap(ccc_ommap_entry const *e);
412
421
431
441[[nodiscard]] ccc_entry_status ccc_omm_entry_status(ccc_ommap_entry const *e);
442
460
472
485[[nodiscard]] void *ccc_omm_max(ccc_ordered_multimap *mm);
486
499[[nodiscard]] void *ccc_omm_min(ccc_ordered_multimap *mm);
500
512[[nodiscard]] void *ccc_omm_extract(ccc_ordered_multimap *mm,
513 ccc_ommap_elem *key_val_handle);
514
527 ccc_ommap_elem *key_val_handle,
528 ccc_any_type_update_fn *fn, void *aux);
529
542 ccc_ommap_elem *key_val_handle,
544 void *aux);
545
558 ccc_ommap_elem *key_val_handle,
560 void *aux);
561
583 ccc_any_type_destructor_fn *destructor);
584
610 void const *begin_key,
611 void const *end_key);
612
620#define ccc_omm_equal_range_r(ordered_multimap_ptr, begin_and_end_key_ptrs...) \
621 &(ccc_range) \
622 { \
623 ccc_omm_equal_range(ordered_multimap_ptr, begin_and_end_key_ptrs).impl \
624 }
625
645 void const *rbegin_key,
646 void const *rend_key);
647
655#define ccc_omm_equal_rrange_r(ordered_multimap_ptr, \
656 rbegin_and_rend_key_ptrs...) \
657 &(ccc_rrange) \
658 { \
659 ccc_omm_equal_rrange(ordered_multimap_ptr, rbegin_and_rend_key_ptrs) \
660 .impl \
661 }
662
671[[nodiscard]] void *ccc_omm_begin(ccc_ordered_multimap const *mm);
672
681[[nodiscard]] void *ccc_omm_rbegin(ccc_ordered_multimap const *mm);
682
693[[nodiscard]] void *ccc_omm_next(ccc_ordered_multimap const *mm,
694 ccc_ommap_elem const *iter_handle);
695
706[[nodiscard]] void *ccc_omm_rnext(ccc_ordered_multimap const *mm,
707 ccc_ommap_elem const *iter_handle);
708
716[[nodiscard]] void *ccc_omm_end(ccc_ordered_multimap const *mm);
717
725[[nodiscard]] void *ccc_omm_rend(ccc_ordered_multimap const *mm);
726
737
742
748
753#ifdef ORDERED_MULTIMAP_USING_NAMESPACE_CCC
754typedef ccc_ommap_elem ommap_elem;
755typedef ccc_ordered_multimap ordered_multimap;
756typedef ccc_ommap_entry ommap_entry;
757# define omm_and_modify_w(args...) ccc_omm_and_modify_w(args)
758# define omm_or_insert_w(args...) ccc_omm_or_insert_w(args)
759# define omm_insert_entry_w(args...) ccc_omm_insert_entry_w(args)
760# define omm_try_insert_w(args...) ccc_omm_try_insert_w(args)
761# define omm_insert_or_assign_w(args...) ccc_omm_insert_or_assign_w(args)
762# define omm_init(args...) ccc_omm_init(args)
763# define omm_swap_entry(args...) ccc_omm_swap_entry(args)
764# define omm_try_insert(args...) ccc_omm_try_insert(args)
765# define omm_insert_or_assign(args...) ccc_omm_insert_or_assign(args)
766# define omm_remove(args...) ccc_omm_remove(args)
767# define omm_remove_entry(args...) ccc_omm_remove_entry(args)
768# define omm_entry_r(args...) ccc_omm_entry_r(args)
769# define omm_entry(args...) ccc_omm_entry(args)
770# define omm_and_modify(args...) ccc_omm_and_modify(args)
771# define omm_and_modify_aux(args...) ccc_omm_and_modify_aux(args)
772# define omm_or_insert(args...) ccc_omm_or_insert(args)
773# define omm_insert_entry(args...) ccc_omm_insert_entry(args)
774# define omm_unwrap(args...) ccc_omm_unwrap(args)
775# define omm_insert_error(args...) ccc_omm_insert_error(args)
776# define omm_occupied(args...) ccc_omm_occupied(args)
777# define omm_clear(args...) ccc_omm_clear(args)
778# define omm_is_empty(args...) ccc_omm_is_empty(args)
779# define omm_size(args...) ccc_omm_size(args)
780# define omm_pop_max(args...) ccc_omm_pop_max(args)
781# define omm_pop_min(args...) ccc_omm_pop_min(args)
782# define omm_max(args...) ccc_omm_max(args)
783# define omm_min(args...) ccc_omm_min(args)
784# define omm_is_max(args...) ccc_omm_is_max(args)
785# define omm_is_min(args...) ccc_omm_is_min(args)
786# define omm_extract(args...) ccc_omm_extract(args)
787# define omm_update(args...) ccc_omm_update(args)
788# define omm_increase(args...) ccc_omm_increase(args)
789# define omm_decrease(args...) ccc_omm_decrease(args)
790# define omm_contains(args...) ccc_omm_contains(args)
791# define omm_begin(args...) ccc_omm_begin(args)
792# define omm_rbegin(args...) ccc_omm_rbegin(args)
793# define omm_next(args...) ccc_omm_next(args)
794# define omm_rnext(args...) ccc_omm_rnext(args)
795# define omm_end(args...) ccc_omm_end(args)
796# define omm_rend(args...) ccc_omm_rend(args)
797# define omm_equal_range(args...) ccc_omm_equal_range(args)
798# define omm_equal_rrange(args...) ccc_omm_equal_rrange(args)
799# define omm_validate(args...) ccc_omm_validate(args)
800#endif /* ORDERED_MULTIMAP_USING_NAMESPACE_CCC */
801
802#endif /* CCC_ORDERED_MULTIMAP_H */
void * ccc_omm_get_key_val(ccc_ordered_multimap *mm, void const *key)
Returns a reference to the user type stored at key. Amortized O(lg N).
ccc_ommap_entry ccc_omm_entry(ccc_ordered_multimap *mm, void const *key)
Return a container specific entry for the given search for key. Amortized O(lg N).
void * ccc_omm_rnext(ccc_ordered_multimap const *mm, ccc_ommap_elem const *iter_handle)
Return the rnext element in a reverse inorder traversal of the multimap. O(1).
struct ccc_ommap_elem ccc_ommap_elem
The intrusive element for the user defined type stored in the multimap.
Definition: ordered_multimap.h:77
ccc_tribool ccc_omm_increase(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle, ccc_any_type_update_fn *fn, void *aux)
Increases an element key that is currently tracked directly as a member of the map....
void * ccc_omm_end(ccc_ordered_multimap const *mm)
Return the end of an inorder traversal of the multimap. O(1).
void * ccc_omm_begin(ccc_ordered_multimap const *mm)
Return the start of an inorder traversal of the multimap. Amortized O(lg N).
ccc_ommap_entry * ccc_omm_and_modify_aux(ccc_ommap_entry *e, ccc_any_type_update_fn *fn, void *aux)
Return a reference to the provided entry modified with fn and auxiliary data aux if Occupied.
ccc_tribool ccc_omm_occupied(ccc_ommap_entry const *e)
Indicates if an entry is Occupied or Vacant.
ccc_result ccc_omm_clear(ccc_ordered_multimap *mm, ccc_any_type_destructor_fn *destructor)
Pops every element from the map calling destructor if destructor is non-NULL. O(N).
ccc_entry ccc_omm_insert_or_assign(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle)
Invariantly inserts the key value pair into the multimap either as the first entry or overwriting the...
void * ccc_omm_or_insert(ccc_ommap_entry const *e, ccc_ommap_elem *key_val_handle)
Insert an initial key value into the multimap if none is present, otherwise return the oldest user ty...
ccc_entry_status ccc_omm_entry_status(ccc_ommap_entry const *e)
Obtain the entry status from a container entry.
ccc_tribool ccc_omm_input_error(ccc_ommap_entry const *e)
Indicates if a function used to generate the provided entry encountered bad arguments that prevented ...
ccc_tribool ccc_omm_validate(ccc_ordered_multimap const *mm)
Returns true if the multimap is empty.
union ccc_ommap_entry ccc_ommap_entry
The container specific type to support the Entry Interface.
Definition: ordered_multimap.h:85
void * ccc_omm_insert_entry(ccc_ommap_entry const *e, ccc_ommap_elem *key_val_handle)
Invariantly writes the specified key value directly to the existing or newly allocated entry....
void * ccc_omm_max(ccc_ordered_multimap *mm)
Returns a reference to the oldest maximum key value user type from the map. Elements are stored in as...
void * ccc_omm_rend(ccc_ordered_multimap const *mm)
Return the rend of a reverse inorder traversal of the multimap. O(1).
ccc_entry ccc_omm_remove(ccc_ordered_multimap *mm, ccc_ommap_elem *out_handle)
Removes the entry specified at key of the type containing out_handle preserving the old value if poss...
void * ccc_omm_min(ccc_ordered_multimap *mm)
Returns a reference to the oldest minimum key value user type from the map. Elements are stored in as...
ccc_ucount ccc_omm_size(ccc_ordered_multimap const *mm)
Returns the size of the multimap. O(1).
ccc_tribool ccc_omm_update(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle, ccc_any_type_update_fn *fn, void *aux)
Updates an element key that is currently tracked directly as a member of the map. Amortized O(lg N).
void * ccc_omm_rbegin(ccc_ordered_multimap const *mm)
Return the start of a reverse inorder traversal of the multimap. Amortized O(lg N).
ccc_entry ccc_omm_remove_entry(ccc_ommap_entry *e)
Removes the entry if it is Occupied. O(1).
ccc_entry ccc_omm_swap_entry(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle)
Returns an entry pointing to the newly inserted element and a status indicating if the map has alread...
ccc_entry ccc_omm_try_insert(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle)
Inserts a new key-value into the multimap only if none exists. Amortized O(lg N).
ccc_ommap_entry * ccc_omm_and_modify(ccc_ommap_entry *e, ccc_any_type_update_fn *fn)
Return a reference to the provided entry modified with fn if Occupied.
ccc_rrange ccc_omm_equal_rrange(ccc_ordered_multimap *mm, 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_omm_extract(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle)
Extracts a user type known to be stored in the map with key_val_handle as an element currently in use...
ccc_result ccc_omm_pop_min(ccc_ordered_multimap *mm)
Pops the oldest minimum element from the map. Elements are stored in ascending order,...
ccc_range ccc_omm_equal_range(ccc_ordered_multimap *mm, void const *begin_key, void const *end_key)
Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).
void * ccc_omm_unwrap(ccc_ommap_entry const *e)
Unwraps the provided entry. An Occupied entry will point to the user type stored in the map,...
ccc_result ccc_omm_pop_max(ccc_ordered_multimap *mm)
Pops the oldest maximum key value user type from the map. Elements are stored in ascending order,...
struct ccc_ommap ccc_ordered_multimap
A container for membership testing by key field, allowing duplicate keys.
Definition: ordered_multimap.h:67
ccc_tribool ccc_omm_contains(ccc_ordered_multimap *mm, void const *key)
Returns the membership of key in the multimap. Amortized O(lg N).
ccc_tribool ccc_omm_insert_error(ccc_ommap_entry const *e)
Indicates if an insertion error occurs.
void * ccc_omm_next(ccc_ordered_multimap const *mm, ccc_ommap_elem const *iter_handle)
Return the next element in an inorder traversal of the multimap. O(1).
ccc_tribool ccc_omm_decrease(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle, ccc_any_type_update_fn *fn, void *aux)
Decreases an element key that is currently tracked directly as a member of the map....
ccc_tribool ccc_omm_is_empty(ccc_ordered_multimap const *mm)
Returns true if the multimap is empty. O(1).
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:187
#define ccc_entry(container_ptr, key_ptr...)
Obtain a container specific entry for the Entry Interface.
Definition: traits.h:141
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:132
union ccc_range ccc_range
The result of a range query on iterable containers.
Definition: types.h:44
union ccc_rrange ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:52
ccc_tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:117
void ccc_any_type_destructor_fn(ccc_any_type)
A callback function for destroying an element in the container.
Definition: types.h:347
void ccc_any_type_update_fn(ccc_any_type)
A callback function for modifying an element in the container.
Definition: types.h:329