aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-29 01:34:58 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-29 01:34:58 +0100
commit8eeb6f5836ee772e3cdc8967d20444d84261373e (patch)
treef7698ee243bcf995d1ced178e2c5591214b8cc1b /map.c
parent305337f6b968c36ed948b2eee6738f5ee42fc824 (diff)
downloadvis-8eeb6f5836ee772e3cdc8967d20444d84261373e.tar.gz
vis-8eeb6f5836ee772e3cdc8967d20444d84261373e.tar.xz
map: implement map_first
Diffstat (limited to 'map.c')
-rw-r--r--map.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/map.c b/map.c
index 10d39de..f6e5c64 100644
--- a/map.c
+++ b/map.c
@@ -232,6 +232,28 @@ void map_iterate(const Map *map, bool (*handle)(const char *, void *, void *), c
iterate(*map, handle, data);
}
+typedef struct {
+ const char *key;
+ void *value;
+} KeyValue;
+
+static bool first(const char *key, void *value, void *data)
+{
+ KeyValue *kv = data;
+ kv->key = key;
+ kv->value = value;
+ return false;
+}
+
+void *map_first(const Map *map, const char **key)
+{
+ KeyValue kv = { 0 };
+ map_iterate(map, first, &kv);
+ if (key && kv.key)
+ *key = kv.key;
+ return kv.value;
+}
+
const Map *map_prefix(const Map *map, const char *prefix)
{
const Map *n, *top;