mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
hashmap: implement api to iterate a hashmap backwards
This commit is contained in:
parent
277e8c5ce4
commit
a1d84e3935
2 changed files with 42 additions and 1 deletions
|
|
@ -237,6 +237,39 @@ at_end:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *pa_hashmap_iterate_backwards(pa_hashmap *h, void **state, const void **key) {
|
||||
struct hashmap_entry *e;
|
||||
|
||||
pa_assert(h);
|
||||
pa_assert(state);
|
||||
|
||||
if (*state == (void*) -1)
|
||||
goto at_beginning;
|
||||
|
||||
if (!*state && !h->iterate_list_tail)
|
||||
goto at_beginning;
|
||||
|
||||
e = *state ? *state : h->iterate_list_tail;
|
||||
|
||||
if (e->iterate_previous)
|
||||
*state = e->iterate_previous;
|
||||
else
|
||||
*state = (void*) -1;
|
||||
|
||||
if (key)
|
||||
*key = e->key;
|
||||
|
||||
return e->value;
|
||||
|
||||
at_beginning:
|
||||
*state = (void *) -1;
|
||||
|
||||
if (key)
|
||||
*key = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* pa_hashmap_first(pa_hashmap *h) {
|
||||
pa_assert(h);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue