C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_ordered_map.h
Go to the documentation of this file.
1
31#ifndef CCC_FLAT_ORDERED_MAP_H
32#define CCC_FLAT_ORDERED_MAP_H
33
35#include <stdbool.h>
36#include <stddef.h>
39#include "impl/impl_flat_ordered_map.h"
40#include "types.h"
41
52typedef struct ccc_fomap_ ccc_flat_ordered_map;
53
61typedef struct ccc_fomap_elem_ ccc_fomap_elem;
62
67typedef union ccc_fomap_entry_ ccc_fomap_entry;
68
85#define ccc_fom_init(mem_ptr, capacity, om_elem_field, key_elem_field, \
86 alloc_fn, key_cmp, aux) \
87 ccc_impl_fom_init(mem_ptr, capacity, om_elem_field, key_elem_field, \
88 alloc_fn, key_cmp, aux)
89
173 ccc_flat_ordered_map const *src, ccc_alloc_fn *fn);
174
185[[nodiscard]] bool ccc_fom_contains(ccc_flat_ordered_map *fom, void const *key);
186
192 void const *key);
193
212 ccc_fomap_elem *out_handle);
213
225#define ccc_fom_insert_r(flat_ordered_map_ptr, out_handle_ptr) \
226 &(ccc_entry) \
227 { \
228 ccc_fom_insert((flat_ordered_map_ptr), (out_handle_ptr)).impl_ \
229 }
230
239 ccc_fomap_elem *key_val_handle);
240
248#define ccc_fom_try_insert_r(flat_ordered_map_ptr, key_val_handle_ptr) \
249 &(ccc_entry) \
250 { \
251 ccc_fom_try_insert((flat_ordered_map_ptr), (key_val_handle_ptr)).impl_ \
252 }
253
266#define ccc_fom_try_insert_w(flat_ordered_map_ptr, key, lazy_value...) \
267 &(ccc_entry) \
268 { \
269 ccc_impl_fom_try_insert_w(flat_ordered_map_ptr, key, lazy_value) \
270 }
271
280[[nodiscard]] ccc_entry
282 ccc_fomap_elem *key_val_handle);
283
296#define ccc_fom_insert_or_assign_w(flat_ordered_map_ptr, key, lazy_value...) \
297 &(ccc_entry) \
298 { \
299 ccc_impl_fom_insert_or_assign_w(flat_ordered_map_ptr, key, lazy_value) \
300 }
301
313 ccc_fomap_elem *out_handle);
314
325#define ccc_fom_remove_r(flat_ordered_map_ptr, out_handle_ptr) \
326 &(ccc_entry) \
327 { \
328 ccc_fom_remove((flat_ordered_map_ptr), (out_handle_ptr)).impl_ \
329 }
330
346 void const *key);
347
363#define ccc_fom_entry_r(flat_ordered_map_ptr, key_ptr) \
364 &(ccc_fomap_entry) \
365 { \
366 ccc_fom_entry((flat_ordered_map_ptr), (key_ptr)).impl_ \
367 }
368
378 ccc_update_fn *fn);
379
388[[nodiscard]] ccc_fomap_entry *
390
417#define ccc_fom_and_modify_w(flat_ordered_map_entry_ptr, type_name, \
418 closure_over_T...) \
419 &(ccc_fomap_entry) \
420 { \
421 ccc_impl_fom_and_modify_w(flat_ordered_map_entry_ptr, type_name, \
422 closure_over_T) \
423 }
424
436[[nodiscard]] void *ccc_fom_or_insert(ccc_fomap_entry const *e,
437 ccc_fomap_elem *elem);
438
450#define ccc_fom_or_insert_w(flat_ordered_map_entry_ptr, lazy_key_value...) \
451 ccc_impl_fom_or_insert_w(flat_ordered_map_entry_ptr, lazy_key_value)
452
460[[nodiscard]] void *ccc_fom_insert_entry(ccc_fomap_entry const *e,
461 ccc_fomap_elem *elem);
462
468#define ccc_fom_insert_entry_w(flat_ordered_map_entry_ptr, lazy_key_value...) \
469 ccc_impl_fom_insert_entry_w(flat_ordered_map_entry_ptr, lazy_key_value)
470
480
489#define ccc_fom_remove_entry_r(flat_ordered_map_entry_ptr) \
490 &(ccc_entry) \
491 { \
492 ccc_fom_remove_entry((flat_ordered_map_entry_ptr)).impl_ \
493 }
494
498[[nodiscard]] void *ccc_fom_unwrap(ccc_fomap_entry const *e);
499
503[[nodiscard]] bool ccc_fom_occupied(ccc_fomap_entry const *e);
504
509[[nodiscard]] bool ccc_fom_insert_error(ccc_fomap_entry const *e);
510
521
549 void const *begin_key,
550 void const *end_key);
551
558#define ccc_fom_equal_range_r(flat_ordered_map_ptr, begin_and_end_key_ptrs...) \
559 &(ccc_range) \
560 { \
561 ccc_fom_equal_range(flat_ordered_map_ptr, begin_and_end_key_ptrs) \
562 .impl_ \
563 }
564
586 void const *rbegin_key,
587 void const *rend_key);
588
596#define ccc_fom_equal_rrange_r(flat_ordered_map_ptr, \
597 rbegin_and_rend_key_ptrs...) \
598 &(ccc_rrange) \
599 { \
600 ccc_fom_equal_rrange(flat_ordered_map_ptr, rbegin_and_rend_key_ptrs) \
601 .impl_ \
602 }
603
608[[nodiscard]] void *ccc_fom_begin(ccc_flat_ordered_map const *fom);
609
614[[nodiscard]] void *ccc_fom_rbegin(ccc_flat_ordered_map const *fom);
615
621[[nodiscard]] void *ccc_fom_next(ccc_flat_ordered_map const *fom,
622 ccc_fomap_elem const *iter_handle);
623
630[[nodiscard]] void *ccc_fom_rnext(ccc_flat_ordered_map const *fom,
631 ccc_fomap_elem const *iter_handle);
632
636[[nodiscard]] void *ccc_fom_end(ccc_flat_ordered_map const *fom);
637
641[[nodiscard]] void *ccc_fom_rend(ccc_flat_ordered_map const *fom);
642
657
670
680[[nodiscard]] size_t ccc_fom_size(ccc_flat_ordered_map const *fom);
681
685[[nodiscard]] size_t ccc_fom_capacity(ccc_flat_ordered_map const *fom);
686
696[[nodiscard]] void *ccc_fom_data(ccc_flat_ordered_map const *fom);
697
701[[nodiscard]] bool ccc_fom_is_empty(ccc_flat_ordered_map const *fom);
702
706[[nodiscard]] bool ccc_fom_validate(ccc_flat_ordered_map const *fom);
707
712#ifdef FLAT_ORDERED_MAP_USING_NAMESPACE_CCC
713typedef ccc_flat_ordered_map flat_ordered_map;
714typedef ccc_fomap_elem fomap_elem;
715typedef ccc_fomap_entry fomap_entry;
716# define fom_and_modify_w(args...) ccc_fom_and_modify_w(args)
717# define fom_or_insert_w(args...) ccc_fom_or_insert_w(args)
718# define fom_insert_entry_w(args...) ccc_fom_insert_entry_w(args)
719# define fom_try_insert_w(args...) ccc_fom_try_insert_w(args)
720# define fom_insert_or_assign_w(args...) ccc_fom_insert_or_assign_w(args)
721# define fom_init(args...) ccc_fom_init(args)
722# define fom_copy(args...) ccc_fom_copy(args)
723# define fom_contains(args...) ccc_fom_contains(args)
724# define fom_get_key_val(args...) ccc_fom_get_key_val(args)
725# define fom_insert_r(args...) ccc_fom_insert_r(args)
726# define fom_try_insert_r(args...) ccc_fom_try_insert_r(args)
727# define fom_remove_r(args...) ccc_fom_remove_r(args)
728# define fom_remove_entry_r(args...) ccc_fom_remove_entry_r(args)
729# define fom_insert(args...) ccc_fom_insert(args)
730# define fom_try_insert(args...) ccc_fom_try_insert(args)
731# define fom_insert_or_assign(args...) ccc_fom_insert_or_assign(args)
732# define fom_remove(args...) ccc_fom_remove(args)
733# define fom_remove_entry(args...) ccc_fom_remove_entry(args)
734# define fom_entry_r(args...) ccc_fom_entry_r(args)
735# define fom_entry(args...) ccc_fom_entry(args)
736# define fom_and_modify(args...) ccc_fom_and_modify(args)
737# define fom_and_modify_aux(args...) ccc_fom_and_modify_aux(args)
738# define fom_or_insert(args...) ccc_fom_or_insert(args)
739# define fom_insert_entry(args...) ccc_fom_insert_entry(args)
740# define fom_unwrap(args...) ccc_fom_unwrap(args)
741# define fom_insert_error(args...) ccc_fom_insert_error(args)
742# define fom_occupied(args...) ccc_fom_occupied(args)
743# define fom_clear(args...) ccc_fom_clear(args)
744# define fom_clear_and_free(args...) ccc_fom_clear_and_free(args)
745# define fom_begin(args...) ccc_fom_begin(args)
746# define fom_rbegin(args...) ccc_fom_rbegin(args)
747# define fom_end(args...) ccc_fom_end(args)
748# define fom_rend(args...) ccc_fom_rend(args)
749# define fom_next(args...) ccc_fom_next(args)
750# define fom_rnext(args...) ccc_fom_rnext(args)
751# define fom_data(args...) ccc_fom_data(args)
752# define fom_size(args...) ccc_fom_size(args)
753# define fom_is_empty(args...) ccc_fom_is_empty(args)
754# define fom_validate(args...) ccc_fom_validate(args)
755#endif /* FLAT_ORDERED_MAP_USING_NAMESPACE_CCC */
756
757#endif /* CCC_FLAT_ORDERED_MAP_H */
ccc_fomap_entry * ccc_fom_and_modify_aux(ccc_fomap_entry *e, ccc_update_fn *fn, void *aux)
Modifies the provided entry if it is Occupied.
union ccc_fomap_entry_ ccc_fomap_entry
A container specific entry used to implement the Entry Interface.
Definition: flat_ordered_map.h:67
void * ccc_fom_rnext(ccc_flat_ordered_map const *fom, ccc_fomap_elem const *iter_handle)
Return the rnext element in a reverse inorder traversal of the map. O(1).
void * ccc_fom_end(ccc_flat_ordered_map const *fom)
Return the end of an inorder traversal of the map. O(1).
bool ccc_fom_is_empty(ccc_flat_ordered_map const *fom)
Returns the size status of the map.
bool ccc_fom_contains(ccc_flat_ordered_map *fom, void const *key)
Searches the map for the presence of key.
struct ccc_fomap_elem_ ccc_fomap_elem
The intrusive element for the user defined type being stored in the map.
Definition: flat_ordered_map.h:61
ccc_entry ccc_fom_try_insert(ccc_flat_ordered_map *fom, ccc_fomap_elem *key_val_handle)
Attempts to insert the key value wrapping key_val_handle.
ccc_entry ccc_fom_insert_or_assign(ccc_flat_ordered_map *fom, ccc_fomap_elem *key_val_handle)
Invariantly inserts or overwrites a user struct into the map.
ccc_range ccc_fom_equal_range(ccc_flat_ordered_map *fom, void const *begin_key, void const *end_key)
Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).
size_t ccc_fom_capacity(ccc_flat_ordered_map const *fom)
Returns the capacity of the map.
size_t ccc_fom_size(ccc_flat_ordered_map const *fom)
Returns the size of the map.
ccc_fomap_entry ccc_fom_entry(ccc_flat_ordered_map *fom, void const *key)
Obtains an entry for the provided key in the map for future use.
ccc_entry_status ccc_fom_entry_status(ccc_fomap_entry const *e)
Obtain the entry status from a container entry.
ccc_result ccc_fom_clear(ccc_flat_ordered_map *fom, ccc_destructor_fn *fn)
Frees all slots in the map for use without affecting capacity.
ccc_fomap_entry * ccc_fom_and_modify(ccc_fomap_entry *e, ccc_update_fn *fn)
Modifies the provided entry if it is Occupied.
bool ccc_fom_occupied(ccc_fomap_entry const *e)
Returns the Vacant or Occupied status of the entry.
ccc_rrange ccc_fom_equal_rrange(ccc_flat_ordered_map *fom, void const *rbegin_key, void const *rend_key)
Return an iterable rrange of values from [rbegin_key, end_key). Amortized O(lg N).
void * ccc_fom_rend(ccc_flat_ordered_map const *fom)
Return the rend of a reverse inorder traversal of the map. O(1).
ccc_result ccc_fom_clear_and_free(ccc_flat_ordered_map *fom, ccc_destructor_fn *fn)
Frees all slots in the map and frees the underlying buffer.
void * ccc_fom_get_key_val(ccc_flat_ordered_map *fom, void const *key)
Returns a reference into the map at entry key.
ccc_entry ccc_fom_insert(ccc_flat_ordered_map *fom, ccc_fomap_elem *out_handle)
Invariantly inserts the key value wrapping key_val_handle.
ccc_entry ccc_fom_remove(ccc_flat_ordered_map *fom, ccc_fomap_elem *out_handle)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
bool ccc_fom_validate(ccc_flat_ordered_map const *fom)
Validation of invariants for the map.
ccc_entry ccc_fom_remove_entry(ccc_fomap_entry *e)
Remove the entry from the map if Occupied.
struct ccc_fomap_ ccc_flat_ordered_map
A self-optimizing data structure offering amortized O(lg N) search, insert, and erase.
Definition: flat_ordered_map.h:52
void * ccc_fom_insert_entry(ccc_fomap_entry const *e, ccc_fomap_elem *elem)
Inserts the provided entry invariantly.
void * ccc_fom_unwrap(ccc_fomap_entry const *e)
Unwraps the provided entry to obtain a view into the map element.
ccc_result ccc_fom_copy(ccc_flat_ordered_map *dst, ccc_flat_ordered_map const *src, ccc_alloc_fn *fn)
Copy the map at source to destination.
bool ccc_fom_insert_error(ccc_fomap_entry const *e)
Provides the status of the entry should an insertion follow.
void * ccc_fom_data(ccc_flat_ordered_map const *fom)
Return a reference to the base of backing array. O(1).
void * ccc_fom_or_insert(ccc_fomap_entry const *e, ccc_fomap_elem *elem)
Inserts the struct with handle elem if the entry is Vacant.
void * ccc_fom_next(ccc_flat_ordered_map const *fom, ccc_fomap_elem const *iter_handle)
Return the next element in an inorder traversal of the map. O(1).
void * ccc_fom_begin(ccc_flat_ordered_map const *fom)
Return the start of an inorder traversal of the map. Amortized O(lg N).
void * ccc_fom_rbegin(ccc_flat_ordered_map const *fom)
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:65
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:216
union ccc_range_ ccc_range
The result of a range query on iterable containers.
Definition: types.h:30
union ccc_entry_ ccc_entry
An Occupied or Vacant position in a searchable container.
Definition: types.h:47
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:199
enum ccc_entry_status_ ccc_entry_status
The status monitoring and entry state once it is obtained.
Definition: types.h:57
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:234
union ccc_rrange_ ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:38