305 |
305 |
306 ## Map |
306 ## Map |
307 |
307 |
308 *Header file:* [map.h](api/map_8h.html) |
308 *Header file:* [map.h](api/map_8h.html) |
309 |
309 |
|
310 Similar to the list interface, the map interface provides a common API for implementing maps. |
|
311 There are some minor subtle differences, though. |
|
312 |
|
313 First, the `remove` method is not always a destructive removal. |
|
314 Instead, the last argument is a Boolean that indicates whether the element shall be destroyed or returned. |
|
315 ```c |
|
316 void *(*remove)(CxMap *map, CxHashKey key, bool destroy); |
|
317 ``` |
|
318 When you implement this method, you are either supposed to invoke the destructors and return `NULL`, |
|
319 or just remove the element from the map and return it. |
|
320 |
|
321 Secondly, the iterator method is a bit more complete. The signature is as follows: |
|
322 ```c |
|
323 CxIterator (*iterator)(CxMap const *map, enum cx_map_iterator_type type); |
|
324 ``` |
|
325 There are three map iterator types: for values, for keys, for pairs. |
|
326 Depending on the iterator type requested, you need to create an iterator with the correct methods that |
|
327 return the requested thing. |
|
328 There are no automatic checks to enforce this - it's completely up to you. |
|
329 If you need inspiration on how to do that, check the hash map implementation that comes with UCX. |
|
330 |
310 ### Hash Map |
331 ### Hash Map |
311 |
332 |
312 *Header file:* [hash_map.h](api/hash__map_8h.html) |
333 *Header file:* [hash_map.h](api/hash__map_8h.html) |
|
334 |
|
335 UCX provides a basic hash map implementation with a configurable amount of buckets. |
|
336 If you do not specify the number of buckets, a default of 16 buckets will be used. |
|
337 You can always rehash the map with `cxMapRehash()` to change the number of buckets to something more efficient, |
|
338 but you need to be careful, because when you use this function you are effectively locking into using this |
|
339 specific hash map implementation, and you would need to remove all calls to this function when you want to |
|
340 exchange the concrete map implementation with something different. |
313 |
341 |
314 ## Utilities |
342 ## Utilities |
315 |
343 |
316 *Header file:* [utils.h](api/utils_8h.html) |
344 *Header file:* [utils.h](api/utils_8h.html) |
317 |
345 |