85 * Add or overwrite an element. |
86 * Add or overwrite an element. |
86 */ |
87 */ |
87 __attribute__((__nonnull__)) |
88 __attribute__((__nonnull__)) |
88 int (*put)( |
89 int (*put)( |
89 CxMap *map, |
90 CxMap *map, |
90 CxDataPtr key, |
91 CxHashKey key, |
91 void *value |
92 void *value |
92 ); |
93 ); |
93 |
94 |
94 /** |
95 /** |
95 * Returns an element. |
96 * Returns an element. |
96 */ |
97 */ |
97 __attribute__((__nonnull__, __warn_unused_result__)) |
98 __attribute__((__nonnull__, __warn_unused_result__)) |
98 void *(*get)( |
99 void *(*get)( |
99 CxMap const *map, |
100 CxMap const *map, |
100 CxDataPtr key |
101 CxHashKey key |
101 ); |
102 ); |
102 |
103 |
103 /** |
104 /** |
104 * Removes an element. |
105 * Removes an element. |
105 */ |
106 */ |
106 __attribute__((__nonnull__, __warn_unused_result__)) |
107 __attribute__((__nonnull__, __warn_unused_result__)) |
107 void *(*remove)( |
108 void *(*remove)( |
108 CxMap *map, |
109 CxMap *map, |
109 CxDataPtr key |
110 CxHashKey key |
110 ); |
111 ); |
111 |
112 |
112 /** |
113 /** |
113 * Iterator over the key/value pairs. |
114 * Iterator over the key/value pairs. |
114 */ |
115 */ |
174 * @return 0 on success, non-zero value on failure |
175 * @return 0 on success, non-zero value on failure |
175 */ |
176 */ |
176 __attribute__((__nonnull__)) |
177 __attribute__((__nonnull__)) |
177 static inline int cxMapPut( |
178 static inline int cxMapPut( |
178 CxMap *map, |
179 CxMap *map, |
179 CxDataPtr key, |
180 CxHashKey key, |
180 void *value |
181 void *value |
181 ) { |
182 ) { |
182 return map->cl->put(map, key, value); |
183 return map->cl->put(map, key, value); |
183 } |
184 } |
184 |
185 |
205 * @return the removed value |
206 * @return the removed value |
206 */ |
207 */ |
207 __attribute__((__nonnull__, __warn_unused_result__)) |
208 __attribute__((__nonnull__, __warn_unused_result__)) |
208 static inline void *cxMapRemove( |
209 static inline void *cxMapRemove( |
209 CxMap *map, |
210 CxMap *map, |
210 CxDataPtr key |
211 CxHashKey key |
211 ) { |
212 ) { |
212 return map->cl->remove(map, key); |
213 return map->cl->remove(map, key); |
213 } |
214 } |
214 |
215 |
215 // TODO: set-like map operations (union, intersect, difference) |
216 // TODO: set-like map operations (union, intersect, difference) |
260 __attribute__((__nonnull__, __warn_unused_result__)) |
261 __attribute__((__nonnull__, __warn_unused_result__)) |
261 static inline CxIterator cxMapIterator(CxMap *map) { |
262 static inline CxIterator cxMapIterator(CxMap *map) { |
262 return map->cl->iterator(map); |
263 return map->cl->iterator(map); |
263 } |
264 } |
264 |
265 |
265 /** |
|
266 * Convenience function to make a key from a NULL-terminated string. |
|
267 * |
|
268 * @param str the NULL-terminated string |
|
269 * @return the string wrapped to be used as a map key |
|
270 */ |
|
271 __attribute__((__nonnull__, __warn_unused_result__)) |
|
272 CxDataPtr cxMapKeyStr(char const *str); |
|
273 |
|
274 #ifdef __cplusplus |
266 #ifdef __cplusplus |
275 } |
267 } |
276 #endif |
268 #endif |
277 |
269 |
278 #endif // UCX_MAP_H |
270 #endif // UCX_MAP_H |