static GtUword determinefmindexsize (const Fmindex *fm, const GtSpecialcharinfo *specialcharinfo, unsigned int suffixlength, bool storeindexpos) { uint64_t sumsize = 0; sumsize += (uint64_t) sizeof (GtUword) * (uint64_t) TFREQSIZE(fm->mapsize); sumsize += (uint64_t) sizeof (GtUword) * (uint64_t) SUPERBFREQSIZE(fm->mapsize,fm->nofsuperblocks); if (storeindexpos) { sumsize += (uint64_t) sizeof (GtUword) * (uint64_t) MARKPOSTABLELENGTH(fm->bwtlength,fm->markdist); } if (suffixlength > 0) { sumsize += (uint64_t) sizeof (GtUlongBound) * (uint64_t) fm->numofcodes; } if (storeindexpos) { sumsize += (uint64_t) sizeof (GtPairBwtidx) * (uint64_t) gt_determinenumberofspecialstostore(specialcharinfo); } sumsize += (uint64_t) sizeof (GtUchar) * (uint64_t) BFREQSIZE(fm->mapsize,fm->nofblocks); return CALLCASTFUNC(uint64_t,unsigned_long,sumsize); }
int gt_mapfmindex (Fmindex *fmindex,const char *indexname, GtLogger *logger,GtError *err) { FILE *fpin = NULL; bool haserr = false, storeindexpos = true; GtSpecialcharinfo specialcharinfo; gt_error_check(err); fmindex->mappedptr = NULL; fmindex->bwtformatching = NULL; fmindex->alphabet = NULL; fpin = gt_fa_fopen_with_suffix(indexname,FMASCIIFILESUFFIX,"rb",err); if (fpin == NULL) { haserr = true; } if (!haserr) { if (scanfmafileviafileptr(fmindex, &specialcharinfo, &storeindexpos, indexname, fpin, logger, err) != 0) { haserr = true; } } gt_fa_xfclose(fpin); if (!haserr) { fmindex->bwtformatching = mapbwtencoding(indexname,logger,err); if (fmindex->bwtformatching == NULL) { haserr = true; } } if (!haserr) { fmindex->specpos.nextfreeGtPairBwtidx = (unsigned long) gt_determinenumberofspecialstostore(&specialcharinfo); fmindex->specpos.spaceGtPairBwtidx = NULL; fmindex->specpos.allocatedGtPairBwtidx = 0; fmindex->alphabet = gt_alphabet_ref( gt_encseq_alphabet(fmindex->bwtformatching)); if (fmindex->alphabet == NULL) { haserr = true; } } if (!haserr) { GtStr *tmpfilename; gt_computefmkeyvalues (fmindex, &specialcharinfo, fmindex->bwtlength, fmindex->log2bsize, fmindex->log2markdist, gt_alphabet_num_of_chars(fmindex->alphabet), fmindex->suffixlength, storeindexpos); tmpfilename = gt_str_new_cstr(indexname); gt_str_append_cstr(tmpfilename,FMDATAFILESUFFIX); if (gt_fillfmmapspecstartptr(fmindex,storeindexpos,tmpfilename,err) != 0) { haserr = true; } gt_str_delete(tmpfilename); } if (haserr) { gt_freefmindex(fmindex); } return haserr ? -1 : 0; }