rEFIt_UEFI/libeg/lodepng.cpp
/*search the index in the array, that has the largest value smaller than or equal to the given value,
given array must be sorted (if no value is smaller, it returns the size of the given array)*/
search the index in the array, that has the largest value smaller than or equal to the given value,
given array must be sorted (if no value is smaller, it returns the size of the given array)
search the index in the array that has the largest value smaller than or equal to the given value given array must be sorted ( if no value is smaller it returns the size of the given array )
static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value) {
  size_t left = 1;
  size_t right = array_size - 1;
  while(left <= right) {
    size_t mid = (left + right) >> 1;
    if(array[mid] >= value) right = mid - 1;
    else left = mid + 1;
  }
  if(left >= array_size || array[left] > value) left--;
  return left;
}
static size_t searchCodeIndex ( const unsigned * array , size_t array_size , size_t value ) { size_t left = 1 ; size_t right = array_size - 1 ; while ( left <= right ) { size_t mid = ( left + right ) >> 1 ; if ( array [ mid ] >= value ) right = mid - 1 ; else left = mid + 1 ; } if ( left >= array_size || array [ left ] > value ) left -- ; return left ; }
search the index in the array, that has the largest value smaller than or equal to the given value,
given array must be sorted (if no value is smaller, it returns the size of the given array)
search the index in the array that has the largest value smaller than or equal to the given value given array must be sorted ( if no value is smaller it returns the size of the given array )
/*binary search (only small gain over linear). TODO: use CPU log2 instruction for getting symbols instead*/