summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>2021-06-23 17:50:50 +0300
committerAlper Nebi Yasak <alpernebiyasak@gmail.com>2022-06-28 15:08:45 +0300
commitec668ac44bc6e666123f22f2696745dcdce98fed (patch)
tree96740ab5461a226965199974934b222a6383586a
parentfb63e589310fab20e60c46bb40c7b7acab5eeac9 (diff)
downloadpulseaudio-ec668ac44bc6e666123f22f2696745dcdce98fed.tar.gz
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>
-rw-r--r--src/pulsecore/idxset.c34
-rw-r--r--src/pulsecore/idxset.h12
2 files changed, 46 insertions, 0 deletions
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. */