Returns a new tree of all intervals common to both self and
        other.
187433
def intersection(self, other):
        
        ivs = set()
        shorter, longer = sorted([self, other], key=len)
        for iv in shorter:
            if iv in longer:
                ivs.add(iv)
        return IntervalTree(ivs)
1275745
public static List<Interval> combine(List<Interval> intervals) {
        List<Interval> combined = new ArrayList<Interval>();
        Collections.sort(intervals);
        int len = intervals.size();
        for (int i = 0; i < len; i++) {
            combined.add(intervals.get(i));

            int j;
            for (j = i + 1; j < len; j++) {
                if (intervals.get(i).stop >= intervals.get(j).start) {
                    intervals.get(i).stop = intervals.get(j).stop;
                } else {
                    break;
                }
            }
            i = j - 1;
        }

        return combined;
    }
1064745
def diff_trees(left, right, diff_options=None, formatter=None):
    """"""
    if formatter is not None:
        formatter.prepare(left, right)
    if diff_options is None:
        diff_options = {}
    differ = diff.Differ(**diff_options)
    diffs = differ.diff(left, right)

    if formatter is None:
        return list(diffs)

    return formatter.format(diffs, left)
516001
public function intersection(Interval $other)
	{
		if ($this->isContaining($other)) {
			return $other;

		} elseif ($other->isContaining($this)) {
			return $this;

		} elseif ($this->isOverlappedFromRightBy($other)) {
			// This:  □□□□□□■■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□
			// Other: □□□□□□□□□□□□■■■■■■■■■■■□□□□□□□□□□□□□□
			//    $other->from   |   | <- $this-till

			return new static($other->getLeft(), $this->getRight());

		} elseif ($other->isOverlappedFromRightBy($this)) {
			// This:  □□□□□□□□□□□□■■■■■■■■■■■□□□□□□□□□□□□□□□□□
			// Other: □□□□□□■■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□
			//    $this->from -> |   | <- $other-till

			return new static($this->getLeft(), $other->getRight());
		}

		$dummy = $this->left->asOpened();

		return new static($dummy, $dummy);
	}
965469
def union(self, other):
        
        result = IntervalSet()
        for el in self:
            result.add(el)
        for el in other:
            result.add(el)
        return result
618830
def intersects(self, other):
		
		return any(key in self and self[key].intersects(value) for key, value in other.iteritems())
1056542
def get_tree(cls, parent=None):
        
        if parent:
            depth = parent.get_depth() + 1
            results = [parent]
        else:
            depth = 1
            results = []
        cls._get_tree_recursively(results, parent, depth)
        return results
838662
public static <E, A> TreeComparison<E, A> of(TreeDef<E> expectedDef, E expectedRoot, TreeDef<A> actualDef, A actualRoot) {
		return new TreeComparison<>(expectedDef, expectedRoot, actualDef, actualRoot);
	}
1341524
public Interval expand(Interval<E> other)
  {
    if (other == null) return this;
    E a = min(this.first, other.first);
    E b = max(this.second, other.second);
    return toInterval(a,b);
  }
1073087
def eq_or_parent(self, other):
        
        return self.parts[: len(other.parts)] == other.parts[: len(self.parts)]
380669
def intersects_all(self, other):
		
		return all(key in self and self[key].intersects(value) for key, value in other.iteritems()) and bool(other)
1024172
def gaps(self) -> "IntervalList":
        
        if len(self.intervals) < 2:
            return IntervalList(None)
        gaps = []
        for i in range(len(self.intervals) - 1):
            gap = Interval(
                self.intervals[i].end,
                self.intervals[i + 1].start
            )
            gaps.append(gap)
        return IntervalList(gaps)
947555
function(that) {
    if (this.sourceString !== that.sourceString) {
      throw errors.intervalSourcesDontMatch();
    }
    assert(this.startIdx >= that.startIdx && this.endIdx <= that.endIdx,
           'other interval does not cover this one');
    return new Interval(this.sourceString,
                        this.startIdx - that.startIdx,
                        this.endIdx - that.startIdx);
  }
147702
def intersection(self, other):
        
        relative_position = self.relative_position_of(other)
        if relative_position in [
            self.RELATIVE_POSITION_PP_C,
            self.RELATIVE_POSITION_PI_LC,
            self.RELATIVE_POSITION_PI_LG,
            self.RELATIVE_POSITION_PI_CG,
            self.RELATIVE_POSITION_IP_B,
            self.RELATIVE_POSITION_II_LB,
        ]:
            return TimeInterval(begin=self.begin, end=self.begin)
        if relative_position in [
            self.RELATIVE_POSITION_IP_E,
            self.RELATIVE_POSITION_II_EG,
        ]:
            return TimeInterval(begin=self.end, end=self.end)
        if relative_position in [
            self.RELATIVE_POSITION_II_BI,
            self.RELATIVE_POSITION_II_BE,
            self.RELATIVE_POSITION_II_II,
            self.RELATIVE_POSITION_II_IE,
        ]:
            return TimeInterval(begin=other.begin, end=other.end)
        if relative_position in [
            self.RELATIVE_POSITION_IP_I,
            self.RELATIVE_POSITION_II_LI,
            self.RELATIVE_POSITION_II_LE,
            self.RELATIVE_POSITION_II_LG,
            self.RELATIVE_POSITION_II_BG,
            self.RELATIVE_POSITION_II_IG,
        ]:
            begin = max(self.begin, other.begin)
            end = min(self.end, other.end)
            return TimeInterval(begin=begin, end=end)
        return None
359350
def intersection(other)
      if other.is_a?(RelativeComplement)
        # A ∩ ¬B = ¬B ∩ A
        other.intersection(self)
      elsif other.is_a?(AbstractSet)
        if other.is_a?(RelativeSet) and size > other.size
          # For efficiency, iterate the smaller of the two sets: A ∩ B = B ∩ A
          other.intersection(self)
        elsif other.empty?
          # A ∩ ∅ = ∅
          NullSet.build
        else
          hash = @hash.clone.delete_if{|o,_| not other.include?(o) }

          if hash.empty?
            NullSet.build
          else
            RelativeSet.new(hash)
          end
        end
      else
        intersection(Cantor.build(other))
      end
    end
1111379
def merge(self, other):
        
        other = IntervalCell.coerce(other)
        if self.is_equal(other):
            # pick among dependencies
            return self
        elif other.is_entailed_by(self):
            return self
        elif self.is_entailed_by(other):
            self.low, self.high = other.low, other.high
        elif self.is_contradictory(other):
            #import traceback
            #for line in traceback.format_stack(): print line.strip()

            raise Contradiction("Cannot merge [%0.2f, %0.2f] with [%0.2f, %0.2f]" \
                    % (self.low, self.high, other.low, other.high))
        else:
            # information in both
            self.low = max(self.low, other.low)
            self.high = min(self.high, other.high)
        return self
1322414
def is_entailed_by(self, other):
        
        other = IntervalCell.coerce(other)
        return other.low >= self.low and other.high <= self.high