167 map->store_pointer =
false;
184 map->store_pointer =
true;
185 map->item_size =
sizeof(
void *);
196 map->cl->destructor(map);
321 return map->
cl->
put(map, key, value);
388 return map->
cl->
get(map, key);
455 (void) map->
cl->
remove(map, key,
true);
543 (void) map->
cl->
remove(map, key,
false);
636 return map->
cl->
remove(map, key, !map->store_pointer);
736 return map->cl->put(map, key, value);
798#define cxMapPut(map, key, value) _Generic((key), \
799 CxHashKey: cx_map_put, \
800 cxstring: cx_map_put_cxstr, \
801 cxmutstr: cx_map_put_mustr, \
802 char*: cx_map_put_str, \
803 char const*: cx_map_put_str) \
818 return map->cl->get(map, key);
873#define cxMapGet(map, key) _Generic((key), \
874 CxHashKey: cx_map_get, \
875 cxstring: cx_map_get_cxstr, \
876 cxmutstr: cx_map_get_mustr, \
877 char*: cx_map_get_str, \
878 char const*: cx_map_get_str) \
892 (void) map->cl->remove(map, key,
true);
951#define cxMapRemove(map, key) _Generic((key), \
952 CxHashKey: cx_map_remove, \
953 cxstring: cx_map_remove_cxstr, \
954 cxmutstr: cx_map_remove_mustr, \
955 char*: cx_map_remove_str, \
956 char const*: cx_map_remove_str) \
971 (void) map->cl->remove(map, key,
false);
1033#define cxMapDetach(map, key) _Generic((key), \
1034 CxHashKey: cx_map_detach, \
1035 cxstring: cx_map_detach_cxstr, \
1036 cxmutstr: cx_map_detach_mustr, \
1037 char*: cx_map_detach_str, \
1038 char const*: cx_map_detach_str) \
1054 return map->cl->remove(map, key, !map->store_pointer);
1102 return map->cl->remove(map,
cx_hash_key_str(key), !map->store_pointer);
1124#define cxMapRemoveAndGet(map, key) _Generic((key), \
1125 CxHashKey: cx_map_remove_and_get, \
1126 cxstring: cx_map_remove_and_get_cxstr, \
1127 cxmutstr: cx_map_remove_and_get_mustr, \
1128 char*: cx_map_remove_and_get_str, \
1129 char const*: cx_map_remove_and_get_str) \
Common definitions for various collection implementations.
#define CX_COLLECTION_MEMBERS
Use this macro to declare common members for a collection structure.
Definition: collection.h:63
Common definitions and feature checks.
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition: common.h:127
Interface for map implementations.
CxHashKey cx_hash_key_str(char const *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:123
CxMutIterator cxMapMutIterator(CxMap *map)
Creates a mutating iterator for a map.
static int cx_map_put(CxMap *map, CxHashKey key, void *value)
Puts a key/value-pair into the map.
Definition: map.h:731
static void * cx_map_remove_and_get_str(CxMap *map, char const *key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:1098
#define cxMapRemoveAndGet(map, key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:1124
static int cx_map_put_cxstr(CxMap *map, cxstring key, void *value)
Puts a key/value-pair into the map.
Definition: map.h:748
static CxIterator cxMapIteratorValues(CxMap const *map)
Creates a value iterator for a map.
Definition: map.h:223
cx_map_iterator_type
The type of iterator for a map.
Definition: map.h:68
@ CX_MAP_ITERATOR_KEYS
Iterates over keys only.
Definition: map.h:76
@ CX_MAP_ITERATOR_PAIRS
Iterates over key/value pairs.
Definition: map.h:72
@ CX_MAP_ITERATOR_VALUES
Iterates over values only.
Definition: map.h:80
static CxIterator cxMapIteratorKeys(CxMap const *map)
Creates a key iterator for a map.
Definition: map.h:239
#define cxMapRemove(map, key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:951
static CxIterator cxMapIterator(CxMap const *map)
Creates an iterator for a map.
Definition: map.h:257
static void * cx_map_remove_and_get_cxstr(CxMap *map, cxstring key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:1066
CxMutIterator cxMapMutIteratorKeys(CxMap *map)
Creates a mutating iterator over the keys of a map.
static void * cx_map_get_mustr(CxMap const *map, cxmutstr key)
Retrieves a value by using a key.
Definition: map.h:844
static void cxMapStorePointers(CxMap *map)
Advises the map to only store pointers to the objects.
Definition: map.h:183
static void cx_map_detach_mustr(CxMap *map, cxmutstr key)
Detaches a key/value-pair from the map by using the key without invoking the destructor.
Definition: map.h:997
CxMutIterator cxMapMutIteratorValues(CxMap *map)
Creates a mutating iterator over the values of a map.
static void cxMapClear(CxMap *map)
Clears a map by removing all elements.
Definition: map.h:206
static void * cx_map_get(CxMap const *map, CxHashKey key)
Retrieves a value by using a key.
Definition: map.h:814
static void cx_map_detach_cxstr(CxMap *map, cxstring key)
Detaches a key/value-pair from the map by using the key without invoking the destructor.
Definition: map.h:982
static void * cx_map_remove_and_get_mustr(CxMap *map, cxmutstr key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:1082
static void cxMapDestroy(CxMap *map)
Deallocates the memory of the specified map.
Definition: map.h:195
static void cx_map_remove_cxstr(CxMap *map, cxstring key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:902
#define cxMapDetach(map, key)
Detaches a key/value-pair from the map by using the key without invoking the destructor.
Definition: map.h:1033
static void cx_map_remove(CxMap *map, CxHashKey key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:888
static void * cx_map_remove_and_get(CxMap *map, CxHashKey key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:1050
static void cx_map_detach_str(CxMap *map, char const *key)
Detaches a key/value-pair from the map by using the key without invoking the destructor.
Definition: map.h:1012
static void cx_map_remove_mustr(CxMap *map, cxmutstr key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:916
static void * cx_map_get_cxstr(CxMap const *map, cxstring key)
Retrieves a value by using a key.
Definition: map.h:829
#define cxMapPut(map, key, value)
Puts a key/value-pair into the map.
Definition: map.h:798
static void cx_map_detach(CxMap *map, CxHashKey key)
Detaches a key/value-pair from the map by using the key without invoking the destructor.
Definition: map.h:967
static int cx_map_put_str(CxMap *map, char const *key, void *value)
Puts a key/value-pair into the map.
Definition: map.h:782
CxMap *const cxEmptyMap
A shared instance of an empty map.
static void * cx_map_get_str(CxMap const *map, char const *key)
Retrieves a value by using a key.
Definition: map.h:859
static void cxMapStoreObjects(CxMap *map)
Advises the map to store copies of the objects (default mode of operation).
Definition: map.h:166
static void cx_map_remove_str(CxMap *map, char const *key)
Removes a key/value-pair from the map by using the key.
Definition: map.h:930
#define cxMapGet(map, key)
Retrieves a value by using a key.
Definition: map.h:873
static int cx_map_put_mustr(CxMap *map, cxmutstr key, void *value)
Puts a key/value-pair into the map.
Definition: map.h:765
Strings that know their length.
Internal structure for a key within a hash map.
Definition: hash_key.h:48
Internal iterator struct - use CxIterator.
Definition: iterator.h:160
The class definition for arbitrary maps.
Definition: map.h:86
void *(* get)(CxMap const *map, CxHashKey key)
Returns an element.
Definition: map.h:113
int(* put)(CxMap *map, CxHashKey key, void *value)
Add or overwrite an element.
Definition: map.h:103
void(* clear)(struct cx_map_s *map)
Removes all elements.
Definition: map.h:97
void *(* remove)(CxMap *map, CxHashKey key, bool destroy)
Removes an element.
Definition: map.h:122
void(* destructor)(struct cx_map_s *map)
Deallocates the entire memory.
Definition: map.h:91
CxIterator(* iterator)(CxMap const *map, enum cx_map_iterator_type type)
Creates an iterator for this map.
Definition: map.h:132
A map entry.
Definition: map.h:138
CxHashKey const * key
A pointer to the key.
Definition: map.h:142
void * value
A pointer to the value.
Definition: map.h:146
Structure for the UCX map.
Definition: map.h:59
CX_COLLECTION_MEMBERS cx_map_class * cl
The map class definition.
Definition: map.h:62
Internal iterator struct - use CxMutIterator.
Definition: iterator.h:96
The UCX string structure.
Definition: string.h:46
The UCX string structure for immutable (constant) strings.
Definition: string.h:65