given an interval, get intervals in the tree that are intersected.

    :param start: start of the intersecting interval
    :param end:   end of the intersecting interval
    :return:      the list of intersected intervals
179269
def intersectingInterval(self, start, end):
    
    # find all intervals in this node that intersect start and end
    l = []
    for x in self.data.starts:
      xStartsAfterInterval = (x.start > end and not self.openEnded) or \
                             (x.start >= end and self.openEnded)
      xEndsBeforeInterval = (x.end < start and not self.openEnded) or \
                            (x.end <= start and self.openEnded)
      if ((not xStartsAfterInterval) and (not xEndsBeforeInterval)):
        l.append(x)

    # process left subtree (if we have one) if the requested interval begins
    # before mid
    if self.left is not None and start <= self.data.mid:
      l += self.left.intersectingInterval(start, end)

    # process right subtree (if we have one) if the requested interval ends
    # after mid
    if self.right is not None and end >= self.data.mid:
      l += self.right.intersectingInterval(start, end)

    return l
733116
function range(begin, end, interval = 1) {
  var a = [];

  for (let i = begin; i < (begin+end); i += interval) {
    a.push(i);
  }

  return a;
}
1353879
@SuppressWarnings({"rawtypes", "unchecked"})
    public static List<Interval<?>> complement(List<Interval> intervals) throws MIDDException {

        final Interval w = new Interval(new EndPoint(EndPoint.Infinity.NEGATIVE), new EndPoint(EndPoint.Infinity.POSITIVE));
        List<Interval<?>> op1 = new ArrayList<>();
        op1.add(w);

        for (Interval op2 : intervals) {
            final List<Interval<?>> result = new ArrayList<>();

            for (Interval item : op1) {
                if (item.isIntersec(op2)) {
                    final List<Interval<?>> l = item.complement(op2);
                    if (!l.isEmpty()) {
                        result.addAll(l);
                    }
                } else {
                    result.add(item);
                }
            }
            op1 = result;
        }
        return ImmutableList.copyOf(op1);
    }
1202303
def range(start, stop):
    

    length = stop - start

    out = list(length=length)

    index = 0

    orig_start = start

    while start < stop:
        val = index + orig_start
        out[index] = val
        index = index + 1
        start = orig_start + index

    return out
1297417
def get_range(self, start=None, stop=None):
		
		return self.from_iterable(self.ranges(start, stop))
1088855
def __get_keys(self, chrom, start, end=None):
    
    keys = []
    if chrom in self.whole_chrom_files:
      keys.append(self.whole_chrom_files[chrom])
    if chrom in self.partial_trees:
      if end is not None:
        hits = self.partial_trees[chrom].intersectingInterval(start, end)
      else:
        hits = self.partial_trees[chrom].intersectingPoint(start, end)
      for hit in hits:
        keys.append(hit.key)
    return keys
511730
function range(start, end) {
  return Array(end - start + 1).fill().map(function (_, index) {
    return start + index;
  });
}
348268
def intervals(graph):
    
    interval_graph = Graph()  # graph of intervals
    heads = [graph.entry]  # list of header nodes
    interv_heads = {}  # interv_heads[i] = interval of header i
    processed = {i: False for i in graph}
    edges = defaultdict(list)

    while heads:
        head = heads.pop(0)

        if not processed[head]:
            processed[head] = True
            interv_heads[head] = Interval(head)

            # Check if there is a node which has all its predecessor in the
            # current interval. If there is, add that node to the interval and
            # repeat until all the possible nodes have been added.
            change = True
            while change:
                change = False
                for node in graph.rpo[1:]:
                    if all(
                                    p in interv_heads[head] for p in graph.all_preds(node)):
                        change |= interv_heads[head].add_node(node)

            # At this stage, a node which is not in the interval, but has one
            # of its predecessor in it, is the header of another interval. So
            # we add all such nodes to the header list.
            for node in graph:
                if node not in interv_heads[head] and node not in heads:
                    if any(
                                    p in interv_heads[head] for p in graph.all_preds(node)):
                        edges[interv_heads[head]].append(node)
                        assert (node not in heads)
                        heads.append(node)

            interval_graph.add_node(interv_heads[head])
            interv_heads[head].compute_end(graph)

    # Edges is a mapping of 'Interval -> [header nodes of interval successors]'
    for interval, heads in edges.items():
        for head in heads:
            interval_graph.add_edge(interval, interv_heads[head])

    interval_graph.entry = graph.entry.interval
    if graph.exit:
        interval_graph.exit = graph.exit.interval

    return interval_graph, interv_heads
45758
def _metrics_get_endpoints(options):
    
    if bool(options.start) ^ bool(options.end):
        log.error('--start and --end must be specified together')
        sys.exit(1)

    if options.start and options.end:
        start = options.start
        end = options.end
    else:
        end = datetime.utcnow()
        start = end - timedelta(options.days)

    return start, end
315716
def recordtree(table, start='start', stop='stop'):
    

    import intervaltree
    getstart = attrgetter(start)
    getstop = attrgetter(stop)
    tree = intervaltree.IntervalTree()
    for rec in records(table):
        tree.addi(getstart(rec), getstop(rec), rec)
    return tree
843024
def __findFirstMissing(self, array, start, end):
        
        if (start > end):
            return end + 1

        if (start != array[start]):
            return start

        mid = int((start + end) / 2)

        if (array[mid] == mid):
            return self.__findFirstMissing(array, mid + 1, end)

        return self.__findFirstMissing(array, start, mid)
390607
def contains_interval(self, other):
        
        return (
            self.begin <= other.begin and
            self.end >= other.end
        )
391096
def intersection(self, *iterables):
        
        comb = self._set.intersection(*iterables)
        return self._fromset(comb, key=self._key)
1291627
def intersectingPoint(self, p):
    
    # perfect match
    if p == self.data.mid:
      return self.data.ends

    if p > self.data.mid:
      # we know all intervals in self.data begin before p (if they began after
      # p, they would have not included mid) we just need to find those that
      # end after p
      endAfterP = [r for r in self.data.ends
                   if (r.end >= p and not self.openEnded) or
                   (r.end > p and self.openEnded)]
      if self.right is not None:
        endAfterP.extend(self.right.intersectingPoint(p))
      return endAfterP

    if p < self.data.mid:
      # we know all intervals in self.data end after p (if they ended before p,
      # they would have not included mid) we just need to find those that start
      # before p
      startBeforeP = [r for r in self.data.starts if r.start <= p]
      if self.left is not None:
        startBeforeP.extend(self.left.intersectingPoint(p))
      return startBeforeP
1224351
protected List<Intervalable> checkForOverlaps(Intervalable interval, Direction direction)
    {

        List<Intervalable> overlaps = new ArrayList<Intervalable>();
        for (Intervalable currentInterval : this.intervals)
        {
            switch (direction)
            {
                case LEFT:
                    if (currentInterval.getStart() <= interval.getEnd())
                    {
                        overlaps.add(currentInterval);
                    }
                    break;
                case RIGHT:
                    if (currentInterval.getEnd() >= interval.getStart())
                    {
                        overlaps.add(currentInterval);
                    }
                    break;
            }
        }
        return overlaps;
    }
64046
public static <T> List<T> slice(List<T> list, Integer start, Integer stop) {
        int size = list.size();

        if (start == null) {
            start = 0;
        } else if (start < 0) {
            start = size + start;
        }

        if (stop == null) {
            stop = size;
        } else if (stop < 0) {
            stop = size + stop;
        }

        if (start >= size || stop <= 0 || start >= stop) {
            return Collections.emptyList();
        }

        start = Math.max(0, start);
        stop = Math.min(size, stop);

        return list.subList(start, stop);
    }
1023180
def intersection(self, range):
        
        if self.worksheet != range.worksheet:
            # Different worksheet
            return None
        start = (max(self._start[0], range._start[0]),
                 max(self._start[1], range._start[1]))
        end = (min(self._end[0], range._end[0]),
               min(self._end[1], range._end[1]))
        if end[0] < start[0] or end[1] < start[1]:
            return None
        return Range(start, end, self.worksheet, validate=False)