public ArithmeticSet Difference(ArithmeticSet other) { List <IntPrimitive> list = new List <IntPrimitive>(set); List <IntPrimitive> otherList = new List <IntPrimitive>(other.set); for (int i = 0; i < list.Count; i++) { if (otherList.Contains(list[i])) { list.RemoveAt(i); i--; } } return(new ArithmeticSet(list.ToArray())); }
public ArithmeticSet Intersection(ArithmeticSet other) { List <IntPrimitive> list = new List <IntPrimitive>(set); List <IntPrimitive> otherList = new List <IntPrimitive>(other.set); List <IntPrimitive> ret = new List <IntPrimitive>(this.Union(other).set); for (int i = 0; i < ret.Count; i++) { var item = ret[i]; if (!list.Contains(item) || !otherList.Contains(item)) { ret.RemoveAt(i); i--; } } return(new ArithmeticSet(ret.ToArray())); }
public ArithmeticSet Union(ArithmeticSet other) { if (set.Length == 0) { return(other); } if (other.set.Length == 0) { return(this); } IntPrimitive[] newSet = new IntPrimitive[set.Length + other.set.Length]; Array.Copy(set, 0, newSet, 0, set.Length); Array.Copy(other.set, 0, newSet, set.Length, other.set.Length); newSet = ResolveSet(newSet); return(new ArithmeticSet(newSet)); }
public bool IsDisjoint(ArithmeticSet other) => this.Intersection(other).set.Length == EmptySet.set.Length;