private SymSet Expand(SymSet old, int newSize) { SymSet expandedSet = old.Copy(); if (newSize > old.bitSet.Length) expandedSet.bitSet.Length = newSize; return expandedSet; }
public SymSet SymDiff(SymSet that) { // Set symmetric difference int commonSize = max(this.bitSet.Length, that.bitSet.Length); SymSet one = Expand(this, commonSize); SymSet two = Expand(that, commonSize); return new SymSet(one.bitSet.Xor(two.bitSet)); }
public SymSet Union(SymSet that) { // Set union int commonSize = max(this.bitSet.Length, that.bitSet.Length); SymSet one = Expand(this, commonSize); SymSet two = Expand(that, commonSize); return new SymSet(one.bitSet.Or(two.bitSet)); }
/* public SymSet Intersection(SymSet that) { // Set intersection int commonSize = max(this.bitSet.Length, that.bitSet.Length); SymSet one = Expand(this, commonSize); SymSet two = Expand(that, commonSize); return new SymSet(one.bitSet.And(two.bitSet)); } // SymSet.intersection */ public SymSet Intersection(SymSet that) { // Set intersection int minSize = min(this.bitSet.Length, that.bitSet.Length); SymSet one = new SymSet(minSize); for (int i = 0; i < minSize; i++) one.bitSet[i] = this.bitSet[i] && that.bitSet[i]; return one; }
public bool Equals(SymSet that) { // Value comparison - sets contain same elements if (that == null) return false; int commonSize = max(this.bitSet.Length, that.bitSet.Length); SymSet one = Expand(this, commonSize); SymSet two = Expand(that, commonSize); for (int i = 0; i < commonSize; i++) { if (one.bitSet[i] != two.bitSet[i]) return false; } return true; }
/* public SymSet Difference(SymSet that) { // Set difference int commonSize = max(this.bitSet.Length, that.bitSet.Length); SymSet one = Expand(this, commonSize); SymSet two = Expand(that, commonSize); for (int i = 0; i < commonSize; i++) one.bitSet[i] = one.bitSet[i] && ! two.bitSet[i]; return one; } // SymSet.Difference */ public SymSet Difference(SymSet that) { // Set difference int minSize = min(this.bitSet.Length, that.bitSet.Length); SymSet one = this.Copy(); for (int i = 0; i < minSize; i++) one.bitSet[i] = one.bitSet[i] && ! that.bitSet[i]; return one; }
public bool Contains(SymSet that) { // Returns true if that is a subset of this set return that.IsEmpty() || that.Difference(this).IsEmpty(); }
// Empty set constructor public SymSet(SymSet old) { // Construct set from old this.bitSet = new BitArray(old.bitSet); }