mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
idxset: Add set comparison operations
Add isdisjoint(), issubset(), issuperset() and equals() functions that element-wise compare two idxsets. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/596>
This commit is contained in:
parent
fb63e58931
commit
ec668ac44b
2 changed files with 46 additions and 0 deletions
|
|
@ -470,6 +470,40 @@ bool pa_idxset_isempty(pa_idxset *s) {
|
|||
return s->n_entries == 0;
|
||||
}
|
||||
|
||||
bool pa_idxset_isdisjoint(pa_idxset *s, pa_idxset *t) {
|
||||
struct idxset_entry *i;
|
||||
|
||||
pa_assert(s);
|
||||
pa_assert(t);
|
||||
|
||||
for (i = s->iterate_list_head; i; i = i->iterate_next)
|
||||
if (pa_idxset_contains(t, i->data))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pa_idxset_issubset(pa_idxset *s, pa_idxset *t) {
|
||||
struct idxset_entry *i;
|
||||
|
||||
pa_assert(s);
|
||||
pa_assert(t);
|
||||
|
||||
for (i = s->iterate_list_head; i; i = i->iterate_next)
|
||||
if (!pa_idxset_contains(t, i->data))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pa_idxset_issuperset(pa_idxset *s, pa_idxset *t) {
|
||||
return pa_idxset_issubset(t, s);
|
||||
}
|
||||
|
||||
bool pa_idxset_equals(pa_idxset *s, pa_idxset *t) {
|
||||
return pa_idxset_issubset(s, t) && pa_idxset_issuperset(s, t);
|
||||
}
|
||||
|
||||
pa_idxset *pa_idxset_copy(pa_idxset *s, pa_copy_func_t copy_func) {
|
||||
pa_idxset *copy;
|
||||
struct idxset_entry *i;
|
||||
|
|
|
|||
|
|
@ -107,6 +107,18 @@ unsigned pa_idxset_size(pa_idxset*s);
|
|||
/* Return true of the idxset is empty */
|
||||
bool pa_idxset_isempty(pa_idxset *s);
|
||||
|
||||
/* Return true if s and t have no entries in common */
|
||||
bool pa_idxset_isdisjoint(pa_idxset *s, pa_idxset *t);
|
||||
|
||||
/* Return true if all entries in s are also in t */
|
||||
bool pa_idxset_issubset(pa_idxset *s, pa_idxset *t);
|
||||
|
||||
/* Return true if all entries in t are also in s */
|
||||
bool pa_idxset_issuperset(pa_idxset *s, pa_idxset *t);
|
||||
|
||||
/* Return true if s and t have all entries in common */
|
||||
bool pa_idxset_equals(pa_idxset *s, pa_idxset *t);
|
||||
|
||||
/* Duplicate the idxset. This will not copy the actual indexes. If copy_func is
|
||||
* set, each entry is copied using the provided function, otherwise a shallow
|
||||
* copy will be made. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue