164 * @param map the map |
164 * @param map the map |
165 * @see cxMapStorePointers() |
165 * @see cxMapStorePointers() |
166 */ |
166 */ |
167 __attribute__((__nonnull__)) |
167 __attribute__((__nonnull__)) |
168 static inline void cxMapStoreObjects(CxMap *map) { |
168 static inline void cxMapStoreObjects(CxMap *map) { |
169 map->base.store_pointer = false; |
169 map->collection.store_pointer = false; |
170 } |
170 } |
171 |
171 |
172 /** |
172 /** |
173 * Advises the map to only store pointers to the objects. |
173 * Advises the map to only store pointers to the objects. |
174 * |
174 * |
181 * @param map the map |
181 * @param map the map |
182 * @see cxMapStoreObjects() |
182 * @see cxMapStoreObjects() |
183 */ |
183 */ |
184 __attribute__((__nonnull__)) |
184 __attribute__((__nonnull__)) |
185 static inline void cxMapStorePointers(CxMap *map) { |
185 static inline void cxMapStorePointers(CxMap *map) { |
186 map->base.store_pointer = true; |
186 map->collection.store_pointer = true; |
187 map->base.elem_size = sizeof(void *); |
187 map->collection.elem_size = sizeof(void *); |
188 } |
188 } |
189 |
189 |
190 |
190 |
191 /** |
191 /** |
192 * Deallocates the memory of the specified map. |
192 * Deallocates the memory of the specified map. |
205 * @param map the map to be cleared |
205 * @param map the map to be cleared |
206 */ |
206 */ |
207 __attribute__((__nonnull__)) |
207 __attribute__((__nonnull__)) |
208 static inline void cxMapClear(CxMap *map) { |
208 static inline void cxMapClear(CxMap *map) { |
209 map->cl->clear(map); |
209 map->cl->clear(map); |
|
210 } |
|
211 |
|
212 /** |
|
213 * Returns the number of elements in this map. |
|
214 * |
|
215 * @param map the map |
|
216 * @return the number of stored elements |
|
217 */ |
|
218 __attribute__((__nonnull__)) |
|
219 static inline size_t cxMapSize(CxMap const *map) { |
|
220 return map->collection.size; |
210 } |
221 } |
211 |
222 |
212 |
223 |
213 // TODO: set-like map operations (union, intersect, difference) |
224 // TODO: set-like map operations (union, intersect, difference) |
214 |
225 |
1051 __attribute__((__nonnull__, __warn_unused_result__)) |
1062 __attribute__((__nonnull__, __warn_unused_result__)) |
1052 static inline void *cx_map_remove_and_get( |
1063 static inline void *cx_map_remove_and_get( |
1053 CxMap *map, |
1064 CxMap *map, |
1054 CxHashKey key |
1065 CxHashKey key |
1055 ) { |
1066 ) { |
1056 return map->cl->remove(map, key, !map->base.store_pointer); |
1067 return map->cl->remove(map, key, !map->collection.store_pointer); |
1057 } |
1068 } |
1058 |
1069 |
1059 /** |
1070 /** |
1060 * Removes a key/value-pair from the map by using the key. |
1071 * Removes a key/value-pair from the map by using the key. |
1061 * |
1072 * |
1067 __attribute__((__nonnull__, __warn_unused_result__)) |
1078 __attribute__((__nonnull__, __warn_unused_result__)) |
1068 static inline void *cx_map_remove_and_get_cxstr( |
1079 static inline void *cx_map_remove_and_get_cxstr( |
1069 CxMap *map, |
1080 CxMap *map, |
1070 cxstring key |
1081 cxstring key |
1071 ) { |
1082 ) { |
1072 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->base.store_pointer); |
1083 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); |
1073 } |
1084 } |
1074 |
1085 |
1075 /** |
1086 /** |
1076 * Removes a key/value-pair from the map by using the key. |
1087 * Removes a key/value-pair from the map by using the key. |
1077 * |
1088 * |
1083 __attribute__((__nonnull__, __warn_unused_result__)) |
1094 __attribute__((__nonnull__, __warn_unused_result__)) |
1084 static inline void *cx_map_remove_and_get_mustr( |
1095 static inline void *cx_map_remove_and_get_mustr( |
1085 CxMap *map, |
1096 CxMap *map, |
1086 cxmutstr key |
1097 cxmutstr key |
1087 ) { |
1098 ) { |
1088 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->base.store_pointer); |
1099 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); |
1089 } |
1100 } |
1090 |
1101 |
1091 /** |
1102 /** |
1092 * Removes a key/value-pair from the map by using the key. |
1103 * Removes a key/value-pair from the map by using the key. |
1093 * |
1104 * |
1099 __attribute__((__nonnull__, __warn_unused_result__)) |
1110 __attribute__((__nonnull__, __warn_unused_result__)) |
1100 static inline void *cx_map_remove_and_get_str( |
1111 static inline void *cx_map_remove_and_get_str( |
1101 CxMap *map, |
1112 CxMap *map, |
1102 char const *key |
1113 char const *key |
1103 ) { |
1114 ) { |
1104 return map->cl->remove(map, cx_hash_key_str(key), !map->base.store_pointer); |
1115 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer); |
1105 } |
1116 } |
1106 |
1117 |
1107 /** |
1118 /** |
1108 * Removes a key/value-pair from the map by using the key. |
1119 * Removes a key/value-pair from the map by using the key. |
1109 * |
1120 * |