354 ``` |
354 ``` |
355 |
355 |
356 The required behavior for the implementations is described in the following table. |
356 The required behavior for the implementations is described in the following table. |
357 You can always look at the source code of the UCX hash map to get inspiration. |
357 You can always look at the source code of the UCX hash map to get inspiration. |
358 |
358 |
359 | Function | Description | |
359 | Function | Description | |
360 |--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
360 |--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
361 | `clear` | Invoke [destructor functions](collection.h.md#destructor-functions) on all elements and remove them from the map. | |
361 | `clear` | Invoke [destructor functions](collection.h.md#destructor-functions) on all elements and remove them from the map. | |
362 | `deallocate` | Invoke destructor functions on all elements and deallocate the entire map memory. | |
362 | `deallocate` | Invoke destructor functions on all elements and deallocate the entire map memory. | |
363 | `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. | |
363 | `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. When the value pointer is `NULL`, only allocate memory without copying an existing value. Return a pointer to the allocated memory, or `NULL` when allocation fails. | |
364 | `get` | Look up the specified key and return the associated value (or `NULL` if the key was not found). | |
364 | `get` | Look up the specified key and return the associated value (or `NULL` if the key was not found). | |
365 | `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. | |
365 | `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. | |
366 | `iterator` | Return an iterator over the pairs, the keys, or the values, depending on the iterator type passed with the last argument. | |
366 | `iterator` | Return an iterator over the pairs, the keys, or the values, depending on the iterator type passed with the last argument. | |
367 |
367 |
368 > In contrast to the list interface, there is no `cx_map_init()` function which automatically |
368 > In contrast to the list interface, there is no `cx_map_init()` function which automatically |
369 > configures a wrapping mechanism when `CX_STORE_POINTERS` is used. |
369 > configures a wrapping mechanism when `CX_STORE_POINTERS` is used. |
370 > That means, in the implementation of the above functions you must take care of distinguishing between |
370 > That means, in the implementation of the above functions you must take care of distinguishing between |
371 > maps that are storing pointers and that are storing elements yourself (if you want to support both). |
371 > maps that are storing pointers and that are storing elements yourself (if you want to support both). |