private int indexedBinarySearch(List<S2CellId> l,S2CellId key,int low){
  int high=l.size() - 1;
  while (low <= high) {
    int mid=(low + high) >> 1;
    S2CellId midVal=l.get(mid);
    int cmp=midVal.compareTo(key);
    if (cmp < 0) {
      low=mid + 1;
    }
 else     if (cmp > 0) {
      high=mid - 1;
    }
 else {
      return mid;
    }
  }
  return low;
}

private int indexedBinarySearch ( List < S2CellId > l , S2CellId key , int low ) { int high = l . size ( ) - 1 ; while ( low <= high ) { int mid = ( low + high ) > > 1 ; S2CellId midVal = l . get ( mid ) ; int cmp = midVal . compareTo ( key ) ; if ( cmp < 0 ) { low = mid + 1 ; } else if ( cmp > 0 ) { high = mid - 1 ; } else { return mid ; } } return low ; }
just as normal binary search , except that it allows specifying the starting value for the lower bound .
