Returns a number indicating which of two overlapping collapsed spans is larger (and thus includes the other). Falls back to comparing ids when the spans cover exactly the same range.
435088
function compareCollapsedMarkers(a, b) {
    var lenDiff = a.lines.length - b.lines.length;
    if (lenDiff != 0) return lenDiff;
    var aPos = a.find(), bPos = b.find();
    var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
    if (fromCmp) return -fromCmp;
    var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
    if (toCmp) return toCmp;
    return b.id - a.id;
  }
11121
def guess(span, mode = :middle)
      return span if not mode
      return span.begin + span.width / 2 if span.width > 1 and (mode == true or mode == :middle)
      return span.end if mode == :end
      span.begin
    end
1374559
def get_1D_overlap(eclusters, depth=1):
    
    overlap_set = set()
    active = set()

    ends = []
    for i, (chr, left, right) in enumerate(eclusters):
        ends.append((chr, left, 0, i))  # 0/1 for left/right-ness
        ends.append((chr, right, 1, i))
    ends.sort()

    chr_last = ""
    for chr, pos, left_right, i in ends:
        if chr != chr_last:
            active.clear()
        if left_right == 0:
            active.add(i)
        else:
            active.remove(i)

        if len(active) > depth:
            overlap_set.add(tuple(sorted(active)))

        chr_last = chr

    return overlap_set
1304895
private function _get_collapsed_margin_length($length1, $length2)
    {
        if ($length1 < 0 && $length2 < 0) {
            return min($length1, $length2); // min(x, y) = - max(abs(x), abs(y)), if x < 0 && y < 0
        }
        
        if ($length1 < 0 || $length2 < 0) {
            return $length1 + $length2; // x + y = x - abs(y), if y < 0
        }
        
        return max($length1, $length2);
    }
275849
def overlaps(self, other):
        
        return (
            self.right > other.left and
            self.left < other.right and
            self.top < other.bottom and
            self.bottom > other.top
        )
1200388
def at_span(self, span, predicate=None, index=None):
        
        starting = self._index_dict[span[0]]
        ending = self._index_dict[span[1] - 1]

        merged = list(starting)
        for marker in ending:
            if marker not in merged:
                merged.append(marker)

        return filter_index(merged, predicate, index)
182149
def intersect(self, other):
        
        if not self.overlap(other):
            return None

        newstart = max(self._start, other.start)
        newend = min(self._end, other.end)
        return Range(newstart, newend)
916918
function compareByIdThenRev(a, b) {
  var idCompare = compare(a._id, b._id);
  if (idCompare !== 0) {
    return idCompare;
  }
  var aStart = a._revisions ? a._revisions.start : 0;
  var bStart = b._revisions ? b._revisions.start : 0;
  return compare(aStart, bStart);
}
454437
def overlap(self, x, ctrs, kdtree=None):
        """"""

        q = len(self.within(x, ctrs, kdtree=kdtree))

        return q
1059274
public static boolean overlapping(Version min1, Version max1, Version min2, Version max2)
	{
		// Versions overlap if:
		// - either Min or Max values are identical (fast test for real scenarios)
		// - Min1|Max1 are within the range Min2-Max2
		// - Min2|Max2 are within the range Min1-Max1

		return min1.equals(min2) || max1.equals(max2) || min2.within(min1, max1) || max2.within(min1, min2) ||
		       min1.within(min2, max2) || max1.within(min2, max2);
	}
1347660
function findLargestInCol (M, i, startAtRow = 0) {
  let me = M.elements;
  let n = M.dimension;
  let offset = i * n;
  let maxIdx = startAtRow;
  let maxVal = _Math.abs(me[offset + maxIdx]);
  for (let i = maxIdx + 1; i < n; ++i) {
    let val = _Math.abs(me[offset + i]);
    if (val > maxVal) {
      maxIdx = i;
      maxVal = val;
    }
  }
  return maxIdx;
}
231870
def no_overlap(multienum):
    
    duplicates = []
    members = []

    for member in multienum.__members__.values():
        for prev_member in members:
            intersection = set(member._value_) & set(prev_member._value_)
            if intersection:
                duplicates.append((member._name_, prev_member._name_, intersection))
        members.append(member)

    if duplicates:
        alias_details = ', '.join(["{} & {} -> {}".format(alias, name, intersection)
                                  for (alias, name, intersection) in duplicates])
        raise ValueError('common element found in {!r}: {}'
                         .format(multienum, alias_details))
    return multienum
1257307
def match_length(self):
        
        length = 0
        for match in self.get_matching_blocks():
            a, b, size = match
            length += self._text_length(self.a[a:a+size])
        return length
416990
def overlaps(self, begin, end=None):
        
        if end is not None:
            return self.overlaps_range(begin, end)
        elif isinstance(begin, Number):
            return self.overlaps_point(begin)
        else:
            return self.overlaps_range(begin.begin, begin.end)
938446
def overlap(self, x, j=None):
        """"""

        q = len(self.within(x, j=j))

        return q
144769
def _one_contains_other(s1, s2):
    
    return min(len(s1), len(s2)) == len(s1 & s2)
820190
def resolve_using_maximal_coverage(matches):
    
    if len(matches) == 0:
        return matches
    matches.sort()
    N = len(matches)
    scores = [len(match) for match in matches]
    prev = [-1] * N
    for i in range(1, N):
        bestscore = -1
        bestprev = -1
        j = i
        while j >= 0:
            # if matches do not overlap
            if matches[j].is_before(matches[i]):
                l = scores[j] + len(matches[i])
                if l >= bestscore:
                    bestscore = l
                    bestprev = j
            else:
                # in case of overlapping matches
                l = scores[j] - len(matches[j]) + len(matches[i])
                if l >= bestscore:
                    bestscore = l
                    bestprev = prev[j]
            j = j - 1
        scores[i] = bestscore
        prev[i] = bestprev
    # first find the matching with highest combined score
    bestscore = max(scores)
    bestidx = len(scores) - scores[-1::-1].index(bestscore) -1
    # then backtrack the non-conflicting matchings that should be kept
    keepidxs = [bestidx]
    bestidx = prev[bestidx]
    while bestidx != -1:
        keepidxs.append(bestidx)
        bestidx = prev[bestidx]
    # filter the matches
    return [matches[idx] for idx in reversed(keepidxs)]