private static IntPrimitive[] ResolveSet(IntPrimitive[] collection) { if (collection.Length < 2) { return((IntPrimitive[])collection.Clone()); } IntPrimitive[] sorted = new IntPrimitive[collection.Length]; collection.CopyTo(sorted, 0); SortAlgorithms.TimSort(sorted); List <IntPrimitive> list = new List <IntPrimitive>(sorted); for (int i = 0; i < list.Count - 1; i++) { if ((list[i] as IComparable <IntPrimitive>).CompareTo(list[i + 1]) == 0) { list.RemoveAt(i); i--; } } return(list.ToArray()); }
public IntPrimitive[] ToArray(object indexerSource = null) { GetValues(indexerSource, out int indexStart, out int indexEnd); if (indexStart > indexEnd) { throw new InvalidOperationException("Range start index must be less than end index"); } IntPrimitive[] ret = new IntPrimitive[indexEnd - indexStart + 1]; for (int i = indexStart; i <= indexEnd; i++) { ret[i - indexStart] = new IntPrimitive(i); } return(ret); }
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)); }