From c6830bd9dc53ee745ac331c4ab1c55134562d114 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jun 2009 03:02:34 +0200 Subject: hashmap: implement pa_hashmap_last() --- src/pulsecore/hashmap.c | 9 +++++++++ src/pulsecore/hashmap.h | 3 +++ 2 files changed, 12 insertions(+) (limited to 'src/pulsecore') diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c index b549cb1c..1fac97eb 100644 --- a/src/pulsecore/hashmap.c +++ b/src/pulsecore/hashmap.c @@ -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; diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h index f379fe3c..ac2092a6 100644 --- a/src/pulsecore/hashmap.h +++ b/src/pulsecore/hashmap.h @@ -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)) -- cgit