390 return map->
cl->
put(map, key, value);
427 return map->
cl->
get(map, key);
463 return map->
cl->
remove(map, key,
nullptr);
498 return map->cl->remove(map, key, targetbuf);
543 return map->
cl->
put(map, key, value);
602#define cxMapPut(map, key, value) _Generic((key), \
603 CxHashKey: cx_map_put, \
604 cxstring: cx_map_put_cxstr, \
605 cxmutstr: cx_map_put_mustr, \
606 char*: cx_map_put_str, \
607 const char*: cx_map_put_str) \
619 return map->
cl->
get(map, key);
670#define cxMapGet(map, key) _Generic((key), \
671 CxHashKey: cx_map_get, \
672 cxstring: cx_map_get_cxstr, \
673 cxmutstr: cx_map_get_mustr, \
674 char*: cx_map_get_str, \
675 const char*: cx_map_get_str) \
686 return map->
cl->
remove(map, key, NULL);
735#define cxMapRemove(map, key) _Generic((key), \
736 CxHashKey: cx_map_remove, \
737 cxstring: cx_map_remove_cxstr, \
738 cxmutstr: cx_map_remove_mustr, \
739 char*: cx_map_remove_str, \
740 const char*: cx_map_remove_str) \
753 return map->cl->remove(map, key, targetbuf);
815#define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \
816 CxHashKey: cx_map_remove_and_get, \
817 cxstring: cx_map_remove_and_get_cxstr, \
818 cxmutstr: cx_map_remove_and_get_mustr, \
819 char*: cx_map_remove_and_get_str, \
820 const char*: cx_map_remove_and_get_str) \
821 (map, key, targetbuf)
Common definitions for various collection implementations.
#define CX_COLLECTION_BASE
Use this macro to declare common members for a collection structure.
Definition collection.h:113
Common definitions and feature checks.
#define cx_attr_export
Only used for building Windows DLLs.
Definition common.h:285
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_access_w(...)
Specifies that the function will only write through the given pointer.
Definition common.h:241
#define cx_attr_cstr_arg(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:206
Interface for map implementations.
CxHashKey cx_hash_key_str(const char *str)
Computes a hash key from a string.
#define cx_hash_key_cxstr(str)
Computes a hash key from a UCX string.
Definition hash_key.h:146
#define CX_ITERATOR_BASE
Declares base attributes for an iterator.
Definition iterator.h:92
CxMapIterator cxMapMutIterator(CxMap *map)
Creates a mutating iterator for a map.
static void * cx_map_get(const CxMap *map, CxHashKey key)
Retrieves a value by using a key.
Definition map.h:615
#define cxMapRemoveAndGet(map, key, targetbuf)
Removes a key/value-pair from the map by using the key.
Definition map.h:815
static CxMapIterator cxMapIteratorValues(const CxMap *map)
Creates a value iterator for a map.
Definition map.h:285
static size_t cxMapSize(const CxMap *map)
Returns the number of elements in this map.
Definition map.h:266
static int cx_map_put(CxMap *map, CxHashKey key, void *value)
Puts a key/value-pair into the map.
Definition map.h:538
static int cx_map_remove_and_get_mustr(CxMap *map, cxmutstr key, void *targetbuf)
Removes a key/value-pair from the map by using the key.
Definition map.h:774
static int cx_map_put_cxstr(CxMap *map, cxstring key, void *value)
Puts a key/value-pair into the map.
Definition map.h:550
CxMapIterator cxMapMutIteratorKeys(CxMap *map)
Creates a mutating iterator over the keys of a map.
static int cx_map_remove_and_get(CxMap *map, CxHashKey key, void *targetbuf)
Removes a key/value-pair from the map by using the key.
Definition map.h:748
cx_map_iterator_type
The type of iterator for a map.
Definition map.h:87
@ CX_MAP_ITERATOR_KEYS
Iterates over keys only.
Definition map.h:95
@ CX_MAP_ITERATOR_PAIRS
Iterates over key/value pairs.
Definition map.h:91
@ CX_MAP_ITERATOR_VALUES
Iterates over values only.
Definition map.h:99
CxMapIterator cxMapMutIteratorValues(CxMap *map)
Creates a mutating iterator over the values of a map.
#define cxMapRemove(map, key)
Removes a key/value-pair from the map by using the key.
Definition map.h:735
static int cx_map_remove_str(CxMap *map, const char *key)
Removes a key/value-pair from the map by using the key.
Definition map.h:716
static int cx_map_remove(CxMap *map, CxHashKey key)
Removes a key/value-pair from the map by using the key.
Definition map.h:682
static void cxMapClear(CxMap *map)
Clears a map by removing all elements.
Definition map.h:255
struct cx_map_iterator_s CxMapIterator
Type for a map iterator.
Definition map.h:55
static CxMapIterator cxMapIteratorKeys(const CxMap *map)
Creates a key iterator for a map.
Definition map.h:303
static int cx_map_remove_and_get_cxstr(CxMap *map, cxstring key, void *targetbuf)
Removes a key/value-pair from the map by using the key.
Definition map.h:761
static int cx_map_remove_cxstr(CxMap *map, cxstring key)
Removes a key/value-pair from the map by using the key.
Definition map.h:693
static int cx_map_remove_and_get_str(CxMap *map, const char *key, void *targetbuf)
Removes a key/value-pair from the map by using the key.
Definition map.h:788
void cxMapFree(CxMap *map)
Deallocates the memory of the specified map.
static void * cx_map_get_cxstr(const CxMap *map, cxstring key)
Retrieves a value by using a key.
Definition map.h:627
static void * cx_map_get_str(const CxMap *map, const char *key)
Retrieves a value by using a key.
Definition map.h:652
static int cx_map_put_str(CxMap *map, const char *key, void *value)
Puts a key/value-pair into the map.
Definition map.h:575
#define cxMapPut(map, key, value)
Puts a key/value-pair into the map.
Definition map.h:602
static int cx_map_remove_mustr(CxMap *map, cxmutstr key)
Removes a key/value-pair from the map by using the key.
Definition map.h:704
CxMap *const cxEmptyMap
A shared instance of an empty map.
static CxMapIterator cxMapIterator(const CxMap *map)
Creates an iterator for a map.
Definition map.h:323
static void * cx_map_get_mustr(const CxMap *map, cxmutstr key)
Retrieves a value by using a key.
Definition map.h:639
#define cxMapGet(map, key)
Retrieves a value by using a key.
Definition map.h:670
static int cx_map_put_mustr(CxMap *map, cxmutstr key, void *value)
Puts a key/value-pair into the map.
Definition map.h:562
Strings that know their length.
size_t size
The number of currently stored elements.
Definition collection.h:71
Internal structure for a key within a hash map.
Definition hash_key.h:48
The class definition for arbitrary maps.
Definition map.h:175
int(* put)(CxMap *map, CxHashKey key, void *value)
Add or overwrite an element.
Definition map.h:189
void(* deallocate)(struct cx_map_s *map)
Deallocates the entire memory.
Definition map.h:179
int(* remove)(CxMap *map, CxHashKey key, void *targetbuf)
Removes an element.
Definition map.h:213
void(* clear)(struct cx_map_s *map)
Removes all elements.
Definition map.h:184
CxMapIterator(* iterator)(const CxMap *map, enum cx_map_iterator_type type)
Creates an iterator for this map.
Definition map.h:222
void *(* get)(const CxMap *map, CxHashKey key)
Returns an element.
Definition map.h:198
A map entry.
Definition map.h:73
const CxHashKey * key
A pointer to the key.
Definition map.h:77
void * value
A pointer to the value.
Definition map.h:81
Internal iterator struct - use CxMapIterator.
Definition map.h:105
size_t slot
Field for storing the current slot number.
Definition map.h:145
CxMapEntry entry
Reserved memory for a map entry.
Definition map.h:138
size_t index
Counts the elements successfully.
Definition map.h:151
size_t elem_count
May contain the total number of elements, if known.
Definition map.h:164
union cx_map_iterator_s::@4 map
Handle for the source map.
CxMap * m
Access for mutating iterators.
Definition map.h:118
void * elem
Handle for the current element.
Definition map.h:130
size_t elem_size
The size of a value stored in this map.
Definition map.h:156
enum cx_map_iterator_type type
The type of this iterator.
Definition map.h:169
const CxMap * c
Access for normal iterators.
Definition map.h:122
Structure for the UCX map.
Definition map.h:61
struct cx_collection_s collection
Base attributes.
Definition map.h:65
cx_map_class * cl
The map class definition.
Definition map.h:67
The UCX string structure.
Definition string.h:51
The UCX string structure for immutable (constant) strings.
Definition string.h:69