diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-09-13 17:35:30 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-09-13 17:35:30 +0200 |
| commit | 4cb296f155191a0de0d0a67995813526b6a4287b (patch) | |
| tree | a956ca952f4e9ba7a2b3eb80a8a57f0647f3ff25 | |
| parent | 0a52f918d01a298236a2edf7a005548edf34a8fb (diff) | |
| download | vis-4cb296f155191a0de0d0a67995813526b6a4287b.tar.gz vis-4cb296f155191a0de0d0a67995813526b6a4287b.tar.xz | |
map: introduce map_contains utility function
| -rw-r--r-- | map.c | 5 | ||||
| -rw-r--r-- | map.h | 3 |
2 files changed, 8 insertions, 0 deletions
@@ -73,6 +73,11 @@ void *map_closest(const Map *map, const char *prefix) return m->v; } +bool map_contains(const Map *map, const char *prefix) +{ + return !map_empty(map_prefix(map, prefix)); +} + bool map_put(Map *map, const char *k, const void *value) { size_t len = strlen(k); @@ -12,6 +12,9 @@ void *map_get(const Map*, const char *key); /* Returns the corresponding value if the given prefix is unique. * Otherwise NULL, if no such prefix exists then errno is set to ENOENT. */ void *map_closest(const Map*, const char *prefix); +/* check whether the map contains the given prefix, i.e. whether it can + * be extended to match a key of an element stored in the map. */ +bool map_contains(const Map*, const char *prefix); /* Place a member in the map. This returns false if we run out of memory * (errno = ENOMEM), or if that key already appears in the map (errno = EEXIST). */ bool map_put(Map*, const char *key, const void *value); |
