Пример #1
0
static void
gt_ht_reinit(GtHashtable *ht, HashElemInfo table_info, unsigned short size_log,
             unsigned short high_mul, unsigned short low_mul)
{
  htsize_t table_size;
  gt_assert(high_mul > low_mul);
  gt_assert(low_mul > 0 && high_mul < FILL_DIVISOR);
  ht->table_info = table_info;
  ht->table_size_log = size_log;
  ht->table_mask = (table_size = 1 << size_log) - 1;
  ht->table = gt_realloc(ht->table, table_info.elem_size * table_size);
  ht->high_fill_mul = high_mul;
  ht->high_fill
    = (unsigned long long)ht->high_fill_mul * table_size / FILL_DIVISOR;
  ht->low_fill_mul = low_mul;
  ht->low_fill
    = (unsigned long long)ht->low_fill_mul * table_size / FILL_DIVISOR;
  {
    uint32_t i;
    ht->links.table = gt_realloc(ht->links.table,
                                 sizeof (*(ht->links.table)) * table_size);
    for (i = 0; i < table_size; ++i)
      ht->links.table[i] = free_mark;
    ht->get_link = gt_ht_get_table_link;
    ht->set_link = gt_ht_set_table_link;
  }
}
Пример #2
0
GtIntset *gt_intset_16_io_fp(GtIntset *intset, FILE *fp, GtError *err,
                                    GtIOFunc io_func)
{
  int had_err = 0;
  GtUword type = (GtUword) GT_INTSET_16_TYPE;
  GtIntset16 *intset_16;
  GtIntsetMembers *members;

  gt_error_check(err);

  intset_16 = gt_intset_16_cast(intset);

  had_err = gt_intset_16_io_one(type);
  if (!had_err && type != GT_INTSET_16_TYPE) {
    /* only applies to reading */
    had_err = 1;
    gt_error_set(err, "Trying to read GtIntset16 from file,"
                 " type does not match!");
  }
  if (!had_err) {
    members = intset->members;
    had_err = gt_intset_16_io_one(members->currentsectionnum);
    if (!had_err)
      had_err = gt_intset_16_io_one(members->maxelement);
    if (!had_err)
      had_err = gt_intset_16_io_one(members->nextfree);
    if (!had_err)
      had_err = gt_intset_16_io_one(members->num_of_elems);
    if (!had_err)
      had_err = gt_intset_16_io_one(members->previouselem);
    if (!had_err) {
      members->logsectionsize = GT_BITS_FOR_TYPE(uint16_t);
      members->numofsections = GT_ELEM2SECTION_M(members->maxelement) + 1;
      members->sectionstart = gt_realloc(members->sectionstart,
                sizeof (*members->sectionstart) * (members->numofsections + 1));
    }
    had_err = io_func(members->sectionstart, sizeof (*members->sectionstart),
                      (size_t) (members->numofsections + 1), fp, err);
    if (!had_err && members->sectionstart[0] != 0) {
      had_err = 1;
      gt_error_set(err, "Unexpected value in sectionstart[0]: "
                   GT_WU " expected 0!", members->sectionstart[0]);
    }
  }
  if (!had_err) {
    intset_16->elements = gt_realloc(intset_16->elements,
                  sizeof (*intset_16->elements) * members->num_of_elems);
    had_err = io_func(intset_16->elements,
                      sizeof (*intset_16->elements),
                      (size_t) members->num_of_elems, fp, err);
  }
  if (had_err) {
    gt_intset_16_delete(intset);
    intset = NULL;
  }
  return intset;

}
Пример #3
0
/* resize space */
static void gt_linspace_management_check_generic(GtLinspaceManagement
                                                 *spacemanager,
                                                 GtUword ulen, GtUword vlen,
                                                 size_t valuesize,
                                                 size_t rtabsize,
                                                 size_t crosspointsize,
                                                 bool local)
{
  size_t space = 0, localspace = 0; /* space in bytes */
  /*if (spacemanager == NULL)
    spacemanager = gt_new_linspace_management();*/

  gt_assert(spacemanager != NULL);

  if (spacemanager->valueTabsize < (ulen+1)*valuesize)
  {
    spacemanager->valueTabspace = gt_realloc(spacemanager->valueTabspace,
                                            (ulen+1)*valuesize);
    spacemanager->valueTabsize = (ulen+1)*valuesize;
  }

  if (spacemanager->rTabsize < (ulen+1)*rtabsize)
  {
    spacemanager->rTabspace = gt_realloc(spacemanager->rTabspace,
                                        (ulen+1)*rtabsize);
    spacemanager->rTabsize = (ulen+1)*rtabsize;
  }
  if (spacemanager->crosspointTabsize < (vlen+1)*crosspointsize)
  {
    spacemanager->crosspointTabspace =
           gt_realloc(spacemanager->crosspointTabspace,(vlen+1)*crosspointsize);
    spacemanager->crosspointTabsize = (vlen+1)*crosspointsize;
  }
  if (local)
  {
    if (spacemanager->maxscoordvaluespace == NULL)
      spacemanager->maxscoordvaluespace = gt_maxcoordvalue_new();
    else
      gt_maxcoordvalue_reset(spacemanager->maxscoordvaluespace);
  }
  if (spacemanager->maxscoordvaluespace != NULL)
    localspace = 2 * sizeof (GtUwordPair) + sizeof (GtWord);
            /* = sizeof (GtMaxcoordvalue)*/

  /* determine space peak */
  space = spacemanager->valueTabsize + spacemanager->rTabsize +
          spacemanager->crosspointTabsize + localspace;

  if (space > spacemanager->spacepeak)
    spacemanager->spacepeak = space;
}
Пример #4
0
void
SRLCompact(struct seqRangeList *rangeList)
{
  gt_assert(rangeList);
  rangeList->ranges = gt_realloc(rangeList->ranges,
                                 sizeof (rangeList->ranges[0])
                                 * rangeList->numRanges);
  if (rangeList->partialSymSums)
    rangeList->partialSymSums =
      gt_realloc(rangeList->partialSymSums, sizeof (Seqpos)
                 * MRAEncGetSize(rangeList->alphabet)
                 * rangeList->numRanges);
  rangeList->numRangesStorable = rangeList->numRanges;
}
static GtUchar sequenceobject_get_char(Sequenceobject *seq,GtUword pos)
{
  if (seq->twobitencoding != NULL)
  {
    return gt_twobitencoding_char_at_pos(seq->twobitencoding,
                                         seq->forward ? seq->startpos + pos
                                                      : seq->startpos - pos);
  }
  if (seq->encseqreader != NULL)
  {
    const GtUword addamount = 256UL;

    if (seq->min_access_pos != GT_UWORD_MAX &&
        seq->min_access_pos >= seq->cache_offset + addamount)
    {
      GtUword idx, end = MIN(seq->cache_num_positions,seq->substringlength);
      GtUchar *cs = ((GtUchar *) seq->sequence_cache->space)
                    - seq->min_access_pos;

      for (idx = seq->min_access_pos; idx < end; idx++)
      {
        cs[idx] = seq->cache_ptr[idx];
      }
      seq->cache_offset = seq->min_access_pos;
      seq->cache_ptr = ((GtUchar *) seq->sequence_cache->space)
                       - seq->cache_offset;
    }
    if (pos >= seq->cache_num_positions)
    {
      GtUword idx, tostore;

      tostore = MIN(seq->cache_num_positions + addamount,seq->substringlength);
      if (tostore > seq->cache_offset + seq->sequence_cache->allocated)
      {
        seq->sequence_cache->allocated += addamount;
        seq->sequence_cache->space
          = gt_realloc(seq->sequence_cache->space,
                       sizeof (GtUchar) * seq->sequence_cache->allocated);
        seq->cache_ptr = ((GtUchar *) seq->sequence_cache->space)
                         - seq->cache_offset;
      }
      gt_assert(pos >= seq->cache_offset);
      for (idx = seq->cache_num_positions; idx < tostore; idx++)
      {
        seq->cache_ptr[idx]
          = gt_encseq_reader_next_encoded_char(seq->encseqreader);
      }
      seq->cache_num_positions = tostore;
    }
    gt_assert(pos < seq->cache_offset + seq->sequence_cache->allocated);
    gt_assert(seq->cache_ptr != NULL);
    return seq->cache_ptr[pos];
  }
  gt_assert(seq->encseq != NULL);
  gt_assert(seq->forward || seq->startpos >= pos);
  return gt_encseq_get_encoded_char(seq->encseq,
                                    seq->forward ? seq->startpos + pos
                                                 : seq->startpos - pos,
                                    GT_READMODE_FORWARD);
}
Пример #6
0
static size_t gt_tableoflcpvalues_realloc(GtLcpvalues *tableoflcpvalues,
                                          GtUword numoflcpvalues)
{
  if (numoflcpvalues > tableoflcpvalues->numofentries)
  {
    size_t sizeofinfo;

    tableoflcpvalues->bucketoflcpvalues
      = gt_realloc(tableoflcpvalues->bucketoflcpvalues,
                   sizeof (*tableoflcpvalues->bucketoflcpvalues) *
                   numoflcpvalues);
    sizeofinfo = sizeof (*tableoflcpvalues->bucketoflcpvalues) *
                         (numoflcpvalues - tableoflcpvalues->numofentries);
#ifndef NDEBUG
    GT_INITBITTABGENERIC(tableoflcpvalues->isset,
                         tableoflcpvalues->isset,
                         numoflcpvalues);
#endif
    sizeofinfo += GT_NUMOFINTSFORBITS(numoflcpvalues -
                                      tableoflcpvalues->numofentries)
                  * sizeof (GtBitsequence);
    tableoflcpvalues->numoflargelcpvalues = 0;
    tableoflcpvalues->numofentries = numoflcpvalues;
    tableoflcpvalues->lcptaboffset = 0;
    return sizeofinfo;
  }
  return 0;
}
Пример #7
0
static void adddistributionuint64_t(GtArrayuint64_t *occdistribution,
                                    unsigned long countocc,
                                    unsigned long value)
{
    if (countocc >= occdistribution->allocateduint64_t)
    {
        const unsigned long addamount = 128UL;
        unsigned long idx;

        occdistribution->spaceuint64_t
            = gt_realloc(occdistribution->spaceuint64_t,
                         sizeof *occdistribution->spaceuint64_t *
                         (countocc+addamount));
        for (idx=occdistribution->allocateduint64_t;
                idx<countocc+addamount; idx++)
        {
            occdistribution->spaceuint64_t[idx] = 0;
        }
        occdistribution->allocateduint64_t = countocc+addamount;
    }
    if (countocc + 1 > occdistribution->nextfreeuint64_t)
    {
        occdistribution->nextfreeuint64_t = countocc+1;
    }
    occdistribution->spaceuint64_t[countocc] += value;
}
Пример #8
0
static void incrementdistribcounts(GtArrayCountwithpositions *occdistribution,
                                   GtUword countocc,GtUword value)
{
  if (countocc >= occdistribution->allocatedCountwithpositions)
  {
    const GtUword addamount = 128UL;
    GtUword idx;

    occdistribution->spaceCountwithpositions
      = gt_realloc(occdistribution->spaceCountwithpositions,
                   sizeof *occdistribution->spaceCountwithpositions
                   * (countocc+addamount));
    for (idx=occdistribution->allocatedCountwithpositions;
         idx<countocc+addamount; idx++)
    {
      occdistribution->spaceCountwithpositions[idx].occcount = 0;
      occdistribution->spaceCountwithpositions[idx].positionlist = NULL;
    }
    occdistribution->allocatedCountwithpositions = countocc+addamount;
  }
  if (countocc + 1 > occdistribution->nextfreeCountwithpositions)
  {
    occdistribution->nextfreeCountwithpositions = countocc+1;
  }
  occdistribution->spaceCountwithpositions[countocc].occcount += value;
}
Пример #9
0
const char *gt_condenseq_extract_decoded_range(GtCondenseq *condenseq,
                                               GtRange range,
                                               char separator)
{
  GtUword length = range.end - range.start + 1,
          idx;
  const GtUchar *ubuf;
  char *buf;
  gt_assert(range.start <= range.end);
  ubuf = gt_condenseq_extract_encoded_range(condenseq, range);
  if (condenseq->buffer == NULL || condenseq->buffsize < length) {
    condenseq->buffer = gt_realloc(condenseq->buffer,
                                   sizeof (*condenseq->buffer) * length);
    condenseq->buffsize = length;
  }
  buf = condenseq->buffer;
  for (idx = 0; idx < length; ++idx) {
    if (ubuf[idx] == SEPARATOR) {
      buf[idx] = separator;
    }
    else {
      buf[idx] = gt_alphabet_decode(condenseq->alphabet, ubuf[idx]);
    }
  }
  return buf;
}
Пример #10
0
void front_trace_add_trace(GtFrontTrace *front_trace,
                           uint8_t backreference,
                           uint32_t localmatch_count)
{
  gt_assert (front_trace != NULL);
  if (front_trace->backref_nextfree >= front_trace->backref_allocated)
  {
    front_trace->backref_allocated
      = front_trace->backref_allocated * 1.2 + 128UL;
    front_trace->backref_table
      = gt_realloc(front_trace->backref_table,
                   sizeof *front_trace->backref_table
                   * front_trace->backref_allocated);
    gt_assert(front_trace->backref_table != NULL);
  }
  gt_assert(front_trace->backref_nextfree < front_trace->backref_allocated);
  front_trace->backref_table[front_trace->backref_nextfree].bits
    = backreference;
  gt_assert(localmatch_count <= front_trace->maxlcs);
  front_trace->backref_table[front_trace->backref_nextfree++].lcs
    = localmatch_count;
#ifdef WITHDISTRIBUTION
  distribution_add(front_trace->lcs_dist,lcs);
#endif
}
Пример #11
0
void gt_ft_trimstat_add(GtFtTrimstat *trimstat,
                        bool diedout,
                        GtUword sumvalid,
                        GtUword maxvalid,
                        GtUword d,
                        size_t spaceforfront)
{
  if (trimstat == NULL)
  {
    return;
  }
  if (trimstat->show_distance)
  {
    if (diedout)
    {
      printf("inf\n");
    } else
    {
      printf(GT_WU "\n",d);
    }
  }
  while (maxvalid >= trimstat->maxvalid_dist.allocatedGtUword)
  {
    GtUword idx;
    const GtUword allocated = trimstat->maxvalid_dist.allocatedGtUword;

    trimstat->maxvalid_dist.allocatedGtUword
      = trimstat->maxvalid_dist.allocatedGtUword * 1.2 + 128UL;
    trimstat->maxvalid_dist.spaceGtUword
      = gt_realloc(trimstat->maxvalid_dist.spaceGtUword,
                   sizeof *trimstat->maxvalid_dist.spaceGtUword *
                   trimstat->maxvalid_dist.allocatedGtUword);
    for (idx = allocated; idx < trimstat->maxvalid_dist.allocatedGtUword; idx++)
    {
      trimstat->maxvalid_dist.spaceGtUword[idx] = 0;
    }
  }
  gt_assert(maxvalid < trimstat->maxvalid_dist.allocatedGtUword);
  trimstat->maxvalid_dist.spaceGtUword[maxvalid]++;
  if (diedout)
  {
    trimstat->diedout++;
  } else
  {
    const GtUword fullfronts = (d+1) * (d+1);
    GtUword percentage;

    percentage
      = (GtUword) (100.0 * (double) (fullfronts - sumvalid)/fullfronts);
    gt_assert(percentage <= 100UL);
    trimstat->sum_meanvalid += (double) sumvalid/(d+1);
    trimstat->trim_dist[percentage]++;
    GT_CHECKARRAYSPACE(&trimstat->distance_dist,GtUword,32);
    trimstat->distance_dist.spaceGtUword[trimstat->
                                         distance_dist.nextfreeGtUword++] = d;
    trimstat->spaceforfront_total += spaceforfront;
  }
}
Пример #12
0
static void* test_realloc(GT_UNUSED void *data)
{
  GtArray *chunks;
  unsigned int i;
  void *mem;
  chunks = gt_array_new(sizeof (void*));
  for (i = 0; i < NUMBER_OF_ALLOCS; i++) {
    mem = gt_realloc(NULL, SIZE_OF_ALLOCS / 2);
    mem = gt_realloc(mem, SIZE_OF_ALLOCS / 2);
    gt_array_add(chunks, mem);
  }
  for (i = 0; i < NUMBER_OF_ALLOCS; i++) {
    mem = *(void**) gt_array_get(chunks, i);
    gt_free(mem);
  }
  gt_array_delete(chunks);
  return NULL;
}
Пример #13
0
static inline void condenseq_ldb_resize(GtCondenseq *condenseq)
{
  if (condenseq->ldb_nelems == condenseq->ldb_allocated) {
    condenseq->ldb_allocated =
      gt_condenseq_array_size_increase(condenseq->ldb_allocated);
    condenseq->links = gt_realloc(condenseq->links,
                            (size_t) condenseq->ldb_allocated *
                            sizeof (*condenseq->links));
  }
}
Пример #14
0
static void secondcolumn (const Limdfsconstinfo *lci,LocaliColumn *outcol,
                          GtUchar dbchar)
{
  GtUword i;

  if (outcol->lenval < lci->maxcollen)
  {
    REALLOCMSG(outcol);
    outcol->colvalues = gt_realloc(outcol->colvalues,
                                   sizeof (LocaliMatrixvalue)
                                     * lci->maxcollen);
    outcol->lenval = lci->maxcollen;
    ATADDRESS("",outcol);
  }
#ifdef AFFINE
  outcol->colvalues[0].repcell = MINUSINFTY;
  outcol->colvalues[0].inscell = lci->scorevalues.gapstart +
                                 lci->scorevalues.gapextend;
  outcol->colvalues[0].delcell = MINUSINFTY;
#endif
  outcol->colvalues[0].bestcell = MINUSINFTY;
  outcol->colvalues[0].tracebit = Notraceback;
  outcol->maxvalue = 0;
  outcol->pprefixlen = 0;
  for (i = 1UL; i <= lci->querylength; i++)
  {
#ifdef AFFINE
    outcol->colvalues[i].delcell = MINUSINFTY;
    outcol->colvalues[i].inscell = MINUSINFTY;
    outcol->colvalues[i].repcell = REPLACEMENTSCORE(&lci->scorevalues,
                                                    dbchar,lci->query[i-1]);
    outcol->colvalues[i].bestcell = max2(outcol->colvalues[i].delcell,
                                         outcol->colvalues[i].repcell);
#else
    Scoretype temp;

    outcol->colvalues[i].bestcell = MINUSINFTY;
    outcol->colvalues[i].tracebit = Notraceback;
    if (outcol->colvalues[i-1].bestcell > 0)
    {
      IDXLOCALIDP_UPDATEMAX(outcol->colvalues[i-1].bestcell +
                lci->scorevalues.gapextend,Deletebit);
    }
    IDXLOCALIDP_UPDATEMAX(REPLACEMENTSCORE(&lci->scorevalues,
                               dbchar,lci->query[i-1]),Replacebit);
    IDXLOCALIDP_UPDATEMAX(lci->scorevalues.gapextend,Insertbit);
#endif
    if (outcol->colvalues[i].bestcell > 0 &&
        outcol->colvalues[i].bestcell > (Scoretype) outcol->maxvalue)
    {
      outcol->maxvalue = (GtUword) outcol->colvalues[i].bestcell;
      outcol->pprefixlen = i;
    }
  }
}
Пример #15
0
void gt_eoplist_reader_reset_width(GtEoplistReader *eoplist_reader,
                                   unsigned int width)
{
  if (eoplist_reader->width < width)
  {
    eoplist_reader->width = width;
    eoplist_reader->outbuffer = gt_realloc(eoplist_reader->outbuffer,
                                           sizeof *eoplist_reader->outbuffer *
                                           3 * (width+1));
    gt_assert(eoplist_reader->outbuffer != NULL);
  }
}
Пример #16
0
static unsigned long remdupsfastakeyqueries(Fastakeyquery *fastakeyqueries,
                                            unsigned long numofqueries,
                                            bool verbose)
{
  if (numofqueries == 0)
  {
    return 0;
  } else
  {
    Fastakeyquery *storeptr, *readptr;
    unsigned long newnumofqueries;

    for (storeptr = fastakeyqueries, readptr = fastakeyqueries+1;
         readptr < fastakeyqueries + numofqueries;
         readptr++)
    {
      if (strcmp(storeptr->fastakey,readptr->fastakey) != 0 ||
          storeptr->frompos != readptr->frompos ||
          storeptr->topos != readptr->topos)
      {
        storeptr++;
        if (storeptr != readptr)
        {
          size_t len;

          storeptr->frompos = readptr->frompos;
          storeptr->topos = readptr->topos;
          len = strlen(readptr->fastakey);
          storeptr->fastakey = gt_realloc(storeptr->fastakey,
                                          sizeof (char) * (len+1));
          strcpy(storeptr->fastakey,readptr->fastakey);
        }
      }
    }
    newnumofqueries = (unsigned long) (storeptr - fastakeyqueries + 1);
    if (newnumofqueries < numofqueries)
    {
      if (verbose)
      {
        printf("# removed %lu duplicate queries\n",
                numofqueries - newnumofqueries);
      }
      for (storeptr = fastakeyqueries + newnumofqueries;
           storeptr < fastakeyqueries + numofqueries;
           storeptr++)
      {
        gt_free(storeptr->fastakey);
        storeptr->fastakey = NULL;
      }
    }
    return newnumofqueries;
  }
}
Пример #17
0
static GtBacktraceFrontStackelem *stack_top_ptr_get(
                          GtBacktraceFrontStack *stack)
{
  if (stack->nextfree >= stack->allocated)
  {
    stack->allocated = stack->allocated * 1.2 + 128UL;
    stack->space = gt_realloc(stack->space,
                              sizeof *stack->space * stack->allocated);
    gt_assert(stack->space != NULL);
  }
  return stack->space + stack->nextfree++;
}
Пример #18
0
void gt_Sfxmappedrangelist_add(GtSfxmappedrangelist *sfxmrlist,
                               GtSfxmappedrange *sfxmappedrange)
{
  gt_assert(sfxmrlist != NULL);

  if (sfxmrlist->nextfree >= sfxmrlist->allocated)
  {
    sfxmrlist->allocated += 4UL;
    sfxmrlist->arr = gt_realloc(sfxmrlist->arr,sizeof (*sfxmrlist->arr) *
                                               sfxmrlist->allocated);
  }
  sfxmrlist->arr[sfxmrlist->nextfree++] = sfxmappedrange;
}
Пример #19
0
static void md5set_prepare_buffer(GtMD5Set *md5set, GtUword bufsize)
{
    gt_assert(md5set != NULL);

    if (md5set->buffer == NULL) {
        md5set->buffer = gt_malloc(sizeof (char) * bufsize);
        md5set->bufsize = bufsize;
    }
    else if (md5set->bufsize < bufsize) {
        md5set->buffer = gt_realloc(md5set->buffer, sizeof (char) * bufsize);
        md5set->bufsize = bufsize;
    }
}
Пример #20
0
void gt_alphabet_add_mapping(GtAlphabet *alphabet, const char *characters)
{
  size_t i, num_of_characters;
  gt_assert(alphabet && characters);
  num_of_characters = strlen(characters);
  gt_assert(num_of_characters);
  alphabet->mapdomain = gt_realloc(alphabet->mapdomain,
                                   (size_t) alphabet->domainsize
                                      + num_of_characters);
  memcpy(alphabet->mapdomain + alphabet->domainsize, characters,
         num_of_characters);
  alphabet->domainsize += num_of_characters;
  alphabet->symbolmap[(int) characters[0]] = (GtUchar) alphabet->mapsize;
  alphabet->characters = gt_realloc(alphabet->characters,
                                    (size_t) alphabet->domainsize);
  alphabet->characters[alphabet->mapsize] = (GtUchar) characters[0];
  for (i = 0; i < num_of_characters; i++)
    alphabet->symbolmap[(int) characters[i]] = (GtUchar) alphabet->mapsize;
  alphabet->mapsize++;
  alphabet->bitspersymbol
    = gt_determinebitspervalue((unsigned long) alphabet->mapsize);
}
Пример #21
0
void gt_alphabet_add_wildcard(GtAlphabet *alphabet, char wildcard)
{
  gt_assert(alphabet);
  alphabet->mapdomain = gt_realloc(alphabet->mapdomain,
                                   (size_t) alphabet->domainsize + 1);
  alphabet->mapdomain[alphabet->domainsize] = (GtUchar) wildcard;
  alphabet->domainsize++;
  alphabet->symbolmap[(int) wildcard] = (GtUchar) WILDCARD;
  if (alphabet->wildcardshow == (GtUchar) UNDEFCHAR) {
    alphabet->wildcardshow = (GtUchar) wildcard;
    alphabet->mapsize++;
  }
  alphabet->mappedwildcards++;
}
Пример #22
0
static void locali_initrootLimdfsstate(DECLAREPTRDFSSTATE(aliasstate),
                                       Limdfsconstinfo *lci)
{
  LocaliColumn *column = (LocaliColumn *) aliasstate;

  if (column->lenval < lci->maxcollen)
  {
    REALLOCMSG(column);
    column->colvalues = gt_realloc(column->colvalues,
                                   sizeof (LocaliMatrixvalue)
                                      * lci->maxcollen);
    column->lenval = lci->maxcollen;
    ATADDRESS("",column);
  }
}
Пример #23
0
void gt_reinitLocaliTracebackstate(Limdfsconstinfo *lci,
                                GtUword dbprefixlen,
                                GtUword pprefixlen)
{
  LocaliTracebackstate *tbs = &lci->tbs;

  tbs->dbprefixlen = tbs->dbcurrent = dbprefixlen;
  tbs->queryend = tbs->querypos = pprefixlen;
  if (dbprefixlen > (GtUword) tbs->allocatedGtUchardbsubstring)
  {
    tbs->spaceGtUchardbsubstring = gt_realloc(tbs->spaceGtUchardbsubstring,
                                            sizeof (GtUchar) * dbprefixlen);
  }
  gt_alignment_reset(tbs->alignment);
}
Пример #24
0
static int save_fastasequence(const char *seqpart, GT_UNUSED GtUword length,
                              void *data, GT_UNUSED GtError* err)
{
  GtSequenceTable *fasta_seqs = (GtSequenceTable*) data;

  if (fasta_seqs->maxsize == fasta_seqs->size)
  {
    fasta_seqs->maxsize += 10;
    fasta_seqs->seqarray = gt_realloc(fasta_seqs->seqarray,
                                      fasta_seqs->maxsize*
                                      sizeof (*fasta_seqs->seqarray));
  }
  fasta_seqs->seqarray[fasta_seqs->size++] = gt_str_new_cstr(seqpart);
  return 0;
}
Пример #25
0
void gt_tag_value_map_set(GtTagValueMap *map, const char *tag,
                          const char *new_value)
{
  size_t old_value_len, new_value_len, map_len = 0;
  char *old_value;
  gt_assert(map && *map && tag && new_value);
  gt_assert(strlen(tag));
  new_value_len = strlen(new_value);
  gt_assert(new_value_len);
  /* determine current map length */
  old_value = get_value(*map, tag, &map_len);
  if (!old_value)
    return gt_tag_value_map_add(map, tag, new_value);
  /* tag already used -> replace it */
  old_value_len = strlen(old_value);
  map_len = get_map_len(*map);
  if (new_value_len < old_value_len) {
    memcpy(old_value, new_value, new_value_len);
    memmove(old_value + new_value_len, old_value + old_value_len,
            map_len - ((size_t) old_value - (size_t) *map + old_value_len) + 1);
    *map = gt_realloc(*map, map_len - (old_value_len - new_value_len) + 1);
  }
  else if (new_value_len == old_value_len) {
    memcpy(old_value, new_value, new_value_len);
  }
  else { /* (new_value_len > old_value_len)  */
    *map = gt_realloc(*map, map_len + (new_value_len - old_value_len) + 1);
    /* determine old_value again, realloc() might have moved it */
    old_value = get_value(*map, tag, &map_len);
    gt_assert(old_value);
    memmove(old_value + new_value_len, old_value + old_value_len,
            map_len - ((size_t) old_value - (size_t) *map + old_value_len) + 1);
    memcpy(old_value, new_value, new_value_len);
  }
  gt_assert((*map)[map_len - old_value_len + new_value_len] == '\0');
}
Пример #26
0
static void stringbuffer_append_cigar(GtStringBuffer *sbuf,
                                      const GtCigarOp *co,
                                      bool distinguish_mismatch_match)
{
  const size_t gt_uword_maxwidth = sizeof ("18446744073709551615");

  if (sbuf->nextfree + gt_uword_maxwidth + 1 + 1 >= sbuf->allocated)
  {
    sbuf->allocated = sbuf->allocated * 1.2 + gt_uword_maxwidth + 1 + 1 + 1;
    sbuf->space = gt_realloc(sbuf->space,sizeof *sbuf->space * sbuf->allocated);
  }
  sbuf->nextfree +=
    sprintf(sbuf->space + sbuf->nextfree,"" GT_WU "%c",
            co->iteration,gt_eoplist_pretty_print(co->eoptype,
                                                  distinguish_mismatch_match));
}
Пример #27
0
static void gt_spacelog_addentry(GtFirstcodesspacelog *fcsl,
                                 const char *filename,int line,
                                 const char *title,size_t size,
                                 bool work)
{
  gt_assert(fcsl->nextfree <= fcsl->allocated);
  if (fcsl->nextfree == fcsl->allocated)
  {
    fcsl->allocated += 16UL;
    fcsl->entries = gt_realloc(fcsl->entries,sizeof (*fcsl->entries) *
                                             fcsl->allocated);
  }
  gt_spacelog_updateaddentry(fcsl->entries + fcsl->nextfree,
                             filename,line,title,size,work);
  fcsl->nextfree++;
}
static int io_cons_field_header(DescField *field,
                                FILE *fp,
                                GtIOFunc io_func,
                                GtError *err)
{
  int had_err = 0;
  had_err = GT_ENCDESC_IO_ONE(field->len);

  if (!had_err) {
    field->data = gt_realloc(field->data,
                             (size_t) (field->len + 1) * sizeof (char));
    field->data[field->len] = '\0';
    had_err = io_func(field->data, sizeof (char), (size_t) field->len, fp, err);
  }
  return had_err;
}
Пример #29
0
GtEoplistReader *gt_eoplist_reader_new(const GtEoplist *eoplist)
{
  GtEoplistReader *eoplist_reader;

  gt_assert(eoplist != NULL);
  eoplist_reader = gt_malloc(sizeof *eoplist_reader);
  gt_assert(eoplist_reader != NULL);
  eoplist_reader->width = 0;
  eoplist_reader->outbuffer = NULL;
  eoplist_reader->distinguish_mismatch_match = false;
  eoplist_reader->width = 70;
  eoplist_reader->outbuffer = gt_realloc(eoplist_reader->outbuffer,
                                         sizeof *eoplist_reader->outbuffer *
                                         3 * (eoplist_reader->width+1));
  gt_eoplist_reader_reset(eoplist_reader,eoplist);
  return eoplist_reader;
}
Пример #30
0
GtLcpvalues *gt_Outlcpinfo_resizereservoir(GtOutlcpinfo *outlcpinfo,
                                           const GtBcktab *bcktab)
{
  Lcpsubtab *lcpsubtab;

  gt_assert(outlcpinfo != NULL);
  lcpsubtab = &outlcpinfo->lcpsubtab;
  if (lcpsubtab->lcp2file != NULL)
  {
    size_t sizeforlcpvalues; /* in bytes */

    gt_assert(bcktab != NULL);
    sizeforlcpvalues = gt_bcktab_sizeforlcpvalues(bcktab);
    if (lcpsubtab->lcp2file->sizereservoir < sizeforlcpvalues)
    {
      lcpsubtab->lcp2file->sizereservoir = sizeforlcpvalues;
      lcpsubtab->lcp2file->reservoir
        = gt_realloc(lcpsubtab->lcp2file->reservoir,
                     lcpsubtab->lcp2file->sizereservoir);
          /* point to the same area, since this is not used simultaneously */
          /* be careful for the parallel version */
      lcpsubtab->lcp2file->smalllcpvalues
        = (uint8_t *) lcpsubtab->lcp2file->reservoir;
#ifndef NDEBUG
      lcpsubtab->tableoflcpvalues.isset = NULL;
#endif
      lcpsubtab->tableoflcpvalues.bucketoflcpvalues
        = (GtLcpvaluetype *) lcpsubtab->lcp2file->reservoir;
      lcpsubtab->tableoflcpvalues.lcptaboffset = 0;
      lcpsubtab->tableoflcpvalues.numofentries
        = (GtUword) lcpsubtab->lcp2file->sizereservoir/
          sizeof (*lcpsubtab->tableoflcpvalues.bucketoflcpvalues);
    }
  } else
  {
    if (lcpsubtab->lcpprocess != NULL)
    {
      outlcpinfo->sizeofinfo
        += gt_tableoflcpvalues_realloc(&lcpsubtab->tableoflcpvalues,
                                       gt_bcktab_maxbucketsize(bcktab));
    }
  }
  return &lcpsubtab->tableoflcpvalues;
}