hmmer-3.3/easel/esl_sq.c
/* Function:  esl_sq_Grow()
 * Synopsis:  Assure that a <ESL_SQ> has space to add more residues.
 * Incept:    SRE, Wed Jan 10 08:26:23 2007 [Janelia]
 *
 * Purpose:   Assure that the sequence <sq> can hold at least
 *            one more residue, whether in digital or text mode.
 *            Reallocate if necessary. Optionally returns the number
 *            of residues that can be added before the next call
 *            to <esl_sq_Grow()> in <opt_nsafe>.
 *            
 *            The terminal <NUL> or sentinel count as a residue for
 *            allocation purposes: that is, you may need to call
 *            <esl_sq_Grow()> before terminating a new sequence.
 *
 * Returns:   <eslOK> on success.
 *
 * Throws:    <eslEMEM> on reallocation failure. In this case, the
 *            original <sq> is untouched, and <*opt_nsafe> is returned
 *            as 0.
 *
 * Xref:      STL11/125.
 */
esl_sq_Grow()
Synopsis:  Assure that a  has space to add more residues.

Assure that the sequence  can hold at least
one more residue, whether in digital or text mode.
Reallocate if necessary. Optionally returns the number
of residues that can be added before the next call
to  in .

The terminal  or sentinel count as a residue for
allocation purposes: that is, you may need to call
 before terminating a new sequence.

 on success.

 on reallocation failure. In this case, the
original  is untouched, and <*opt_nsafe> is returned
as 0.


esl_sq_Grow () Synopsis : Assure that a has space to add more residues . Assure that the sequence can hold at least one more residue whether in digital or text mode . Reallocate if necessary . Optionally returns the number of residues that can be added before the next call to in . The terminal or sentinel count as a residue for allocation purposes : that is you may need to call before terminating a new sequence . on success . on reallocation failure . In this case the original is untouched and < * opt_nsafe > is returned as 0 .
int
esl_sq_Grow(ESL_SQ *sq, int64_t *opt_nsafe)
{
  void   *tmp;
  int64_t new;
  int64_t nsafe;
  int     x;       
  int     status;
  if (sq->seq != NULL)  nsafe = sq->salloc     - sq->n;     
  else                  nsafe = (sq->salloc-1) - sq->n;     
  if (nsafe < 1)
    {  
      new = sq->salloc;
      do { nsafe += new; new*=2; } while (nsafe < 1);
      if (sq->seq != NULL) ESL_RALLOC(sq->seq, tmp, new * sizeof(char));	
      else                 ESL_RALLOC(sq->dsq, tmp, new * sizeof(ESL_DSQ));	
      if (sq->ss != NULL)  ESL_RALLOC(sq->ss,  tmp, new * sizeof(char));
      for (x = 0; x < sq->nxr; x++) 
	if (sq->xr[x] != NULL)  ESL_RALLOC(sq->xr[x],  tmp, new * sizeof(char));
      sq->salloc = new;
    }
  if (opt_nsafe != NULL) *opt_nsafe = nsafe;
  return eslOK;
 ERROR:
  if (opt_nsafe != NULL) *opt_nsafe = 0;
  return status;
}
int esl_sq_Grow ( ESL_SQ * sq , int64_t * opt_nsafe ) { void * tmp ; int64_t new ; int64_t nsafe ; int x ; int status ; if ( sq -> seq != NULL ) nsafe = sq -> salloc - sq -> n ; else nsafe = ( sq -> salloc - 1 ) - sq -> n ; if ( nsafe < 1 ) { new = sq -> salloc ; do { nsafe += new ; new *= 2 ; } while ( nsafe < 1 ) ; if ( sq -> seq != NULL ) ESL_RALLOC ( sq -> seq , tmp , new * sizeof ( char ) ) ; else ESL_RALLOC ( sq -> dsq , tmp , new * sizeof ( ESL_DSQ ) ) ; if ( sq -> ss != NULL ) ESL_RALLOC ( sq -> ss , tmp , new * sizeof ( char ) ) ; for ( x = 0 ; x < sq -> nxr ; x ++ ) if ( sq -> xr [ x ] != NULL ) ESL_RALLOC ( sq -> xr [ x ] , tmp , new * sizeof ( char ) ) ; sq -> salloc = new ; } if ( opt_nsafe != NULL ) * opt_nsafe = nsafe ; return eslOK ; ERROR : if ( opt_nsafe != NULL ) * opt_nsafe = 0 ; return status ; }
Function:  esl_sq_Grow()
 Synopsis:  Assure that a <ESL_SQ> has space to add more residues.
Function : esl_sq_Grow () Synopsis : Assure that a <ESL_SQ > has space to add more residues .
/* index for optional extra residue markups */ /* text */ /* digital: -1 because 0 is a sentinel       */ /* reallocate by doubling (shouldn't need more, but if we do, keep doubling) */ /* text    */ /* digital */