/// <summary> /// Returns a new BitVectorSet which is the intersection of this BitVectorSet and the <i>otherSet</i>. /// </summary> /// <param name="otherSet">The set whose intersection with this set is to be computed.</param> /// <returns>The intersection of this set and the <i>otherSet</i>.</returns> public BitVectorSet GetIntersectionWith(BitVectorSet otherSet) { BitVectorSet intersection = new BitVectorSet(this); intersection.IntersectWith(otherSet); return(intersection); }
/// <summary> /// Returns a new BitVectorSet which is the union of this BitVectorSet and the <i>otherSet</i>. /// </summary> /// <param name="otherSet">The set whose union with this set is to be computed.</param> /// <returns>The union of this set and the <i>otherSet</i>.</returns> public BitVectorSet GetUnionWith(BitVectorSet otherSet) { BitVectorSet union = new BitVectorSet(this); union.UnionWith(otherSet); return(union); }
/// <summary> /// Computes the intersection of the elements contained in this BitVectorSet and the <i>otherSet</i> /// and stores the result in this BitVectorSet instance. /// </summary> /// <param name="otherSet">The set with which this instance's set is to be intersected with.</param> /// <exception cref="ArgumentException">when the BitVectorSets are geared for different ranges.</exception> public void IntersectWith(BitVectorSet otherSet) { if (this.capacity != otherSet.capacity) { throw new ArgumentException("The sets are geared for different ranges.", "otherSet"); } for (int i = 0; i < this.bitVectors.Length; i++) { this.bitVectors[i] &= otherSet.bitVectors[i]; } }
/// <summary> /// Computes the relative complement of <i>set2</i> in <i>set1</i>. /// </summary> /// <returns>The relative complement of <i>set2</i> in <i>set1</i>.</returns> public static BitVectorSet operator -(BitVectorSet set1, BitVectorSet set2) { BitVectorSet complement = new BitVectorSet(set1.capacity); if (set1.capacity != set2.capacity) { throw new ArgumentException("The sets are geared for different capacities.", "otherSet"); } for (int i = 0; i < complement.bitVectors.Length; i++) { complement.bitVectors[i] = set1.bitVectors[i] & ~set2.bitVectors[i]; } return(complement); }
/// <summary> /// Determines whether the two sets represented by this BitVectorSet instance and the <i>otherSet</i> /// are mutually disjoint. /// </summary> /// <param name="otherSet">The set to be checked for intersections with this instance.</param> /// <returns><b>true</b> if the two sets are disjoint; <b>false</b> otherwise</returns> /// <exception cref="ArgumentException">when the BitVectorSets are geared for different ranges.</exception> public bool IsDisjointWith(BitVectorSet otherSet) { if (this.capacity != otherSet.capacity) { throw new ArgumentException("The sets are geared for different capacities.", "otherSet"); } for (int i = 0; i < this.bitVectors.Length; i++) { if ((this.bitVectors[i] & otherSet.bitVectors[i]) != 0) { return(false); } } return(true); }
/// <summary> /// Creates a BitVectorSet by duplicating another one. /// </summary> /// <param name="originalSet">The BitVectorSet to be duplicated.</param> public BitVectorSet(BitVectorSet originalSet) { this.capacity = originalSet.capacity; this.bitVectors = new int[originalSet.bitVectors.Length]; originalSet.bitVectors.CopyTo(this.bitVectors, 0); }