diff --git a/src/pulsecore/idxset.c b/src/pulsecore/idxset.c index 5175ca217..91ac6a015 100644 --- a/src/pulsecore/idxset.c +++ b/src/pulsecore/idxset.c @@ -258,6 +258,20 @@ void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx) { return e->data; } +bool pa_idxset_contains(pa_idxset *s, const void *p) { + unsigned hash; + struct idxset_entry *e; + + pa_assert(s); + + hash = s->hash_func(p) % NBUCKETS; + + if (!(e = data_scan(s, hash, p))) + return false; + + return e->data == p; +} + void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx) { struct idxset_entry *e; unsigned hash; diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h index 7acb202ff..6797852b7 100644 --- a/src/pulsecore/idxset.h +++ b/src/pulsecore/idxset.h @@ -66,6 +66,9 @@ void* pa_idxset_get_by_index(pa_idxset*s, uint32_t idx); /* Get the entry by its data. The index is returned in *idx */ void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx); +/* Return true if item is in idxset */ +bool pa_idxset_contains(pa_idxset *s, const void *p); + /* Similar to pa_idxset_get_by_index(), but removes the entry from the idxset. */ void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx);