Pass in |opt_totalRange| in order to find empty ranges before the first of |inRanges| and after the last of |inRanges|.
193816
function findEmptyRangesBetweenRanges(inRanges, opt_totalRange) {
    if (opt_totalRange && opt_totalRange.isEmpty)
      opt_totalRange = undefined;

    var emptyRanges = [];
    if (!inRanges.length) {
      if (opt_totalRange)
        emptyRanges.push(opt_totalRange);
      return emptyRanges;
    }

    inRanges = inRanges.slice();
    inRanges.sort(function(x, y) {
      return x.min - y.min;
    });
    if (opt_totalRange &&
        (opt_totalRange.min < inRanges[0].min)) {
      emptyRanges.push(tr.b.Range.fromExplicitRange(
          opt_totalRange.min, inRanges[0].min));
    }

    inRanges.forEach(function(range, index) {
      for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) {
        if (index === otherIndex)
          continue;
        var other = inRanges[otherIndex];

        if (other.min > range.max) {
          // |inRanges| is sorted, so |other| is the first range after |range|,
          // and there is an empty range between them.
          emptyRanges.push(tr.b.Range.fromExplicitRange(
              range.max, other.min));
          return;
        }
        // Otherwise, |other| starts before |range| ends, so |other| might
        // possibly contain the end of |range|.

        if (other.max > range.max) {
          // |other| does contain the end of |range|, so no empty range starts
          // at the end of this |range|.
          return;
        }
      }
      if (opt_totalRange && (range.max < opt_totalRange.max)) {
        emptyRanges.push(tr.b.Range.fromExplicitRange(
            range.max, opt_totalRange.max));
      }
    });
    return emptyRanges;
  }
56252
function(sel, range) {
            var ranges = sel.getAllRanges();
            sel.removeAllRanges();
            for (var i = 0, len = ranges.length; i < len; ++i) {
                if (!rangesEqual(range, ranges[i])) {
                    sel.addRange(ranges[i]);
                }
            }
            if (!sel.rangeCount) {
                updateEmptySelection(sel);
            }
        }
672480
def _filter_row_ranges(self):
        
        new_row_ranges = []

        for row_range in self.message.rows.row_ranges:
            # if current end_key (open or closed) is set, return its value,
            # if not, set to empty string ('').
            # NOTE: Empty string in end_key means "end of table"
            end_key = self._end_key_set(row_range)
            # if end_key is already read, skip to the next row_range
            if end_key and self._key_already_read(end_key):
                continue

            # if current start_key (open or closed) is set, return its value,
            # if not, then set to empty string ('')
            # NOTE: Empty string in start_key means "beginning of table"
            start_key = self._start_key_set(row_range)

            # if start_key was already read or doesn't exist,
            # create a row_range with last_scanned_key as start_key_open
            # to be passed to retry request
            retry_row_range = row_range
            if self._key_already_read(start_key):
                retry_row_range = copy.deepcopy(row_range)
                retry_row_range.start_key_closed = _to_bytes("")
                retry_row_range.start_key_open = self.last_scanned_key

            new_row_ranges.append(retry_row_range)

        return new_row_ranges
1200569
def simplify(self):
        

        # Sort the ranges
        self.__range.sort()

        new_range = []
        new_first = self.__range[0].first
        new_count = self.__range[0].count

        for r in self.__range:
            if r.first == new_first:
                # Longest range starting at new_first
                new_count = r.count
            elif r.first <= new_first + new_count:
                # Overlapping ranges
                if new_first + new_count - 1 < r.last:
                    # There is a part of the range to add to the new range
                    new_count = r.last - new_first + 1
            else:
                # No overlap, this is a new disjoint range
                new_range.append(IdRange(new_first, new_count))
                new_first = r.first
                new_count = r.count

        # End of the last range
        new_range.append(IdRange(new_first, new_count))

        self.__range = new_range
1166337
def in_range?( val )
      val = val.to_i
      (@above.nil? or val > @above) and
        (@below.nil? or val < @below) and
        (@valid_range.nil? or @valid_range.include?(val))
    end
579061
def unconsumed_ranges(self):
        
        res = IntervalTree()

        prev = None

        # normal iteration is not in a predictable order
        ranges = sorted([x for x in self.range_set], key=lambda x: x.begin)

        for rng in ranges:
            if prev is None:
                prev = rng
                continue
            res.add(Interval(prev.end, rng.begin))
            prev = rng
        
        # means we've seeked past the end
        if len(self.range_set[self.tell()]) != 1:
            res.add(Interval(prev.end, self.tell()))

        return res
25405
def _xxrange(self, start, end, step_count):
        """"""
        _step = (end - start) / float(step_count)
        return (start + (i * _step) for i in xrange(int(step_count)))
1235096
private static <T extends Comparable<T>> Optional<Range<T>> smallestContainerForRange(
      Collection<Range<T>> ranges, Range<T> target) {
    Range<T> best = Range.all();
    for (final Range<T> r : ranges) {
      if (r.equals(target)) {
        continue;
      }
      // prefer a smaller range, always;
      if (r.encloses(target) && best.encloses(r)) {
        best = r;
      }
    }
    if (best.equals(Range.<T>all())) {
      return Optional.absent();
    }
    return Optional.of(best);
  }
430464
function getRange(sel) {
	sel = sel || getSelection();
	return sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
}
182560
function getNextRange(ranges, anchor) {
	for (let i = 0; i < ranges.length; i++) {
		if (anchor.isEqual(ranges[i])) {
			// NB may return `undefined`, which is totally fine and means that
			// we should move to next element
			return ranges[i + 1];
		}
	}

	// Keep ranges which are not on the left of given selection
	ranges = ranges.filter(r => anchor.end.isLessThanOrEqual(r.start));

	return ranges[0];
}
1014097
function range(start, length) {
      var rgArr = [];
      if (isNum(start)) {
        function rangeLoop(isAdd) {
          if (length >= 0) {
            for (var i = 0; i < length; i++) rgArr.push(isAdd ? i + start : i);
          } else if (length < 0) {
            for (var i = 0; i > length; i--) rgArr.push(isAdd ? i + start : i);
          }
        };
        if (isUdf(length)) {
          length = start, start = UDF;
          rangeLoop(false);
        } else if (isNum(length)) {
          rangeLoop(true);
        }
      }
      return rgArr;
    }
1162528
int rangeEnd(int start, int limitp, int val) {
        int c;
        int limit = Math.min(highStart, limitp);

        for (c = start+1; c < limit; c++) {
            if (get(c) != val) {
                break;
            }
        }
        if (c >= highStart) {
            c = limitp;
        }
        return c - 1;
    }
1365309
function selectRange(range, window) {
      var selection = window.getSelection();
      selection.removeAllRanges();
      selection.addRange(range);
    }
215660
def _combine_ranges_on_length(self, data_len, first, second):
        '''
        
        '''
        first = get_true_slice(first, data_len)
        second = get_true_slice(second, data_len)
        final_start, final_step, final_stop = (None, None, None)

        # Get our start
        if first.start == None and second.start == None:
            final_start = None
        else:
            final_start = (first.start if first.start else 0)+(second.start if second.start else 0)

        # Get our stop
        if second.stop == None:
            final_stop = first.stop
        elif first.stop == None:
            final_stop = (first.start if first.start else 0) + second.stop
        else:
            final_stop = min(first.stop, (first.start if first.start else 0) + second.stop)

        # Get our step
        if first.step == None and second.step == None:
            final_step = None
        else:
            final_step = (first.step if first.step else 1)*(second.step if second.step else 1)

        # If we have a start above our stop, set them to be equal
        if final_start > final_stop:
            final_start = final_stop

        return slice(final_start, final_stop, final_step)
277476
function rangeToLines(range) {
    range = (range || '').split(':');
    if (range.length != 2) {
        return null;
    }

    return {
        start: Number(range[0]) - 1,
        end: Number(range[1]) - 1
    }
}
644038
function rangesIntersect(rangeA, rangeB) {
  return rangeA.compareBoundaryPoints(Range.END_TO_START, rangeB) === -1 &&
    rangeA.compareBoundaryPoints(Range.START_TO_END, rangeB) === 1
}
417184
def ranges_intersect(rset):
    
    if not rset:
        return None

    a = rset[0]
    for b in rset[1:]:
        if not a:
            return None
        a = range_intersect(a, b)

    return a