Returns closest smaller (Comparator::compare returns -1) or any equal.
199458
public int searchLowerBound(MonikerComparator moniker, int treap) {
		int cur = getRoot(treap);
		int bound = -1;
		while (cur != nullNode()) {
			int res = moniker.compare(this, cur);
			if (res == 0)
				return cur;
			else if (res < 0)
				cur = getLeft(cur);
			else {
				bound = cur;
				cur = getRight(cur);
			}
		}

		return bound;
	}
958656
def _almost_equal(a, b):
    
    # arbitrary small number!!!
    threshold = 1e-9
    diff = np.abs(a - b)
    return (diff < threshold)
248788
function compare (options, less, x, y) {
  const ifLess = options.asc ? -1 : 1;

  return less(x, y) ? ifLess
    : less(y, x) ? -ifLess
    : 0;
}
1244702
def index_nearest(value, array):
    

    a = (array-value)**2
    return index(a.min(), a)
64643
@Override
  public int compareTo(@Nonnull B other) {
    int length = Math.min(this.getSegments().size(), other.getSegments().size());
    for (int i = 0; i < length; i++) {
      int cmp = this.getSegments().get(i).compareTo(other.getSegments().get(i));
      if (cmp != 0) {
        return cmp;
      }
    }
    return Integer.compare(this.getSegments().size(), other.getSegments().size());
  }
329557
function SMALLER(tree, n, m) {
		return tree[n].fc < tree[m].fc || (tree[n].fc === tree[m].fc && depth[n] <= depth[m]);
	}
1187961
private static CompareOp reverseCompareOp(CompareOp compareOp) {
    switch (compareOp) {
    case EQUAL:
    case NOT_EQUAL:
    case NO_OP:
      return compareOp;
    case LESS:
      return CompareOp.GREATER;
    case LESS_OR_EQUAL:
      return CompareOp.GREATER_OR_EQUAL;
    case GREATER:
      return CompareOp.LESS;
    case GREATER_OR_EQUAL:
      return CompareOp.LESS_OR_EQUAL;
    default:
      return CompareOp.NO_OP;
    }
  }
476887
def nearest(self, idx):
        """"""
        hi = self.after(idx)
        lo = self.before(idx)
        if hi is None:
            return lo
        if lo is None:
            return hi
        if abs(hi - idx) < abs(lo - idx):
            return hi
        return lo
359692
def smallest(self):
        '''
        
        '''
        if len(self) == 0:
            raise IndexError, "smallest of empty priorityDictionary"
        heap = self.__heap
        while heap[0][1] not in self or self[heap[0][1]] != heap[0][0]:
            lastItem = heap.pop()
            insertionPoint = 0
            while 1:
                smallChild = 2*insertionPoint+1
                if smallChild+1 < len(heap) and heap[smallChild] > heap[smallChild+1] :
                    smallChild += 1
                if smallChild >= len(heap) or lastItem <= heap[smallChild]:
                    heap[insertionPoint] = lastItem
                    break
                heap[insertionPoint] = heap[smallChild]
                insertionPoint = smallChild
        return heap[0][1]
209902
def get_closest(word, possibilities, cutoff=0.6, fallback_to_first=True):
    """"""
    possibilities = list(possibilities)
    try:
        return difflib_get_close_matches(word, possibilities, 1, cutoff)[0]
    except IndexError:
        if fallback_to_first:
            return possibilities[0]
303616
def index_nearest(array, value):
    
    idx = (np.abs(array-value)).argmin()
    return idx
1237085
function closestNumber(arr, num) {
  return arr.reduce((prev, curr) => (Math.abs(curr - num) < Math.abs(prev - num)) ? curr : prev);
}
382927
private int compare(Object key1, Object key2) {
        if (comparator == null)
            return ((Comparable) key1).compareTo(key2);
        else
            return comparator.compare(key1, key2);
    }
1180731
def closest_match(match, specs, depth=0):
    
    new_specs = []
    match_lengths = []
    for i, spec in specs:
        if spec[0] == match[0]:
            new_specs.append((i, spec[1:]))
        else:
            if all(isinstance(s[0], basestring) for s in [spec, match]):
                match_length = max(i for i in range(len(match[0]))
                                   if match[0].startswith(spec[0][:i]))
            elif is_number(match[0]) and is_number(spec[0]):
                match_length = -abs(match[0]-spec[0])
            else:
                match_length = 0
            match_lengths.append((i, match_length, spec[0]))

    if len(new_specs) == 1:
        return new_specs[0][0]
    elif new_specs:
        depth = depth+1
        return closest_match(match[1:], new_specs, depth)
    else:
        if depth == 0 or not match_lengths:
            return None
        else:
            return sorted(match_lengths, key=lambda x: -x[1])[0][0]
854296
public int compareTo (ComparableTuple<L, R> other)
    {
        int rv = ObjectUtil.compareTo(left, other.left);
        return (rv != 0) ? rv : ObjectUtil.compareTo(right, other.right);
    }
904368
def __compare_helper(self, other, condition, notimpl_target):
        
        if not isinstance(other, self.__class__):
            return NotImplemented

        cmp_res = self.__cmp__(other)
        if cmp_res is NotImplemented:
            return notimpl_target

        return condition(cmp_res)
102031
function sortCompare(left, right) {
        var hasj = $hasOwn(left, 0),
            hask = $hasOwn(right, 0),
            typex,
            typey,
            val;

        if (!hasj && !hask) {
            val = +0;
        } else if (!hasj) {
            val = 1;
        } else if (!hask) {
            val = -1;
        } else {
            typex = typeof left[0];
            typey = typeof right[0];
            if (typex === 'undefined' && typey === 'undefined') {
                val = +0;
            } else if (typex === 'undefined') {
                val = 1;
            } else if (typey === 'undefined') {
                val = -1;
            }
        }

        return val;
    }