docs/Writerside/topics/map.h.md

branch
docs/3.1
changeset 1141
a06a2d27c043
child 1142
9437530176bc
equal deleted inserted replaced
1140:88a9ee79c102 1141:a06a2d27c043
1 # map.h
2
3 Similar to the list interface, the map interface provides a common API for implementing maps.
4 There are some minor subtle differences, though.
5
6 First, the `remove` method is not always a destructive removal.
7 Instead, the last argument is a Boolean that indicates whether the element shall be destroyed or returned.
8 ```c
9 void *(*remove)(CxMap *map, CxHashKey key, bool destroy);
10 ```
11 When you implement this method, you are either supposed to invoke the destructors and return `NULL`,
12 or just remove the element from the map and return it.
13
14 Secondly, the iterator method is a bit more complete. The signature is as follows:
15 ```c
16 CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
17 ```
18 There are three map iterator types: for values, for keys, for pairs.
19 Depending on the iterator type requested, you need to create an iterator with the correct methods that
20 return the requested thing.
21 There are no automatic checks to enforce this - it's completely up to you.
22 If you need inspiration on how to do that, check the hash map implementation that comes with UCX.

mercurial