30 #ifndef CDCONTAINERS_INCLUDE_CDCONTAINERS_MAP_H 31 #define CDCONTAINERS_INCLUDE_CDCONTAINERS_MAP_H 256 void *iter = it ? it->
iter : NULL;
280 void *iter = it ? it->
iter : NULL;
505 #ifdef CDC_USE_SHORT_NAMES 510 #define map_ctor(...) cdc_map_ctor(__VA_ARGS__) 511 #define map_ctorv(...) cdc_map_ctorv(__VA_ARGS__) 512 #define map_ctorl(...) cdc_map_ctorl(__VA_ARGS__) 513 #define map_dtor(...) cdc_map_dtor(__VA_ARGS__) 516 #define map_get(...) cdc_map_get(__VA_ARGS__) 517 #define map_count(...) cdc_map_count(__VA_ARGS__) 518 #define map_find(...) cdc_map_find(__VA_ARGS__) 521 #define map_size(...) cdc_map_size(__VA_ARGS__) 522 #define map_empty(...) cdc_map_empty(__VA_ARGS__) 525 #define map_clear(...) cdc_map_clear(__VA_ARGS__) 526 #define map_insert(...) cdc_map_insert(__VA_ARGS__) 527 #define map_insert_or_assign(...) cdc_map_insert_or_assign(__VA_ARGS__) 528 #define map_erase(...) cdc_map_erase(__VA_ARGS__) 529 #define map_swap(...) cdc_map_swap(__VA_ARGS__) 532 #define map_begin(...) cdc_map_begin(__VA_ARGS__) 533 #define map_end(...) cdc_map_end(__VA_ARGS__) 536 #define map_iter_ctor(...) cdc_map_iter_ctor(__VA_ARGS__) 537 #define map_iter_dtor(...) cdc_map_iter_dtor(__VA_ARGS__) 538 #define map_iter_next(...) cdc_map_iter_next(__VA_ARGS__) 539 #define map_iter_has_next(...) cdc_map_iter_has_next(__VA_ARGS__) 540 #define map_iter_key(...) cdc_map_iter_key(__VA_ARGS__) 541 #define map_iter_value(...) cdc_map_iter_value(__VA_ARGS__) 542 #define map_iter_key_value(...) cdc_map_iter_key_value(__VA_ARGS__) 543 #define map_iter_is_eq(...) cdc_map_iter_is_eq(__VA_ARGS__) 546 #endif // CDCONTAINERS_INCLUDE_CDCONTAINERS_MAP_H void(* find)(void *cntr, void *key, void *it)
Definition: imap.h:66
size_t(* count)(void *cntr, void *key)
Definition: imap.h:65
static void cdc_map_iter_next(struct cdc_map_iter *it)
Advances the iterator to the next element in the map.
Definition: map.h:403
static size_t cdc_map_erase(struct cdc_map *m, void *key)
Removes the element (if one exists) with the key equivalent to key.
Definition: map.h:290
bool(* has_next)(void *it)
Definition: imap.h:47
static void cdc_map_iter_prev(struct cdc_map_iter *it)
Advances the iterator to the previous element in the map.
Definition: map.h:414
enum cdc_stat cdc_map_ctor(const struct cdc_map_table *table, struct cdc_map **m, struct cdc_data_info *info)
Constructs an empty map.
enum cdc_stat(* insert)(void *cntr, void *key, void *value, void *it, bool *inserted)
Definition: imap.h:70
void * iter
Definition: map.h:62
enum cdc_stat(* get)(void *cntr, void *key, void **value)
Definition: imap.h:64
bool(* has_prev)(void *it)
Definition: imap.h:48
void(* end)(void *cntr, void *it)
Definition: imap.h:77
static void cdc_map_end(struct cdc_map *m, struct cdc_map_iter *it)
Initializes the iterator to the end.
Definition: map.h:335
void *(* value)(void *it)
Definition: imap.h:50
static bool cdc_map_iter_has_prev(struct cdc_map_iter *it)
Returns true if there is at least one element behind the iterator, i.e. the iterator is not at the fr...
Definition: map.h:442
The cdc_map is service struct.
Definition: map.h:51
void(* begin)(void *cntr, void *it)
Definition: imap.h:76
static void cdc_map_iter_dtor(struct cdc_map_iter *it)
Destroys the iterator. It should be called after the iterator is no longer needed. Releases resources.
Definition: map.h:380
static bool cdc_map_iter_is_eq(struct cdc_map_iter *it1, struct cdc_map_iter *it2)
Returns false if the iterator |it1| equal to the iterator |it2|, otherwise returns false...
Definition: map.h:493
void(* next)(void *it)
Definition: imap.h:45
The cdc_map_table is a map interface.
enum cdc_stat(* insert_or_assign)(void *cntr, void *key, void *value, void *it, bool *inserted)
Definition: imap.h:72
The cdc_map_table struct.
Definition: imap.h:60
static void * cdc_map_iter_value(struct cdc_map_iter *it)
Returns an item's value.
Definition: map.h:466
static void cdc_map_find(struct cdc_map *m, void *key, struct cdc_map_iter *it)
Finds an element with key equivalent to key.
Definition: map.h:182
static size_t cdc_map_count(struct cdc_map *m, void *key)
Returns the number of elements with key that compares equal to the specified argument key...
Definition: map.h:167
const struct cdc_map_iter_table * table
Definition: map.h:63
static void cdc_map_clear(struct cdc_map *m)
Removes all the elements from the map.
Definition: map.h:230
enum cdc_stat cdc_map_iter_ctor(struct cdc_map *m, struct cdc_map_iter *it)
Constructs a map iterator. Should be called for each new iterator.
cdc_iterator_type
Definition: common.h:115
static struct cdc_pair cdc_map_iter_key_value(struct cdc_map_iter *it)
Returns a pair, where first - key, second - value.
Definition: map.h:478
const struct cdc_map_table * table
Definition: map.h:53
enum cdc_stat cdc_map_ctorv(const struct cdc_map_table *table, struct cdc_map **m, struct cdc_data_info *info, va_list args)
Constructs a map, initialized by args. The last item must be CDC_END.
#define CDC_SWAP(T, x, y)
Definition: common.h:40
enum cdc_stat cdc_map_ctorl(const struct cdc_map_table *table, struct cdc_map **m, struct cdc_data_info *info,...)
Constructs a map, initialized by an variable number of pointers on cdc_pair's(first - key...
The cdc_map_iter_table struct.
Definition: imap.h:41
static bool cdc_map_iter_has_next(struct cdc_map_iter *it)
Returns true if there is at least one element ahead of the iterator, i.e. the iterator is not at the ...
Definition: map.h:428
void * container
Definition: map.h:52
bool(* eq)(void *it1, void *it2)
Definition: imap.h:52
static void * cdc_map_iter_key(struct cdc_map_iter *it)
Returns an item's key.
Definition: map.h:454
cdc_stat
Definition: status.h:24
void(* dtor)(void *it)
Definition: imap.h:43
static void cdc_map_swap(struct cdc_map *a, struct cdc_map *b)
Swaps maps a and b. This operation is very fast and never fails.
Definition: map.h:302
static enum cdc_stat cdc_map_insert(struct cdc_map *m, void *key, void *value, struct cdc_map_iter *it, bool *inserted)
Inserts an element into the container, if the container doesn't already contain an element with an eq...
Definition: map.h:250
void(* prev)(void *it)
Definition: imap.h:46
The cdc_map_iter is service struct.
Definition: map.h:61
void cdc_map_dtor(struct cdc_map *m)
Destroys the map.
bool(* empty)(void *cntr)
Definition: imap.h:68
static enum cdc_stat cdc_map_get(struct cdc_map *m, void *key, void **value)
Returns a value that is mapped to a key. If the key does not exist, then NULL will return...
Definition: map.h:151
void *(* key)(void *it)
Definition: imap.h:49
static enum cdc_stat cdc_map_insert_or_assign(struct cdc_map *m, void *key, void *value, struct cdc_map_iter *it, bool *inserted)
Inserts an element or assigns to the current element if the key already exists.
Definition: map.h:273
static enum cdc_iterator_type cdc_map_iter_type(struct cdc_map_iter *it)
Returns a type of iterator.
Definition: map.h:392
enum cdc_iterator_type(* type)()
Definition: imap.h:44
size_t(* size)(void *cntr)
Definition: imap.h:67
struct cdc_pair(* key_value)(void *it)
Definition: imap.h:51
size_t(* erase)(void *cntr, void *key)
Definition: imap.h:74
static size_t cdc_map_size(struct cdc_map *m)
Returns the number of items in the map.
Definition: map.h:201
The cdc_data_info struct used to initialize contaners.
Definition: common.h:71
void(* clear)(void *cntr)
Definition: imap.h:69
static void cdc_map_begin(struct cdc_map *m, struct cdc_map_iter *it)
Initializes the iterator to the beginning.
Definition: map.h:322
static bool cdc_map_empty(struct cdc_map *m)
Checks if the map has no elements.
Definition: map.h:213