]> git.ozlabs.org Git - ccan/blobdiff - ccan/intmap/intmap.c
intmap: implement uintmap_last/sintmap_last.
[ccan] / ccan / intmap / intmap.c
index bfaa2fe9d90bc50a3e079f9990a36928d5b97693..447f8eec40bec49ceab42e8ddf88f412ac8aebb2 100644 (file)
@@ -197,6 +197,24 @@ void *intmap_after_(const struct intmap *map, intmap_index_t *indexp)
        return intmap_first_(&prev->u.n->child[1], indexp);
 }
 
+void *intmap_last_(const struct intmap *map, intmap_index_t *indexp)
+{
+       const struct intmap *n;
+
+       if (intmap_empty_(map)) {
+               errno = ENOENT;
+               return NULL;
+       }
+
+       n = map;
+       /* Anything with NULL value is a node. */
+       while (!n->v)
+               n = &n->u.n->child[1];
+       errno = 0;
+       *indexp = n->u.i;
+       return n->v;
+}
+
 static void clear(struct intmap n)
 {
        if (!n.v) {