deps/kb_meme/meme-5.0.1/src/buffer.c
/*
 * buf_bm_search
 * Boyer-Moore search
 * moves the buffer forward to the first match or partial
 * match. Returns the index of the matched string or 
 * negative min chars to match.
 * If a partial match starts before a full match, the 
 * algorithm will return the partial.
 */
buf_bm_search
Boyer-Moore search
moves the buffer forward to the first match or partial
match. Returns the index of the matched string or
negative min chars to match.
If a partial match starts before a full match, the
algorithm will return the partial.
buf_bm_search Boyer - Moore search moves the buffer forward to the first match or partial match . Returns the index of the matched string or negative min chars to match . If a partial match starts before a full match the algorithm will return the partial .
int buf_bm_search(BUF_T *buf, int count, BMSTR_T **strings) {
  int len, i, pos, pos_stm, left_i, left, left_stm;
  char *txt;
  txt = (buf->buffer)+(buf->position);
  len = (buf->limit - buf->position);
  left_i = -1;
  left = 0;
  left_stm = 0;
  for (i = 0; i < count; ++i) {
    pos = bmstr_substring(strings[i], txt, len);
    if (pos < 0) {
      pos = -(pos + 1);
      pos_stm = bmstr_length(strings[i]) - (len - pos);
    } else {
      pos_stm = 0;
    }
    if (left_i == -1 || pos < left) {
      left_i = i;
      left = pos;
      left_stm = pos_stm;
    }
  }
  if (left_i == -1) {
    return -1;
  } else {
    buf->position += left;
    if (left_stm) return -left_stm;
    return left_i;
  }
}
int buf_bm_search ( BUF_T * buf , int count , BMSTR_T * * strings ) { int len , i , pos , pos_stm , left_i , left , left_stm ; char * txt ; txt = ( buf -> buffer ) + ( buf -> position ) ; len = ( buf -> limit - buf -> position ) ; left_i = -1 ; left = 0 ; left_stm = 0 ; for ( i = 0 ; i < count ; ++ i ) { pos = bmstr_substring ( strings [ i ] , txt , len ) ; if ( pos < 0 ) { pos = - ( pos + 1 ) ; pos_stm = bmstr_length ( strings [ i ] ) - ( len - pos ) ; } else { pos_stm = 0 ; } if ( left_i == -1 || pos < left ) { left_i = i ; left = pos ; left_stm = pos_stm ; } } if ( left_i == -1 ) { return -1 ; } else { buf -> position += left ; if ( left_stm ) return - left_stm ; return left_i ; } }
buf_bm_search
 Boyer-Moore search
 moves the buffer forward to the first match or partial
 match.
buf_bm_search Boyer - Moore search moves the buffer forward to the first match or partial match .
//stop compilier complaining about uninitilized vars //this should only happen if count is zero, which shouldn't happen