Wed, 12 Mar 2025 16:08:35 +0100
complete most of the map.h documentation
relates to #451
1143
0559812df10c
assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents:
1142
diff
changeset
|
1 | # Map Interface |
1141 | 2 | |
3 | Similar to the list interface, the map interface provides a common API for implementing maps. | |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
4 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
5 | UCX is shipped with a [hash map](hash_map.h.md) implementation of this interface. |
1141 | 6 | |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
7 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
8 | #include <cx/hash_map.h> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
9 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
10 | CxMap *cxHashMapCreate(const CxAllocator *allocator, |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
11 | size_t itemsize, size_t buckets); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
12 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
13 | CxMap *cxHashMapCreateSimple(size_t itemsize); |
1141 | 14 | ``` |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
15 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
16 | The function `cxHashMapCreate()` creates a new map where both the map structure |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
17 | and the contained buckets are allocated by the specified `allocator`. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
18 | The default stdlib allocator is used in `cxHashMapCreateSimple()`. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
19 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
20 | The map will store items of size `itemsize`. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
21 | You can use the `CX_STORE_POINTERS` macro for `itemsize` to indicate that the map shall store |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
22 | pointers instead of actual items. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
23 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
24 | If you pass zero for the number of `buckets`, or use `cxHashMapSimple()`, |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
25 | the map is initialized with a default of 16 buckets, otherwise the specified number of buckets is allocated. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
26 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
27 | > If you want to lazy-initialize maps, you can use the global `cxEmptyMap` symbol as a placeholder instead of using a `NULL`-pointer. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
28 | > While you *must not* insert elements into that map, you can safely access this map or create iterators. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
29 | > This allows you to write clean code without checking for `NULL`-pointer everywhere. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
30 | > You still need to make sure that the placeholder is replaced with an actual map before inserting elements. |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
31 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
32 | ## Overview |
1141 | 33 | |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
34 | <warning> |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
35 | TODO: example |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
36 | </warning> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
37 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
38 | > In the following Sections, the type for the key is denoted `KeyType`. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
39 | > All functions are implemented as generics, so that the following types are supported: |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
40 | > `CxHashKey`, `cxstring`, `cxmutstr`, `const char*`, and `char*`. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
41 | > {style="note"} |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
42 | |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
43 | ## Insert |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
44 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
45 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
46 | #include <cx/map.h> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
47 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
48 | int cxMapPut(CxMap *map, KeyType key, void *value); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
49 | ``` |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
50 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
51 | The function `cxMapPut()` stores the specified `key` / `value` pair. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
52 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
53 | The key is always copied. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
54 | The behavior for the value is dependent on whether the map is storing pointers. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
55 | If it is storing pointers, the `value` pointer is directly stored in the map. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
56 | Otherwise, the memory pointed to by `value` is copied, using the element size of the collection. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
57 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
58 | If an element is already associated with the specified key, it is replaced. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
59 | If [destructor functions](collection.h.md#destructor-functions) are registered, |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
60 | they are invoked for the old element before it is replaced. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
61 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
62 | This function returns zero if the element was successfully put into the map and non-zero otherwise. |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
63 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
64 | ## Access |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
65 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
66 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
67 | #include <cx/map.h> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
68 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
69 | void *cxMapGet(CxMap *map, KeyType key); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
70 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
71 | size_t cxMapSize(const CxMap *map); |
1141 | 72 | ``` |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
73 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
74 | With the function `cxMapGet()` you can retrieve a value stored under the specified `key`. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
75 | If there is no such value, this function returns `NULL`. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
76 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
77 | The function `cxMapSize()` returns how many key/value-pairs are currently stored in the map. |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
78 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
79 | ## Remove |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
80 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
81 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
82 | #include <cx/map.h> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
83 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
84 | int cxMapRemove(CxMap *map, KeyType key); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
85 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
86 | int cxMapRemoveAndGet(CxMap *map, KeyType key, void* targetbuf); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
87 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
88 | void cxMapClear(CxMap *map); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
89 | ``` |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
90 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
91 | The function `cxMapRemove()` retrieves and removes a value stored under the specified `key`. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
92 | If [destructor functions](collection.h.md#destructor-functions) are registered, they are called before removal. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
93 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
94 | On the other hand, `cxMapRemoveAndGet()` does not invoke the destructor functions, |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
95 | and instead copies the value into the `targetbuf` which must be sufficiently large to hold the value. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
96 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
97 | In either case, the functions return zero when an element was found under the specified key, and non-zero otherwise. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
98 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
99 | The function `cxMapClear()` removes all elements from the map, invoking the destructor functions for each of them. |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
100 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
101 | ## Iterators |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
102 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
103 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
104 | #include <cx/map.h> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
105 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
106 | CxMapIterator cxMapIterator(const CxMap *map); |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
107 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
108 | CxMapIterator cxMapIteratorKeys(const CxMap *map); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
109 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
110 | CxMapIterator cxMapIteratorValues(const CxMap *map); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
111 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
112 | CxMapIterator cxMapMutIterator(CxMap *map); |
1142
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
113 | |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
114 | CxMapIterator cxMapMutIteratorKeys(CxMap *map); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
115 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
116 | CxMapIterator cxMapMutIteratorValues(CxMap *map); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
117 | ``` |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
118 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
119 | The above functions create a ([mutating](iterator.h.md#mutating-iterators)) iterator over the |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
120 | pairs, keys, or values of the specified `map`, respectively. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
121 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
122 | Iterators over pairs yield elements of type `CxMapEntry*` which is a struct containing a pointer to the `key` and the value, respectively. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
123 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
124 | Iterators over keys yield elements of type `const CxHashKey*` (cf. [CxHashKey documentation](hash_key.h.md)). |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
125 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
126 | The behavior of iterators over values depends on the concrete implementation. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
127 | Implementations are encouraged to support `CX_STORE_POINTERS`. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
128 | If used, the `void*` elements the iterator yields, shall be directly the stored pointers. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
129 | Otherwise, the iterator shall yield pointers to the map's memory where the value is stored. |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
130 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
131 | ## Dispose |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
132 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
133 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
134 | #include <cx/map.h> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
135 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
136 | void cxMapFree(CxMap *map); |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
137 | ``` |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
138 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
139 | The function `cxMapFree()` invokes the [destructor functions](collection.h.md#destructor-functions) for all elements, |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
140 | and then deallocates the entire memory for the map. |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
141 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
142 | ## Implement own Map Structures |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
143 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
144 | ```C |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
145 | typedef struct cx_map_entry_s { |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
146 | const CxHashKey *key; |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
147 | void *value; |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
148 | } CxMapEntry; |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
149 | ``` |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
150 | |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
151 | <warning> |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
152 | TODO: example |
1243
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
153 | </warning> |
13e15cd529ae
structur for map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
154 | |
1244
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
155 | The required behavior for the implementations is described in the following table. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
156 | You can always look at the source code of the UCX hash map to get inspiration. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
157 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
158 | | Function | Description | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
159 | |--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
160 | | `clear` | Invoke [destructor functions](collection.h.md#destructor-functions) on all elements and remove them from the map. | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
161 | | `deallocate` | Invoke destructor functions on all elements and deallocate the entire map memory. | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
162 | | `put` | Store an element in the map. If an element is already stored, invoke the destructor functions on that element and replace it with the new element. Return non-zero when allocating memory fails. | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
163 | | `get` | Look up the specified key and return the associated value (or `NULL` if the key was not found). | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
164 | | `remove` | Remove an element from the map. If a target buffer is specified, copy the elements to that buffer. Otherwise, invoke the destructor functions for the element. If the key was not found in the map, return non-zero. | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
165 | | `iterator` | Return an iterator over the pairs, the keys, or the values, depending on the iterator type passed with the last argument. | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
166 | |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
167 | > In contrast to the list interface, there is no `cx_map_init()` function which automatically |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
168 | > configures a wrapping mechanism when `CX_STORE_POINTERS` is used. |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
169 | > That means, in the implementation of the above functions you must take care of distinguishing between |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
170 | > maps that are storing pointers and that are storing elements yourself (if you want to support both). |
9a8e781258ac
complete most of the map.h documentation
Mike Becker <universe@uap-core.de>
parents:
1243
diff
changeset
|
171 | >{style="note"} |
1190
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
172 | |
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
173 | <seealso> |
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
174 | <category ref="apidoc"> |
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
175 | <a href="https://ucx.sourceforge.io/api/map_8h.html">map.h</a> |
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
176 | </category> |
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
177 | </seealso> |
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
178 |