map: fix return value of map_delete
[vis.git] / map.h
blob078c9c66efe96b4ebbd517e1f97ddb0deb486e3e
1 #ifndef MAP_H
2 #define MAP_H
4 #include <stdbool.h>
6 typedef struct Map Map;
8 /* Allocate a new map. */
9 Map *map_new(void);
10 /* Retrieves a value, or NULL if it isn't in the map */
11 void *map_get(const Map*, const char *key);
12 /* Returns the corresponding value if the given prefix is unique.
13 * Otherwise NULL, if no such prefix exists then errno is set to ENOENT. */
14 void *map_closest(const Map*, const char *prefix);
15 /* check whether the map contains the given prefix, i.e. whether it can
16 * be extended to match a key of an element stored in the map. */
17 bool map_contains(const Map*, const char *prefix);
18 /* Place a member in the map. This returns false if we run out of memory
19 * (errno = ENOMEM), or if that key already appears in the map (errno = EEXIST). */
20 bool map_put(Map*, const char *key, const void *value);
21 /* Remove a member from the map. Returns the removed entry or NULL
22 * if there was no entry found using the given key*/
23 void *map_delete(Map*, const char *key);
24 /* Ordered iteration over a map, call handle for every entry. If handle
25 * returns false, the iteration will stop. */
26 void map_iterate(const Map*, bool (*handle)(const char *key, void *value, void *data), const void *data);
27 /* Return a submap matching a prefix. This returns a pointer into the
28 * original map, so don't alter the map while using the return value. */
29 const Map *map_prefix(const Map*, const char *prefix);
30 /* Test whether the map is empty i.e. contains no elements */
31 bool map_empty(const Map*);
32 /* Remove every member from the map. The map will be empty after this. */
33 void map_clear(Map*);
34 /* Release all memory associated with this map */
35 void map_free(Map*);
37 #endif