starts with binary search and finishes with a sequential search
545739
protected static int hybridUnsignedBinarySearch(final short[] array, final int begin,
      final int end, final short k) {
    int ikey = toIntUnsigned(k);
    // next line accelerates the possibly common case where the value would
    // be inserted at the end
    if ((end > 0) && (toIntUnsigned(array[end - 1]) < ikey)) {
      return -end - 1;
    }
    int low = begin;
    int high = end - 1;
    // 32 in the next line matches the size of a cache line
    while (low + 32 <= high) {
      final int middleIndex = (low + high) >>> 1;
      final int middleValue = toIntUnsigned(array[middleIndex]);

      if (middleValue < ikey) {
        low = middleIndex + 1;
      } else if (middleValue > ikey) {
        high = middleIndex - 1;
      } else {
        return middleIndex;
      }
    }
    // we finish the job with a sequential search
    int x = low;
    for (; x <= high; ++x) {
      final int val = toIntUnsigned(array[x]);
      if (val >= ikey) {
        if (val == ikey) {
          return x;
        }
        break;
      }
    }
    return -(x + 1);
  }
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.
    }
689127
private int searchInternal(Composite name, int startIdx)
    {
        if (isEmpty())
            return -1;

        int pos = Arrays.binarySearch(starts, startIdx, size, name, comparator);
        if (pos >= 0)
        {
            // We're exactly on an interval start. The one subtility is that we need to check if
            // the previous is not equal to us and doesn't have a higher marked at
            if (pos > 0 && comparator.compare(name, ends[pos-1]) == 0 && markedAts[pos-1] > markedAts[pos])
                return pos-1;
            else
                return pos;
        }
        else
        {
            // We potentially intersect the range before our "insertion point"
            int idx = -pos-2;
            if (idx < 0)
                return -1;

            return comparator.compare(name, ends[idx]) <= 0 ? idx : -idx-2;
        }
    }
699495
function isAtStart(string, index) {
  const before = string.substring(0, index).trim();

  return before.length === 0 || before.search(/[({,]$/) !== -1;
}
294052
function search(root, test, skip, callback) {
  var index = -1
  var children = root.children
  var length = children.length
  var depth = null
  var start = null
  var end = null
  var nodes
  var clean
  var child

  while (++index < length) {
    child = children[index]

    if (closing(child, depth)) {
      end = index
      break
    }

    if (opening(child, depth, test)) {
      start = index
      depth = child.depth
    }
  }

  if (start !== null) {
    if (end === null) {
      end = length
    }

    if (skip) {
      while (end > start) {
        child = children[end - 1]

        if (!definition(child)) {
          break
        }

        end--
      }
    }

    nodes = callback(
      children[start],
      children.slice(start + 1, end),
      children[end],
      {
        parent: root,
        start: start,
        end: children[end] ? end : null
      }
    )

    clean = []
    index = -1
    length = nodes && nodes.length

    // Ensure no empty nodes are inserted.  This could be the case if `end` is
    // in `nodes` but no `end` node exists.
    while (++index < length) {
      if (nodes[index]) {
        clean.push(nodes[index])
      }
    }

    if (nodes) {
      splice.apply(children, [start, end - start + 1].concat(clean))
    }
  }
}
1336490
def binary_search(pVector, pElement)
      pVector.bsearch { |obj| pElement.name <=> obj.name }
    end
675801
public static int binarySearch(byte[] a, int key) {
        int low = 0;
        int high = a.length;

        while (low < high) {
            int mid = (low + high) >>> 1;
            if (mid % 4 != 0) {
                if (high == a.length) {
                    mid = low;
                } else {
                    mid = high;
                }
            }
            int midVal = getInt(a, mid);

            if (midVal < key)
                low = mid + 4;
            else if (midVal > key)
                high = mid - 4;
            else
                return mid; // key found
        }
        if (low == a.length) {
            return low;
        }
        return key > getInt(a, low) ? low + 4 : low;

    }
1238883
static int binarySearch(long keys[], int start, int len, long key) {
        int high = start + len, low = start - 1, guess;
        while (high - low > 1) {
            // use >>> for average or we could get an integer overflow.
            guess = (high + low) >>> 1;
            long guessedKey = keys[guess];
            if (guessedKey < key) {
                low = guess;
            } else {
                high = guess;
            }
        }

        if (high == start + len) {
            return ~(start + len);
        }

        long highKey = keys[high];
        if (highKey == key) {
            return high;
        } else {
            return ~high;
        }
    }
801269
def find_first_match(basedir, string):
    
    matches = find(basedir, string)
    return matches[0] if matches else matches
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;

		}
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;
    }
43724
protected int binarySearch (int x)
    {
        // copied from java.util.Arrays which I wouldn't have to have done had the provided a
        // means by which to binarySearch in a subset of an array. alas.
        int low = 0;
        int high = _size-1;

        while (low <= high) {
            int mid = (low + high) >>> 1;
            int cmp = (_records[mid].x - x);

            if (cmp < 0) {
                low = mid + 1;
            } else if (cmp > 0) {
                high = mid - 1;
            } else {
                return mid; // key found
            }
        }

        return low;  // key not found
    }
783037
private static int unsignedBinarySearch(int[] a, int fromIndex, int toIndex, int key,
      Comparator<? super Integer> c) {
    int low = fromIndex;
    int high = toIndex - 1;

    while (low <= high) {
      int mid = (low + high) >>> 1;
      int midVal = a[mid];
      int cmp = c.compare(midVal, key);
      if (cmp < 0) {
        low = mid + 1;
      } else if (cmp > 0) {
        high = mid - 1;
      } else {
        return mid; // key found
      }
    }
    return -(low + 1); // key not found.
  }
1077846
private int binarySearch(int position) {
		int[] minSeqIndex = getMinSequenceIndex();
		int[] maxSeqIndex = getMaxSequenceIndex();

		int low = 0;
		int high = minSeqIndex.length - 1;
		while (low <= high) {
			//Go to the mid point in the array
			int mid = (low + high) >>> 1;

			//Get the max position represented by this Sequence
			int midMinPosition = minSeqIndex[mid];
			int midMaxPosition = maxSeqIndex[mid];

			//if current position is greater than the current bounds then
			//increase search space
			if (midMinPosition < position && midMaxPosition < position) {
				low = mid + 1;
			} //if current position is less than current bounds then decrease
			//search space
			else if (midMinPosition > position && midMaxPosition > position) {
				high = mid - 1;
			} else {
				return mid;
			}
		}
		throw new IndexOutOfBoundsException("Given position " + position + " does not map into this Sequence");
	}
455240
def binsearch(reader, key, compare_func=cmp, block_size=8192):
    

    min_ = binsearch_offset(reader, key, compare_func, block_size)

    reader.seek(min_)

    if min_ > 0:
        reader.readline()  # skip partial line

    def gen_iter(line):
        while line:
            yield line.rstrip()
            line = reader.readline()

    return gen_iter(reader.readline())
265342
def next(self, match, predicate=None, index=None):
        
        current = match.start + 1
        while current <= self._max_end:
            next_matches = self.starting(current)
            if next_matches:
                return filter_index(next_matches, predicate, index)
            current += 1
        return filter_index(_BaseMatches._base(), predicate, index)
24654
def search_worker(self, regex, directory_path, names, binary=False,
                      callback=None):
        
        try:
            result = DirectoryResult(directory_path)
            def find_matches(name):
                full_path = path.join(directory_path, name)
                file_contents = get_file_contents(full_path, binary)
                start = 0
                match = regex.search(file_contents, start)
                while match:
                    result.put(name, file_contents, match)
                    start = match.end()
                    match = regex.search(file_contents, start)
            for name in names:
                try:
                    find_matches(name)
                except IOError:
                    pass
            if callback:
                callback(result)
        except KeyboardInterrupt, e:
            exit(1)