hmmer-3.3/src/fm_general.c
/* Function:  fm_findOverlappingAmbiguityBlock()
 * Synopsis:  Search in the meta->ambig_list array for the first
 *            ambiguity range starting after <start>. If that index
 *            comes before <end>, return it. Otherwise, return -1.
 */
fm_findOverlappingAmbiguityBlock()
Synopsis:  Search in the meta->ambig_list array for the first
ambiguity range starting after . If that index
comes before , return it. Otherwise, return -1.
fm_findOverlappingAmbiguityBlock () Synopsis : Search in the meta - > ambig_list array for the first ambiguity range starting after . If that index comes before return it . Otherwise return - 1 .
int32_t
fm_findOverlappingAmbiguityBlock (const FM_DATA *fm, const FM_METADATA *meta, uint32_t start, uint32_t end)
{
  int lo = fm->ambig_offset;
  int hi = lo + fm->ambig_cnt - 1;
  int mid;
  FM_INTERVAL *ranges = meta->ambig_list->ranges;
  if (hi <= lo)                   return hi; 
  if (ranges[lo].lower > end)     return -1;
  if (ranges[hi].upper < start)   return -1;
  while (lo < hi) {
    mid = (lo + hi) / 2;  
    if      (ranges[mid].lower   < start)  lo = mid + 1; 
    else                                   hi = mid;    
  }
  if      (lo>0 &&  ranges[lo-1].upper   >= start && ranges[lo-1].lower <= end) return lo-1;
  else if (         ranges[lo].upper     >= start && ranges[lo].lower   <= end) return lo;
  else return -1;
}
int32_t fm_findOverlappingAmbiguityBlock ( const FM_DATA * fm , const FM_METADATA * meta , uint32_t start , uint32_t end ) { int lo = fm -> ambig_offset ; int hi = lo + fm -> ambig_cnt - 1 ; int mid ; FM_INTERVAL * ranges = meta -> ambig_list -> ranges ; if ( hi <= lo ) return hi ; if ( ranges [ lo ] . lower > end ) return -1 ; if ( ranges [ hi ] . upper < start ) return -1 ; while ( lo < hi ) { mid = ( lo + hi ) / 2 ; if ( ranges [ mid ] . lower < start ) lo = mid + 1 ; else hi = mid ; } if ( lo > 0 && ranges [ lo - 1 ] . upper >= start && ranges [ lo - 1 ] . lower <= end ) return lo - 1 ; else if ( ranges [ lo ] . upper >= start && ranges [ lo ] . lower <= end ) return lo ; else return -1 ; }
Function:  fm_findOverlappingAmbiguityBlock()
 Synopsis:  Search in the meta->ambig_list array for the first
            ambiguity range starting after <start>.
Function : fm_findOverlappingAmbiguityBlock () Synopsis : Search in the meta - > ambig_list array for the first ambiguity range starting after <start > .
// (1) Search in the meta->ambig_list array for the last ambiguity range // ending before <start>, using binary search, first handling edge cases: // either 0 or -1 // round down // too far left // might be too far right //the range test above may have pushed the target one too far to the right