3rd_party/hmmer-3.1b2-linux-intel-x86_64/src/fm_general.c
/* Function:  fm_computeSequenceOffset()
 * Synopsis:  Search in the meta->seq_data array for the sequence id corresponding to the
 *            requested position. The matching entry is the one with the largest index i
 *            such that seq_data[i].offset < pos
 */
fm_computeSequenceOffset()
Synopsis:  Search in the meta->seq_data array for the sequence id corresponding to the
requested position. The matching entry is the one with the largest index i
such that seq_data[i].offset < pos
fm_computeSequenceOffset () Synopsis : Search in the meta - > seq_data array for the sequence id corresponding to the requested position . The matching entry is the one with the largest index i such that seq_data [ i ] . offset < pos
uint64_t
fm_computeSequenceOffset (const FM_DATA *fms, const FM_METADATA *meta, int block, uint64_t pos)
{
  uint64_t lo = fms[block].seq_offset;
  uint64_t hi  = lo + fms[block].seq_cnt - 1;
  uint64_t mid;
  if (lo==hi)                             return lo;
  if (meta->seq_data[hi].fm_start <= pos) return hi;
  while (1) {
    mid = (lo + hi + 1) / 2;  
    if      (meta->seq_data[mid].fm_start <= pos) lo = mid; 
    else if (meta->seq_data[mid-1].fm_start > pos) hi = mid; 
    else return mid-1;                 
  }
}
uint64_t fm_computeSequenceOffset ( const FM_DATA * fms , const FM_METADATA * meta , int block , uint64_t pos ) { uint64_t lo = fms [ block ] . seq_offset ; uint64_t hi = lo + fms [ block ] . seq_cnt - 1 ; uint64_t mid ; if ( lo == hi ) return lo ; if ( meta -> seq_data [ hi ] . fm_start <= pos ) return hi ; while ( 1 ) { mid = ( lo + hi + 1 ) / 2 ; if ( meta -> seq_data [ mid ] . fm_start <= pos ) lo = mid ; else if ( meta -> seq_data [ mid - 1 ] . fm_start > pos ) hi = mid ; else return mid - 1 ; } }
Function:  fm_computeSequenceOffset()
 Synopsis:  Search in the meta->seq_data array for the sequence id corresponding to the
            requested position.
Function : fm_computeSequenceOffset () Synopsis : Search in the meta - > seq_data array for the sequence id corresponding to the requested position .
//binary search, first handling edge cases /* round up */ /* too far left  */ /* too far right */ /* found it */