public static void IntersetOnTwoKeys() { var set = new IndexRangeSet(); var result = set.Intersect(SqlExpressionType.LessThan, new IndexKey(SqlObject.Integer(3))); result = result.Intersect(SqlExpressionType.GreaterThan, new IndexKey(SqlObject.Integer(12))); Assert.NotNull(result); var ranges = result.ToArray(); Assert.Equal(0, ranges.Length); }
public static void IntersectOnSingleKey() { var set = new IndexRangeSet(); var result = set.Intersect(SqlExpressionType.Equal, new IndexKey(SqlObject.Boolean(true))); Assert.NotNull(result); var ranges = result.ToArray(); Assert.Equal(1, ranges.Length); Assert.Equal(new IndexKey(SqlObject.Boolean(true)), ranges[0].StartValue); Assert.Equal(new IndexKey(SqlObject.Boolean(true)), ranges[0].EndValue); }
public static void UnionTwoSets() { var set1 = new IndexRangeSet(); set1.Intersect(SqlExpressionType.GreaterThan, new IndexKey(SqlObject.Integer(3))); var set2 = new IndexRangeSet(); set2.Intersect(SqlExpressionType.LessThan, new IndexKey(SqlObject.Integer(12))); var result = set1.Union(set2); Assert.NotNull(result); var ranges = result.ToArray(); Assert.Equal(2, ranges.Length); }
/// <summary> /// Unions the current range set with the given range set. /// </summary> public IndexRangeSet Union(IndexRangeSet unionTo) { lock (this) { var rangeSet = new List <IndexRange>(ranges); var inputSet = unionTo.ranges; int inSz = inputSet.Count; int n = 0; while (n < inSz) { var inRange = inputSet[n]; int sz = rangeSet.Count; var i = rangeSet.GetRange(0, sz); int j = 0; while (j < i.Count) { var range = i[j]; if (IntersectedBy(inRange, range)) { i.RemoveAt(j); inRange = ChangeRangeSizeToEncompass(inRange, range); } j++; } // Insert into sorted position var startPoint = inRange.StartOffset; var start = inRange.StartValue; var endPoint = inRange.EndOffset; var end = inRange.EndValue; if (start == IndexRange.FirstInSet) { rangeSet.Insert(0, inRange); } else { var startCell = start; i = rangeSet.GetRange(0, rangeSet.Count); j = 0; while (j < i.Count) { var range = i[j]; var curStart = range.StartValue; if (!curStart.Equals(IndexRange.FirstInSet)) { if (curStart.CompareTo(startCell) > 0) { i[j] = i[j - 1]; break; } } j++; } i.Add(inRange); } n++; } return(new IndexRangeSet(rangeSet)); } }