C Container Collection (CCC)
Loading...
Searching...
No Matches
ordered_multimap.h
Go to the documentation of this file.
1
32#ifndef CCC_ORDERED_MULTIMAP_H
33#define CCC_ORDERED_MULTIMAP_H
34
36#include <stddef.h>
39#include "impl/impl_ordered_multimap.h"
40#include "types.h"
41
52typedef struct ccc_ommap_ ccc_ordered_multimap;
53
62typedef struct ccc_ommap_elem_ ccc_ommap_elem;
63
70typedef union ccc_ommap_entry_ ccc_ommap_entry;
71
90#define ccc_omm_init(omm_name, user_struct_name, ommap_elem_field, key_field, \
91 key_cmp_fn, alloc_fn, aux) \
92 ccc_impl_omm_init(omm_name, user_struct_name, ommap_elem_field, key_field, \
93 key_cmp_fn, alloc_fn, aux)
94
107 void const *key);
108
115 void const *key);
116
139 ccc_ommap_elem *key_val_handle);
140
154 ccc_ommap_elem *key_val_handle);
155
169#define ccc_omm_try_insert_w(ordered_multimap_ptr, key, lazy_value...) \
170 &(ccc_entry) \
171 { \
172 ccc_impl_omm_try_insert_w(ordered_multimap_ptr, key, lazy_value) \
173 }
174
188[[nodiscard]] ccc_entry
190 ccc_ommap_elem *key_val_handle);
191
207#define ccc_omm_insert_or_assign_w(ordered_multimap_ptr, key, lazy_value...) \
208 &(ccc_entry) \
209 { \
210 ccc_impl_omm_insert_or_assign_w(ordered_multimap_ptr, key, lazy_value) \
211 }
212
225 ccc_ommap_elem *out_handle);
226
235 void const *key);
236
248#define ccc_omm_entry_r(ordered_multimap_ptr, key_ptr) \
249 &(ccc_ommap_entry) \
250 { \
251 ccc_omm_entry((ordered_multimap_ptr), (key_ptr)).impl_ \
252 }
253
263 ccc_update_fn *fn);
264
274[[nodiscard]] ccc_ommap_entry *
276
304#define ccc_omm_and_modify_w(ordered_multimap_entry_ptr, type_name, \
305 closure_over_T...) \
306 &(ccc_ommap_entry) \
307 { \
308 ccc_impl_omm_and_modify_w(ordered_multimap_entry_ptr, type_name, \
309 closure_over_T) \
310 }
311
324[[nodiscard]] void *ccc_omm_or_insert(ccc_ommap_entry const *e,
325 ccc_ommap_elem *key_val_handle);
326
340#define ccc_omm_or_insert_w(ordered_multimap_entry_ptr, lazy_key_value...) \
341 ccc_impl_omm_or_insert_w(ordered_multimap_entry_ptr, lazy_key_value)
342
355[[nodiscard]] void *ccc_omm_insert_entry(ccc_ommap_entry const *e,
356 ccc_ommap_elem *key_val_handle);
357
371#define ccc_omm_insert_entry_w(ordered_multimap_entry_ptr, lazy_key_value...) \
372 ccc_impl_omm_insert_entry_w(ordered_multimap_entry_ptr, lazy_key_value)
373
383
389
394[[nodiscard]] void *ccc_omm_unwrap(ccc_ommap_entry const *e);
395
404
414
425
443
455
468[[nodiscard]] void *ccc_omm_max(ccc_ordered_multimap *mm);
469
482[[nodiscard]] void *ccc_omm_min(ccc_ordered_multimap *mm);
483
495[[nodiscard]] void *ccc_omm_extract(ccc_ordered_multimap *mm,
496 ccc_ommap_elem *key_val_handle);
497
510 ccc_ommap_elem *key_val_handle,
511 ccc_update_fn *fn, void *aux);
512
525 ccc_ommap_elem *key_val_handle,
526 ccc_update_fn *fn, void *aux);
527
540 ccc_ommap_elem *key_val_handle,
541 ccc_update_fn *fn, void *aux);
542
564 ccc_destructor_fn *destructor);
565
591 void const *begin_key,
592 void const *end_key);
593
601#define ccc_omm_equal_range_r(ordered_multimap_ptr, begin_and_end_key_ptrs...) \
602 &(ccc_range) \
603 { \
604 ccc_omm_equal_range(ordered_multimap_ptr, begin_and_end_key_ptrs) \
605 .impl_ \
606 }
607
627 void const *rbegin_key,
628 void const *rend_key);
629
637#define ccc_omm_equal_rrange_r(ordered_multimap_ptr, \
638 rbegin_and_rend_key_ptrs...) \
639 &(ccc_rrange) \
640 { \
641 ccc_omm_equal_rrange(ordered_multimap_ptr, rbegin_and_rend_key_ptrs) \
642 .impl_ \
643 }
644
653[[nodiscard]] void *ccc_omm_begin(ccc_ordered_multimap const *mm);
654
663[[nodiscard]] void *ccc_omm_rbegin(ccc_ordered_multimap const *mm);
664
675[[nodiscard]] void *ccc_omm_next(ccc_ordered_multimap const *mm,
676 ccc_ommap_elem const *iter_handle);
677
688[[nodiscard]] void *ccc_omm_rnext(ccc_ordered_multimap const *mm,
689 ccc_ommap_elem const *iter_handle);
690
698[[nodiscard]] void *ccc_omm_end(ccc_ordered_multimap const *mm);
699
707[[nodiscard]] void *ccc_omm_rend(ccc_ordered_multimap const *mm);
708
719
724
730
735#ifdef ORDERED_MULTIMAP_USING_NAMESPACE_CCC
736typedef ccc_ommap_elem ommap_elem;
737typedef ccc_ordered_multimap ordered_multimap;
738typedef ccc_ommap_entry ommap_entry;
739# define omm_and_modify_w(args...) ccc_omm_and_modify_w(args)
740# define omm_or_insert_w(args...) ccc_omm_or_insert_w(args)
741# define omm_insert_entry_w(args...) ccc_omm_insert_entry_w(args)
742# define omm_try_insert_w(args...) ccc_omm_try_insert_w(args)
743# define omm_insert_or_assign_w(args...) ccc_omm_insert_or_assign_w(args)
744# define omm_init(args...) ccc_omm_init(args)
745# define omm_swap_entry(args...) ccc_omm_swap_entry(args)
746# define omm_try_insert(args...) ccc_omm_try_insert(args)
747# define omm_insert_or_assign(args...) ccc_omm_insert_or_assign(args)
748# define omm_remove(args...) ccc_omm_remove(args)
749# define omm_remove_entry(args...) ccc_omm_remove_entry(args)
750# define omm_entry_r(args...) ccc_omm_entry_r(args)
751# define omm_entry(args...) ccc_omm_entry(args)
752# define omm_and_modify(args...) ccc_omm_and_modify(args)
753# define omm_and_modify_aux(args...) ccc_omm_and_modify_aux(args)
754# define omm_or_insert(args...) ccc_omm_or_insert(args)
755# define omm_insert_entry(args...) ccc_omm_insert_entry(args)
756# define omm_unwrap(args...) ccc_omm_unwrap(args)
757# define omm_insert_error(args...) ccc_omm_insert_error(args)
758# define omm_occupied(args...) ccc_omm_occupied(args)
759# define omm_clear(args...) ccc_omm_clear(args)
760# define omm_is_empty(args...) ccc_omm_is_empty(args)
761# define omm_size(args...) ccc_omm_size(args)
762# define omm_pop_max(args...) ccc_omm_pop_max(args)
763# define omm_pop_min(args...) ccc_omm_pop_min(args)
764# define omm_max(args...) ccc_omm_max(args)
765# define omm_min(args...) ccc_omm_min(args)
766# define omm_is_max(args...) ccc_omm_is_max(args)
767# define omm_is_min(args...) ccc_omm_is_min(args)
768# define omm_extract(args...) ccc_omm_extract(args)
769# define omm_update(args...) ccc_omm_update(args)
770# define omm_increase(args...) ccc_omm_increase(args)
771# define omm_decrease(args...) ccc_omm_decrease(args)
772# define omm_contains(args...) ccc_omm_contains(args)
773# define omm_begin(args...) ccc_omm_begin(args)
774# define omm_rbegin(args...) ccc_omm_rbegin(args)
775# define omm_next(args...) ccc_omm_next(args)
776# define omm_rnext(args...) ccc_omm_rnext(args)
777# define omm_end(args...) ccc_omm_end(args)
778# define omm_rend(args...) ccc_omm_rend(args)
779# define omm_equal_range(args...) ccc_omm_equal_range(args)
780# define omm_equal_rrange(args...) ccc_omm_equal_rrange(args)
781# define omm_validate(args...) ccc_omm_validate(args)
782#endif /* ORDERED_MULTIMAP_USING_NAMESPACE_CCC */
783
784#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).
ccc_tribool ccc_omm_update(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle, ccc_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_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).
ccc_ommap_entry * ccc_omm_and_modify(ccc_ommap_entry *e, ccc_update_fn *fn)
Return a reference to the provided entry modified with fn if Occupied.
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_tribool ccc_omm_occupied(ccc_ommap_entry const *e)
Indicates if an entry is Occupied or Vacant.
union ccc_ommap_entry_ ccc_ommap_entry
The container specific type to support the Entry Interface.
Definition: ordered_multimap.h:70
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...
struct ccc_ommap_ ccc_ordered_multimap
A container for membership testing by key field, allowing duplicate keys.
Definition: ordered_multimap.h:52
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.
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).
struct ccc_ommap_elem_ ccc_ommap_elem
The intrusive element for the user defined type stored in the multimap.
Definition: ordered_multimap.h:62
ccc_tribool ccc_omm_decrease(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle, ccc_update_fn *fn, void *aux)
Decreases an element key that is currently tracked directly as a member of the map....
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).
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_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).
ccc_ommap_entry * ccc_omm_and_modify_aux(ccc_ommap_entry *e, ccc_update_fn *fn, void *aux)
Return a reference to the provided entry modified with fn and auxiliary data aux if Occupied.
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,...
ccc_tribool ccc_omm_increase(ccc_ordered_multimap *mm, ccc_ommap_elem *key_val_handle, ccc_update_fn *fn, void *aux)
Increases an element key that is currently tracked directly as a member of the map....
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_result ccc_omm_clear(ccc_ordered_multimap *mm, ccc_destructor_fn *destructor)
Pops every element from the map calling destructor if destructor is non-NULL. O(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_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:172
The C Container Collection Fundamental Types.
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:300
union ccc_range_ ccc_range
The result of a range query on iterable containers.
Definition: types.h:29
ccc_result
A result of actions on containers.
Definition: types.h:117
union ccc_entry_ ccc_entry
An Occupied or Vacant position in a searchable container.
Definition: types.h:46
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:102
enum ccc_entry_status_ ccc_entry_status
The status monitoring and entry state once it is obtained.
Definition: types.h:56
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:318
union ccc_rrange_ ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:37