Exemple #1
0
 /// <summary>Add the range indices.</summary>
 /// <remarks>
 /// Add the range indices. It is ensured that the added range
 /// doesn't overlap the existing ranges. If it overlaps, the
 /// existing overlapping ranges are removed and a single range
 /// having the superset of all the removed ranges and this range
 /// is added.
 /// If the range is of 0 length, doesn't do anything.
 /// </remarks>
 /// <param name="range">Range to be added.</param>
 internal virtual void Add(SortedRanges.Range range)
 {
     lock (this)
     {
         if (range.IsEmpty())
         {
             return;
         }
         long startIndex = range.GetStartIndex();
         long endIndex   = range.GetEndIndex();
         //make sure that there are no overlapping ranges
         ICollection <SortedRanges.Range> headSet = ranges.HeadSet(range);
         if (headSet.Count > 0)
         {
             SortedRanges.Range previousRange = headSet.Last();
             Log.Debug("previousRange " + previousRange);
             if (startIndex < previousRange.GetEndIndex())
             {
                 //previousRange overlaps this range
                 //remove the previousRange
                 if (ranges.Remove(previousRange))
                 {
                     indicesCount -= previousRange.GetLength();
                 }
                 //expand this range
                 startIndex = previousRange.GetStartIndex();
                 endIndex   = endIndex >= previousRange.GetEndIndex() ? endIndex : previousRange.GetEndIndex
                                  ();
             }
         }
         IEnumerator <SortedRanges.Range> tailSetIt = ranges.TailSet(range).GetEnumerator();
         while (tailSetIt.HasNext())
         {
             SortedRanges.Range nextRange = tailSetIt.Next();
             Log.Debug("nextRange " + nextRange + "   startIndex:" + startIndex + "  endIndex:"
                       + endIndex);
             if (endIndex >= nextRange.GetStartIndex())
             {
                 //nextRange overlaps this range
                 //remove the nextRange
                 tailSetIt.Remove();
                 indicesCount -= nextRange.GetLength();
                 if (endIndex < nextRange.GetEndIndex())
                 {
                     //expand this range
                     endIndex = nextRange.GetEndIndex();
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
         Add(startIndex, endIndex);
     }
 }
Exemple #2
0
 private void DoNext()
 {
     next++;
     Log.Debug("currentIndex " + next + "   " + range);
     SkipIfInRange();
     while (next >= range.GetEndIndex() && rangeIterator.HasNext())
     {
         range = rangeIterator.Next();
         SkipIfInRange();
     }
 }