Add complementary functions to the existing idxset iterate(),
steal_first(), first(), next() functions that work in the reverse
direction: reverse_iterate(), steal_last(), last() and previous().
Add isdisjoint(), issubset(), issuperset() and equals() functions that
element-wise compare two idxsets.
Add set contains() function, This is functionally equivalent to get_by_data(s, p, NULL) == p, but
with a more obvious name and form because some existing code is instead
manually iterating through idxsets to check for existence of an item.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/596>
87 lines
2.6 KiB
Diff
87 lines
2.6 KiB
Diff
From ec668ac44bc6e666123f22f2696745dcdce98fed Mon Sep 17 00:00:00 2001
|
|
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
|
|
Date: Wed, 23 Jun 2021 17:50:50 +0300
|
|
Subject: [PATCH] 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>
|
|
---
|
|
src/pulsecore/idxset.c | 34 ++++++++++++++++++++++++++++++++++
|
|
src/pulsecore/idxset.h | 12 ++++++++++++
|
|
2 files changed, 46 insertions(+)
|
|
|
|
diff --git a/src/pulsecore/idxset.c b/src/pulsecore/idxset.c
|
|
index 91ac6a015..b5dd9b3e1 100644
|
|
--- a/src/pulsecore/idxset.c
|
|
+++ b/src/pulsecore/idxset.c
|
|
@@ -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;
|
|
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
|
|
index 6797852b7..ee530bf2b 100644
|
|
--- a/src/pulsecore/idxset.h
|
|
+++ b/src/pulsecore/idxset.h
|
|
@@ -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. */
|
|
--
|
|
2.33.0
|
|
|