From ffc2cf97231a543492b5733c7961b65a58b64fe5 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 12 Oct 2018 14:26:39 +0200 Subject: [PATCH] imported patch BitSetTools-prelim.patch --- prism/src/common/BitSetTools.java | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 prism/src/common/BitSetTools.java diff --git a/prism/src/common/BitSetTools.java b/prism/src/common/BitSetTools.java new file mode 100644 index 00000000..a1f3472c --- /dev/null +++ b/prism/src/common/BitSetTools.java @@ -0,0 +1,87 @@ +package common; + +import java.util.BitSet; +import java.util.Iterator; + +public class BitSetTools +{ + public static boolean areNonEmpty(final Iterable sets) + { + for (BitSet set : sets) { + if (set.isEmpty()) { + return false; + } + } + return true; + } + + public static BitSet complement(final int toIndex, final BitSet indices) + { + final BitSet complement = (BitSet) indices.clone(); + complement.flip(0, toIndex); + return complement; + } + + public static BitSet minus(final BitSet set, final BitSet... sets) + { + final BitSet difference = (BitSet) set.clone(); + for (BitSet each : sets) { + difference.andNot(each); + } + return difference; + } + + public static BitSet union(final BitSet... sets) + { + BitSet union = new BitSet(); + for (BitSet set : sets) { + union.or(set); + } + return union; + } + + public static BitSet union(final Iterable sets) + { + return union(sets.iterator()); + } + + public static BitSet union(final Iterator sets) + { + BitSet union = new BitSet(); + while (sets.hasNext()) { + union.or(sets.next()); + } + return union; + } + + public static BitSet intersect(BitSet set, BitSet... sets) + { + BitSet intersection = (BitSet) set.clone(); + for (BitSet each : sets) { + intersection.and(each); + } + return intersection; + } + + public static BitSet intersect(Iterable sets) + { + return intersect(sets.iterator()); + } + + public static BitSet intersect(Iterator sets) + { + if (! sets.hasNext()) { + throw new IllegalArgumentException("Expected at least one set."); + } + BitSet intersection = sets.next(); + while (sets.hasNext()) { + intersection.and(sets.next()); + } + return intersection; + } + + public static boolean isSubset(BitSet subset, BitSet superset) + { + return minus(subset, superset).isEmpty(); + } +} \ No newline at end of file