hashmap: implement pa_hashmap_last()
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jun 2009 01:02:34 +0000 (03:02 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Jun 2009 01:02:34 +0000 (03:02 +0200)
src/pulsecore/hashmap.c
src/pulsecore/hashmap.h

index b549cb1..1fac97e 100644 (file)
@@ -279,6 +279,15 @@ void* pa_hashmap_first(pa_hashmap *h) {
     return h->iterate_list_head->value;
 }
 
+void* pa_hashmap_last(pa_hashmap *h) {
+    pa_assert(h);
+
+    if (!h->iterate_list_tail)
+        return NULL;
+
+    return h->iterate_list_tail->value;
+}
+
 void* pa_hashmap_steal_first(pa_hashmap *h) {
     void *data;
 
index f379fe3..ac2092a 100644 (file)
@@ -69,6 +69,9 @@ void *pa_hashmap_steal_first(pa_hashmap *h);
 /* Return the oldest entry in the hashmap */
 void* pa_hashmap_first(pa_hashmap *h);
 
+/* Return the newest entry in the hashmap */
+void* pa_hashmap_last(pa_hashmap *h);
+
 /* A macro to ease iteration through all entries */
 #define PA_HASHMAP_FOREACH(e, h, state) \
     for ((state) = NULL, (e) = pa_hashmap_iterate((h), &(state), NULL); (e); (e) = pa_hashmap_iterate((h), &(state), NULL))