From 496be212ad645999647c432a856c906b86d41487 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 6 Jun 2009 15:30:24 +0200 Subject: hashmap: introduce PA_HASHMAP_FOREACH macro --- src/pulsecore/hashmap.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/pulsecore/hashmap.h') diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h index 08e18ead..828e2448 100644 --- a/src/pulsecore/hashmap.h +++ b/src/pulsecore/hashmap.h @@ -65,4 +65,8 @@ void *pa_hashmap_steal_first(pa_hashmap *h); /* Return the oldest entry in the hashmap */ void* pa_hashmap_first(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)) + #endif -- cgit From a1d84e39359fed52770f9d15650aabc6bcce6910 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jun 2009 03:02:19 +0200 Subject: hashmap: implement api to iterate a hashmap backwards --- src/pulsecore/hashmap.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/pulsecore/hashmap.h') diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h index 828e2448..f379fe3c 100644 --- a/src/pulsecore/hashmap.h +++ b/src/pulsecore/hashmap.h @@ -26,7 +26,8 @@ /* Simple Implementation of a hash table. Memory management is the * user's job. It's a good idea to have the key pointer point to a - * string in the value data. */ + * string in the value data. The insertion order is preserved when + * iterating. */ typedef struct pa_hashmap pa_hashmap; @@ -59,6 +60,9 @@ pa_bool_t pa_hashmap_isempty(pa_hashmap *h); returned. */ void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void**key); +/* Same as pa_hashmap_iterate() but goes backwards */ +void *pa_hashmap_iterate_backwards(pa_hashmap *h, void **state, const void**key); + /* Remove the oldest entry in the hashmap and return it */ void *pa_hashmap_steal_first(pa_hashmap *h); @@ -69,4 +73,8 @@ void* pa_hashmap_first(pa_hashmap *h); #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)) +/* A macro to ease iteration through all entries, backwards */ +#define PA_HASHMAP_FOREACH_BACKWARDS(e, h, state) \ + for ((state) = NULL, (e) = pa_hashmap_iterate_backwards((h), &(state), NULL); (e); (e) = pa_hashmap_iterate_backwards((h), &(state), NULL)) + #endif -- cgit 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.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pulsecore/hashmap.h') 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