LCP_DAC_VAR::LCP_DAC_VAR(TextIndex *csa, char *text, size_t length){ lcp_type = DAC_VAR; n = length; uint *lcp; uint *frec_acu = new uint[n]; uint max_lcp = 0; ushort *kvalues; uint nkvalues; /*create the LCP array and frec_acu array*/ lcp = create_lcp(csa,text,n,32); for(uint i=0; i<n; i++) frec_acu[i]=0; frec_acu[0]++; for(uint i=0; i < n; i++){ frec_acu[lcp[i]]++; if(max_lcp<lcp[i]) max_lcp = lcp[i]; } for(uint i=1; i<=max_lcp; i++) frec_acu[i] = frec_acu[i] + frec_acu[i-1]; /*calculate the kvalues*/ kvalues = NULL; calc_kvalues(max_lcp, frec_acu, &kvalues, &nkvalues); rep = new factorization_var(lcp, n, kvalues, nkvalues); next_p_var = new size_t[(uint)rep->nLevels -1]; delete [] kvalues; delete [] frec_acu; delete [] lcp; }
LCP_Sad::LCP_Sad(TextIndex *csa, char *text, size_t n, size_t op_rs) { if(op_rs!=BRW32_HDR && op_rs!=DARRAY_HDR) { cout << "Error: op_rs must be BRW32_HDR or DARRAY_HDR\n" << endl; exit(1); } lcp_type = SAD_GON_OS; U_type = op_rs; uint *lcp = create_lcp(csa,text,n,32); uint pos =0; uint lcp_prev, lcp_act; long long nb = 1; nb = (nb*2*n+W-1)/W; if(nb > MAXINT) { cout << "Memory limit excess (in LCP)" << endl; exit(1); } uint *S = new uint[(uint)nb]; for(uint i=0; i < (uint)nb; i++) S[i]=0; cds_utils::bitset(S,0); lcp_prev = lcp[csa->getISA(0)]; pos += lcp_prev +1; //calculate S and create U for(uint i=1; i<n ;i++) { cds_utils::bitset(S,pos); lcp_act = lcp[csa->getISA(i)]; pos+= lcp_act - lcp_prev + 2; lcp_prev = lcp_act; } cds_utils::bitset(S,pos); if(op_rs==BRW32_HDR) //(bitarray, length, factor) U = new BitSequenceRG(S, pos+1, 4); else U = new BitSequenceDArray(S, pos+1); U_length = (size_t)(pos+1); delete [] S; delete [] lcp; }