binary search cumulative areas array
196560
function binarySearchIndices( value ) {

			function binarySearch( start, end ) {

				// return closest larger index
				// if exact number is not found

				if ( end < start )
					return start;

				var mid = start + Math.floor( ( end - start ) / 2 );

				if ( cumulativeAreas[ mid ] > value ) {

					return binarySearch( start, mid - 1 );

				} else if ( cumulativeAreas[ mid ] < value ) {

					return binarySearch( mid + 1, end );

				} else {

					return mid;

				}

			}

			var result = binarySearch( 0, cumulativeAreas.length - 1 )
			return result;

		}
954586
def all_same_area(self):
        """"""
        all_areas = [x.attrs.get('area', None) for x in self.values()]
        all_areas = [x for x in all_areas if x is not None]
        return all(all_areas[0] == x for x in all_areas[1:])
1111769
function arrayHasAdjacent(values, array) {
    error_if_not_array_1.errorIfNotArray(values);
    if (is_empty_not_empty_1.isEmpty(values))
        return false;
    var indexes = array_get_indexes_1.getIndexesOf(values[0], array);
    var i = -1;
    while (++i < indexes.length) {
        if (indexes[i] + values.length > array.length)
            return false;
        var adjacentItems = array_get_adjacent_at_1.getAdjacentAt(indexes[i], values.length, array);
        if (arrays_match_1.arraysMatch(values, adjacentItems))
            return true;
    }
    return false;
}
855929
function binSearch(test) {
        var i0 = 0;
        var i1 = array.length;
        while (i0 < i1 - 1) {
          var i = Math.trunc((i0 + i1) / 2);
          if (test(i))
            i1 = i;  // Explore the left branch.
          else
            i0 = i;  // Explore the right branch.
        }
        return i1;
      }
1190912
protected int binarySearch(int value) {
		int left = 0;
		int right = size-1;
		while(left <= right) {
			int mid = (left + right)>>1;
			int midValue = elementData[mid];
			if(value==midValue) return mid;
			if(value<midValue) right = mid-1;
			else left = mid+1;
		}
		return -(left+1);
	}
36572
function dary(arity) {

	/**
  * Note that here we reverse the order of the
  * comparison operator since when we extract
  * values from the heap they can only be stored
  * at the end of the array. We thus build a max-heap
  * and then pop elements from it until it is empty.
  */

	var sort = function sort(compare, a, i, j) {

		// construct the max-heap

		var k = i + 1;

		for (; k < j; ++k) {

			var current = k - i;

			// while we are not the root

			while (current !== 0) {

				// address of the parent in a zero-based
				// d-ary heap

				var parent = i + ((current - 1) / arity | 0);
				current += i;

				// if current value is smaller than its parent
				// then we are done

				if (compare(a[current], a[parent]) <= 0) {
					break;
				}

				// otherwise
				// swap with parent

				var tmp = a[current];
				a[current] = a[parent];
				a[parent] = tmp;

				current = parent - i;
			}
		}

		// exhaust the max-heap

		for (--k; k > i; --k) {

			// put max element at the end of the array
			// and percolate new max element down
			// the heap

			var _tmp = a[k];
			a[k] = a[i];
			a[i] = _tmp;

			var _current = 0;

			while (true) {

				// address of the first child in a zero-based
				// d-ary heap

				var candidate = i + arity * _current + 1;

				// if current node has no children
				// then we are done

				if (candidate >= k) {
					break;
				}

				// search for greatest child

				var t = Math.min(candidate + arity, k);

				var y = candidate;

				for (++y; y < t; ++y) {

					if (compare(a[y], a[candidate]) > 0) {
						candidate = y;
					}
				}

				// if current value is greater than its greatest
				// child then we are done

				_current += i;

				if (compare(a[_current], a[candidate]) >= 0) {
					break;
				}

				// otherwise
				// swap with greatest child

				var _tmp2 = a[_current];
				a[_current] = a[candidate];
				a[candidate] = _tmp2;

				_current = candidate - i;
			}
		}
	};

	return sort;
}
1081693
static int binarySearch(final boolean[] a, final boolean key) {
        if (N.isNullOrEmpty(a)) {
            return N.INDEX_NOT_FOUND;
        }

        if (a[0] == key) {
            return 0;
        } else if (a[a.length - 1] != key) {
            return N.INDEX_NOT_FOUND;
        }

        int left = 0, right = a.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;

            if (a[mid] == key) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
1326902
def _binary_search_intervals(cls, intervals, index):
        
        start = 0
        end = len(intervals) - 1
        while start <= end:
            middle_index = start + ((end - start) // 2)
            middle = intervals[middle_index]
            if (middle[0] <= index) and (index < middle[1]):
                return middle
            elif middle[0] > index:
                end = middle_index - 1
            else:
                start = middle_index + 1
        return None
1110611
function insertSorted(arr, item, comparator) {
  var idx = binarySearch(arr, item, comparator);
  arr.splice(idx, 0, item);
}
489109
private static int binarySearch(int[] a, int fromIndex, int length, int key)
    {
        int low = fromIndex;
        int high = fromIndex + length - 1;

        while (low <= high)
        {
            int mid = (low + high) >>> 1;
            int midVal = a[mid << 1];

            if (midVal < key)
                low = mid + 1;
            else if (midVal > key)
                high = mid - 1;
            else
                return mid; // key found
        }
        return -(low + 1);  // key not found.
    }
782757
def _suffixArrayWithTrace(s, SA, n, K, operations, totalOperations):
    
    if _trace:
        _traceSuffixArray(operations, totalOperations)

    n0 = (n + 2) // 3
    n1 = (n + 1) // 3
    n2 = n // 3
    n02 = n0 + n2

    SA12 = _array("i", [0] * (n02 + 3))
    SA0 = _array("i", [0] * n0)
    s0 = _array("i", [0] * n0)

    # s12 : positions of mod 1 and mod 2 suffixes
    s12 = _array("i", [i for i in range(n + (n0 - n1)) if i % 3])  # <- writing i%3 is more efficient than i%3!=0
    s12.extend([0] * 3)

    # lsb radix sort the mod 1 and mod 2 triples
    _radixPass(s12, SA12, s[2:], n02, K)
    if _trace:
        operations += n02
        _traceSuffixArray(operations, totalOperations)

    _radixPass(SA12, s12, s[1:], n02, K)
    if _trace:
        operations += n02
        _traceSuffixArray(operations, totalOperations)

    _radixPass(s12, SA12, s, n02, K)
    if _trace:
        operations += n02
        _traceSuffixArray(operations, totalOperations)

    # find lexicographic names of triples
    name = 0
    c = _array("i", [-1] * 3)
    for i in range(n02):
        cSA12 = s[SA12[i]:SA12[i] + 3]
        if cSA12 != c:
            name += 1
            c = cSA12

        if SA12[i] % 3 == 1:
            s12[SA12[i] // 3] = name  # left half
        else:
            s12[(SA12[i] // 3) + n0] = name  # right half

    if name < n02:  # recurse if names are not yet unique
        operations = _suffixArrayWithTrace(s12, SA12, n02, name + 1, operations, totalOperations)
        if _trace:
            _traceSuffixArray(operations, totalOperations)

        # store unique names in s12 using the suffix array
        for i, SA12_i in enumerate(SA12[:n02]):
            s12[SA12_i] = i + 1
    else:  # generate the suffix array of s12 directly
        if _trace:
            operations += _nbOperations(n02)
            _traceSuffixArray(operations, totalOperations)

        for i, s12_i in enumerate(s12[:n02]):
            SA12[s12_i - 1] = i

    # stably sort the mod 0 suffixes from SA12 by their first character
    j = 0
    for SA12_i in SA12[:n02]:
        if (SA12_i < n0):
            s0[j] = 3 * SA12_i
            j += 1

    _radixPass(s0, SA0, s, n0, K)
    if _trace:
        operations += n0
        _traceSuffixArray(operations, totalOperations)

    # merge sorted SA0 suffixes and sorted SA12 suffixes
    p = j = k = 0
    t = n0 - n1
    while k < n:
        if SA12[t] < n0:  # pos of current offset 12 suffix
            i = SA12[t] * 3 + 1
        else:
            i = (SA12[t] - n0) * 3 + 2

        j = SA0[p]  # pos of current offset 0 suffix

        if SA12[t] < n0:
            bool = (s[i], s12[SA12[t] + n0]) <= (s[j], s12[int(j / 3)])
        else:
            bool = (s[i], s[i + 1], s12[SA12[t] - n0 + 1]) <= (s[j], s[j + 1], s12[int(j / 3) + n0])

        if (bool):
            SA[k] = i
            t += 1
            if t == n02:  # done --- only SA0 suffixes left
                k += 1
                while p < n0:
                    SA[k] = SA0[p]
                    p += 1
                    k += 1

        else:
            SA[k] = j
            p += 1
            if p == n0:  # done --- only SA12 suffixes left
                k += 1
                while t < n02:
                    if SA12[t] < n0:  # pos of current offset 12 suffix
                        SA[k] = (SA12[t] * 3) + 1
                    else:
                        SA[k] = ((SA12[t] - n0) * 3) + 2
                    t += 1
                    k += 1
        k += 1
    return operations
1005760
def find(self, start, end, chrom=None):
        """"""
        intervals = self.intervals[chrom]
        ilen = len(intervals)
        # NOTE: we only search for starts, since any feature that starts within max_len of
        # the query could overlap, we must subtract max_len from the start to get the needed
        # search space. everything else proceeds like a binary search.
        # (but add distance calc for candidates).
        if not chrom in self.max_len: return []
        ileft  = binsearch_left_start(intervals, start - self.max_len[chrom], 0, ilen)
        iright = binsearch_right_end(intervals, end, ileft, ilen)
        query = Feature(start, end)
        # we have to check the distance to make sure we didnt pick up anything 
        # that started within max_len, but wasnt as long as max_len
        return [f for f in intervals[ileft:iright] if distance(f, query) == 0]
185240
function binarySearch(arr, pred) {
    let begin   = -1;
    let end     = arr.length;

    while (1 + begin < end) {
        const mi = begin + ((end - begin) >> 1);

        if (pred(arr[mi]))
            end = mi;
        else
            begin = mi;
    }

    return end;
}
1107475
public static int find(byte[] arra, int start, int limit, byte[] arrb) {

        int k = start;

        limit = limit - arrb.length + 1;

        int value = arrb[0];

        for (; k < limit; k++) {
            if (arra[k] == value) {
                if (arrb.length == 1) {
                    return k;
                }

                if (containsAt(arra, k, arrb)) {
                    return k;
                }
            }
        }

        return -1;
    }
902679
def _binary_search(f, xmin, xmax, eps=1e-9):
    """"""
    middle = (xmax + xmin) / 2.
    while xmax - xmin > eps:
        assert xmin < xmax
        middle = (xmax + xmin) / 2.
        if f(xmax):
            return xmax
        if not f(xmin):
            return xmin
        if f(middle):
            xmin = middle
        else:
            xmax = middle
    return middle
1159473
public static int find(byte[] arra, int start, int limit, int b, int c) {

        int k = 0;

        for (; k < limit; k++) {
            if (arra[k] == b || arra[k] == c) {
                return k;
            }
        }

        return -1;
    }
531810
public static int[] binaryToRgb(boolean[] binaryArray) {
        int[] rgbArray = new int[binaryArray.length];

        for (int i = 0; i < binaryArray.length; i++) {
            if (binaryArray[i]) {
                rgbArray[i] = 0x00000000;
            } else {
                rgbArray[i] = 0x00FFFFFF;
            }
        }
        return rgbArray;
    }