public IValueSet Union(IValueSet other) { SortedRangeSet OtherRangeSet = this.CheckCompatibility(other); return(new Builder(this.Type) .AddAll(this.GetOrderedRanges()) .AddAll(OtherRangeSet.GetOrderedRanges()) .Build()); }
public IValueSet Intersect(IValueSet other) { SortedRangeSet OtherRangeSet = this.CheckCompatibility(other); Builder Builder = new Builder(this.Type); IEnumerator <Range> Iterator1 = this.GetOrderedRanges().GetEnumerator(); IEnumerator <Range> Iterator2 = OtherRangeSet.GetOrderedRanges().GetEnumerator(); if (Iterator1.MoveNext() && Iterator2.MoveNext()) { Range Range1 = Iterator1.Current; Range Range2 = Iterator2.Current; while (true) { if (Range1.Overlaps(Range2)) { Builder.Add(Range1.Intersect(Range2)); } if (Range1.High.CompareTo(Range2.High) <= 0) { if (!Iterator1.MoveNext()) { break; } Range1 = Iterator1.Current; } else { if (!Iterator2.MoveNext()) { break; } Range2 = Iterator2.Current; } } } return(Builder.Build()); }