C Container Collection (CCC)
Loading...
Searching...
No Matches
adaptive_map.h
Go to the documentation of this file.
1
39#ifndef CCC_ADAPTIVE_MAP_H
40#define CCC_ADAPTIVE_MAP_H
41
43#include <stddef.h>
47#include "types.h"
48
60
69
75
91#define CCC_adaptive_map_initialize(struct_name, type_intruder_field_name, \
92 type_key_field_name, key_order, allocate, \
93 context) \
94 CCC_private_adaptive_map_initialize(struct_name, type_intruder_field_name, \
95 type_key_field_name, key_order, \
96 allocate, context)
97
119#define CCC_adaptive_map_from(type_intruder_field_name, type_key_field_name, \
120 compare, allocate, destroy, context_data, \
121 compound_literal_array...) \
122 CCC_private_adaptive_map_from( \
123 type_intruder_field_name, type_key_field_name, compare, allocate, \
124 destroy, context_data, compound_literal_array)
125
138 void const *key);
139
145 void const *key);
146
166[[nodiscard]] CCC_Entry
168 CCC_Adaptive_map_node *type_intruder,
169 CCC_Adaptive_map_node *temp_intruder);
170
185#define CCC_adaptive_map_swap_entry_wrap(map_pointer, type_intruder_pointer, \
186 temp_intruder_pointer) \
187 &(CCC_Entry) \
188 { \
189 CCC_adaptive_map_swap_entry((map_pointer), (type_intruder_pointer), \
190 (temp_intruder_pointer)) \
191 .private \
192 }
193
201[[nodiscard]] CCC_Entry
203 CCC_Adaptive_map_node *type_intruder);
204
214#define CCC_adaptive_map_try_insert_wrap(map_pointer, type_intruder_pointer) \
215 &(CCC_Entry) \
216 { \
217 CCC_adaptive_map_try_insert((map_pointer), (type_intruder_pointer)) \
218 .private \
219 }
220
234#define CCC_adaptive_map_try_insert_with(map_pointer, key, \
235 compound_literal_type...) \
236 &(CCC_Entry) \
237 { \
238 CCC_private_adaptive_map_try_insert_with(map_pointer, key, \
239 compound_literal_type) \
240 }
241
250[[nodiscard]] CCC_Entry
252 CCC_Adaptive_map_node *type_intruder);
253
267#define CCC_adaptive_map_insert_or_assign_with(map_pointer, key, \
268 compound_literal_type...) \
269 &(CCC_Entry) \
270 { \
271 CCC_private_adaptive_map_insert_or_assign_with(map_pointer, key, \
272 compound_literal_type) \
273 }
274
290[[nodiscard]] CCC_Entry
292 CCC_Adaptive_map_node *type_output_intruder);
293
310#define CCC_adaptive_map_remove_key_value_wrap(map_pointer, \
311 type_output_intruder_pointer) \
312 &(CCC_Entry) \
313 { \
314 CCC_adaptive_map_remove_key_value((map_pointer), \
315 (type_output_intruder_pointer)) \
316 .private \
317 }
318
333[[nodiscard]] CCC_Adaptive_map_entry
335
352#define CCC_adaptive_map_entry_wrap(map_pointer, key_pointer) \
353 &(CCC_Adaptive_map_entry) \
354 { \
355 CCC_adaptive_map_entry((map_pointer), (key_pointer)).private \
356 }
357
367[[nodiscard]] CCC_Adaptive_map_entry *
369 CCC_Type_modifier *modify);
370
379[[nodiscard]] CCC_Adaptive_map_entry *
381 CCC_Type_modifier *modify, void *context);
382
419#define CCC_adaptive_map_and_modify_with(adaptive_map_entry_pointer, \
420 type_name, closure_over_T...) \
421 &(CCC_Adaptive_map_entry) \
422 { \
423 CCC_private_adaptive_map_and_modify_with(adaptive_map_entry_pointer, \
424 type_name, closure_over_T) \
425 }
426
440[[nodiscard]] void *
442 CCC_Adaptive_map_node *type_intruder);
443
455#define CCC_adaptive_map_or_insert_with(adaptive_map_entry_pointer, \
456 type_compound_literal...) \
457 CCC_private_adaptive_map_or_insert_with(adaptive_map_entry_pointer, \
458 type_compound_literal)
459
467[[nodiscard]] void *
469 CCC_Adaptive_map_node *type_intruder);
470
477#define CCC_adaptive_map_insert_entry_with(adaptive_map_entry_pointer, \
478 type_compound_literal...) \
479 CCC_private_adaptive_map_insert_entry_with(adaptive_map_entry_pointer, \
480 type_compound_literal)
481
492[[nodiscard]] CCC_Entry
494
505#define CCC_adaptive_map_remove_entry_wrap(adaptive_map_entry_pointer) \
506 &(CCC_Entry) \
507 { \
508 CCC_adaptive_map_remove_entry((adaptive_map_entry_pointer)).private \
509 }
510
514[[nodiscard]] void *
516
520[[nodiscard]] CCC_Tribool
522
528[[nodiscard]] CCC_Tribool
530
540[[nodiscard]] CCC_Entry_status
542
570 void const *begin_key,
571 void const *end_key);
572
580#define CCC_adaptive_map_equal_range_wrap(map_pointer, \
581 begin_and_end_key_pointers...) \
582 &(CCC_Range) \
583 { \
584 CCC_adaptive_map_equal_range(map_pointer, begin_and_end_key_pointers) \
585 .private \
586 }
587
611[[nodiscard]] CCC_Range_reverse
613 void const *reverse_begin_key,
614 void const *reverse_end_key);
615
623#define CCC_adaptive_map_equal_range_reverse_wrap( \
624 map_pointer, reverse_begin_and_reverse_end_key_pointers...) \
625 &(CCC_Range_reverse) \
626 { \
627 CCC_adaptive_map_equal_range_reverse( \
628 map_pointer, reverse_begin_and_reverse_end_key_pointers) \
629 .private \
630 }
631
636[[nodiscard]] void *CCC_adaptive_map_begin(CCC_Adaptive_map const *map);
637
642[[nodiscard]] void *CCC_adaptive_map_reverse_begin(CCC_Adaptive_map const *map);
643
649[[nodiscard]] void *
651 CCC_Adaptive_map_node const *iterator_intruder);
652
660[[nodiscard]] void *
662 CCC_Adaptive_map_node const *iterator_intruder);
663
667[[nodiscard]] void *CCC_adaptive_map_end(CCC_Adaptive_map const *map);
668
673[[nodiscard]] void *CCC_adaptive_map_reverse_end(CCC_Adaptive_map const *map);
674
696 CCC_Type_destructor *destroy);
697
707[[nodiscard]] CCC_Tribool
709
714
719[[nodiscard]] CCC_Tribool
721
726#ifdef ADAPTIVE_MAP_USING_NAMESPACE_CCC
727typedef CCC_Adaptive_map_node Adaptive_map_node;
728typedef CCC_Adaptive_map Adaptive_map;
729typedef CCC_Adaptive_map_entry Adaptive_map_entry;
730# define adaptive_map_initialize(args...) CCC_adaptive_map_initialize(args)
731# define adaptive_map_from(args...) CCC_adaptive_map_from(args)
732# define adaptive_map_and_modify_with(args...) \
733 CCC_adaptive_map_and_modify_with(args)
734# define adaptive_map_or_insert_with(args...) \
735 CCC_adaptive_map_or_insert_with(args)
736# define adaptive_map_insert_entry_with(args...) \
737 CCC_adaptive_map_insert_entry_with(args)
738# define adaptive_map_try_insert_with(args...) \
739 CCC_adaptive_map_try_insert_with(args)
740# define adaptive_map_insert_or_assign_with(args...) \
741 CCC_adaptive_map_insert_or_assign_with(args)
742# define adaptive_map_swap_entry_wrap(args...) \
743 CCC_adaptive_map_swap_entry_wrap(args)
744# define adaptive_map_remove_key_value_wrap(args...) \
745 CCC_adaptive_map_remove_key_value_wrap(args)
746# define adaptive_map_remove_entry_wrap(args...) \
747 CCC_adaptive_map_remove_entry_wrap(args)
748# define adaptive_map_entry_wrap(args...) CCC_adaptive_map_entry_wrap(args)
749# define adaptive_map_and_modify_wrap(args...) \
750 CCC_adaptive_map_and_modify_wrap(args)
751# define adaptive_map_and_modify_context_wrap(args...) \
752 CCC_adaptive_map_and_modify_context_wrap(args)
753# define adaptive_map_contains(args...) CCC_adaptive_map_contains(args)
754# define adaptive_map_get_key_value(args...) \
755 CCC_adaptive_map_get_key_value(args)
756# define adaptive_map_get_mut(args...) CCC_adaptive_map_get_mut(args)
757# define adaptive_map_swap_entry(args...) CCC_adaptive_map_swap_entry(args)
758# define adaptive_map_remove_key_value(args...) \
759 CCC_adaptive_map_remove_key_value(args)
760# define adaptive_map_entry(args...) CCC_adaptive_map_entry(args)
761# define adaptive_map_remove_entry(args...) \
762 CCC_adaptive_map_remove_entry(args)
763# define adaptive_map_or_insert(args...) CCC_adaptive_map_or_insert(args)
764# define adaptive_map_insert_entry(args...) \
765 CCC_adaptive_map_insert_entry(args)
766# define adaptive_map_unwrap(args...) CCC_adaptive_map_unwrap(args)
767# define adaptive_map_unwrap_mut(args...) CCC_adaptive_map_unwrap_mut(args)
768# define adaptive_map_begin(args...) CCC_adaptive_map_begin(args)
769# define adaptive_map_next(args...) CCC_adaptive_map_next(args)
770# define adaptive_map_reverse_begin(args...) \
771 CCC_adaptive_map_reverse_begin(args)
772# define adaptive_map_reverse_next(args...) \
773 CCC_adaptive_map_reverse_next(args)
774# define adaptive_map_end(args...) CCC_adaptive_map_end(args)
775# define adaptive_map_reverse_end(args...) CCC_adaptive_map_reverse_end(args)
776# define adaptive_map_count(args...) CCC_adaptive_map_count(args)
777# define adaptive_map_is_empty(args...) CCC_adaptive_map_is_empty(args)
778# define adaptive_map_clear(args...) CCC_adaptive_map_clear(args)
779# define adaptive_map_validate(args...) CCC_adaptive_map_validate(args)
780#endif
781
782#endif /* CCC_ADAPTIVE_MAP_H */
CCC_Range CCC_adaptive_map_equal_range(CCC_Adaptive_map *map, 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_adaptive_map_reverse_end(CCC_Adaptive_map const *map)
Return the reverse_end of a reverse inorder traversal of the map. O(1).
void * CCC_adaptive_map_or_insert(CCC_Adaptive_map_entry const *entry, CCC_Adaptive_map_node *type_intruder)
Inserts the struct with handle type_intruder if the entry is Vacant.
CCC_Tribool CCC_adaptive_map_validate(CCC_Adaptive_map const *map)
Validation of invariants for the map.
CCC_Entry_status CCC_adaptive_map_entry_status(CCC_Adaptive_map_entry const *entry)
Obtain the entry status from a container entry.
void * CCC_adaptive_map_next(CCC_Adaptive_map const *map, CCC_Adaptive_map_node const *iterator_intruder)
Return the next element in an inorder traversal of the map. O(1).
CCC_Entry CCC_adaptive_map_insert_or_assign(CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_intruder)
Invariantly inserts or overwrites a user struct into the map.
CCC_Tribool CCC_adaptive_map_contains(CCC_Adaptive_map *map, void const *key)
Searches the map for the presence of key.
CCC_Result CCC_adaptive_map_clear(CCC_Adaptive_map *map, CCC_Type_destructor *destroy)
Pops every element from the map calling destructor if destructor is non-NULL. O(N).
CCC_Tribool CCC_adaptive_map_insert_error(CCC_Adaptive_map_entry const *entry)
Provides the status of the entry should an insertion follow.
void * CCC_adaptive_map_reverse_next(CCC_Adaptive_map const *map, CCC_Adaptive_map_node const *iterator_intruder)
Return the reverse_next element in a reverse inorder traversal of the map. O(1).
CCC_Adaptive_map_entry CCC_adaptive_map_entry(CCC_Adaptive_map *map, void const *key)
Obtains an entry for the provided key in the map for future use.
CCC_Tribool CCC_adaptive_map_is_empty(CCC_Adaptive_map const *map)
Returns the size status of the map.
void * CCC_adaptive_map_end(CCC_Adaptive_map const *map)
Return the end of an inorder traversal of the map. O(1).
CCC_Entry CCC_adaptive_map_remove_entry(CCC_Adaptive_map_entry *entry)
Remove the entry from the map if Occupied.
void * CCC_adaptive_map_begin(CCC_Adaptive_map const *map)
Return the start of an inorder traversal of the map. Amortized O(lg N).
CCC_Entry CCC_adaptive_map_swap_entry(CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_intruder, CCC_Adaptive_map_node *temp_intruder)
Invariantly inserts the key value wrapping type_intruder.
void * CCC_adaptive_map_get_key_value(CCC_Adaptive_map *map, void const *key)
Returns a reference into the map at entry key.
CCC_Adaptive_map_entry * CCC_adaptive_map_and_modify_context(CCC_Adaptive_map_entry *entry, CCC_Type_modifier *modify, void *context)
Modifies the provided entry if it is Occupied.
CCC_Entry CCC_adaptive_map_try_insert(CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_intruder)
Attempts to insert the key value wrapping type_intruder.
CCC_Entry CCC_adaptive_map_remove_key_value(CCC_Adaptive_map *map, CCC_Adaptive_map_node *type_output_intruder)
Removes the key value in the map storing the old value, if present, in the struct containing type_out...
void * CCC_adaptive_map_reverse_begin(CCC_Adaptive_map const *map)
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
CCC_Tribool CCC_adaptive_map_occupied(CCC_Adaptive_map_entry const *entry)
Returns the Vacant or Occupied status of the entry.
void * CCC_adaptive_map_unwrap(CCC_Adaptive_map_entry const *entry)
Unwraps the provided entry to obtain a view into the map element.
void * CCC_adaptive_map_insert_entry(CCC_Adaptive_map_entry const *entry, CCC_Adaptive_map_node *type_intruder)
Inserts the provided entry invariantly.
CCC_Adaptive_map_entry * CCC_adaptive_map_and_modify(CCC_Adaptive_map_entry *entry, CCC_Type_modifier *modify)
Modifies the provided entry if it is Occupied.
CCC_Range_reverse CCC_adaptive_map_equal_range_reverse(CCC_Adaptive_map *map, void const *reverse_begin_key, void const *reverse_end_key)
Return an iterable range_reverse of values from [begin_key, end_key). Amortized O(lg N).
CCC_Count CCC_adaptive_map_count(CCC_Adaptive_map const *map)
Returns the count of occupied map nodes.
The Adaptive Map Private Interface.
Definition: private_adaptive_map.h:93
Definition: private_adaptive_map.h:44
Definition: private_adaptive_map.h:59
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:202
Definition: private_types.h:53
Definition: private_types.h:112
The C Container Collection Fundamental Types.
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:133
void CCC_Type_destructor(CCC_Type_context)
A callback function for destroying an element in the container.
Definition: types.h:376
CCC_Result
A result of actions on containers.
Definition: types.h:148
void CCC_Type_modifier(CCC_Type_context)
A callback function for modifying an element in the container.
Definition: types.h:358
Definition: private_adaptive_map.h:105
Definition: private_types.h:160