ImpWTLF ( iterator BWT, uint64_t const rn, ::libmaus2::util::TempFileNameGenerator & rtmpgen, uint64_t const rmaxval = 0) : n(rn) { if ( n ) { uint64_t maxval = rmaxval; for ( uint64_t i = 0; i < n; ++i ) maxval = std::max ( maxval, static_cast<uint64_t>(BWT[i]) ); uint64_t const b = ::libmaus2::math::numbits(maxval); ::libmaus2::wavelet::ImpExternalWaveletGenerator IEWG(b,rtmpgen); for ( uint64_t i = 0; i < n; ++i ) IEWG.putSymbol(BWT[i]); std::string const tmpfilename = rtmpgen.getFileName(); IEWG.createFinalStream(tmpfilename); std::ifstream istr(tmpfilename.c_str(),std::ios::binary); wt_ptr_type tW(new wt_type(istr)); W = UNIQUE_PTR_MOVE(tW); istr.close(); remove ( tmpfilename.c_str() ); D = ::libmaus2::autoarray::AutoArray < uint64_t >((1ull<<W->getB())+1); for ( uint64_t i = 0; i < (1ull<<W->getB()); ++i ) D [ i ] = W->rank(i,n-1); D.prefixSums(); } }
void testImpExternalWaveletGenerator() { ::libmaus::util::TempFileNameGenerator tmpgen("tmpdir",1); uint64_t const b = 3; ::libmaus::wavelet::ImpExternalWaveletGenerator IEWG(b,tmpgen); #if 0 IEWG.putSymbol(0); IEWG.putSymbol(1); IEWG.putSymbol(2); IEWG.putSymbol(3); IEWG.putSymbol(4); IEWG.putSymbol(5); IEWG.putSymbol(6); IEWG.putSymbol(7); #endif std::vector < uint64_t > V; for ( uint64_t i = 0; i < 381842*41; ++i ) { uint64_t const v = rand() % (1ull<<b); // uint64_t const v = i % (1ull<<b); IEWG.putSymbol(v); V.push_back(v); } std::ostringstream ostr; IEWG.createFinalStream(ostr); std::istringstream istr(ostr.str()); ::libmaus::wavelet::ImpWaveletTree IWT(istr); std::cerr << "Testing..."; std::vector<uint64_t> R(1ull << b,0); for ( uint64_t i = 0; i < IWT.size(); ++i ) { std::pair<uint64_t,uint64_t> IS = IWT.inverseSelect(i); assert ( IS.first == V[i] ); assert ( IS.second == R[V[i]] ); uint64_t const s = IWT.select(V[i],R[V[i]]); // std::cerr << "expect " << i << " got " << s << std::endl; assert ( s == i ); R [ V[i] ] ++; assert ( IWT.rank(V[i],i) == R[V[i]] ); assert ( IWT[i] == V[i] ); } std::cerr << "done." << std::endl; #if 0 for ( uint64_t i = 0; i < IWT.n; ++i ) { std::cerr << "IWT[" << i << "]=" << IWT[i] << std::endl; std::cerr << "rank(" << IWT[i] << "," << i << ")" << "=" << IWT.rank(IWT[i],i) << std::endl; } #endif }
ImpWTLF (::libmaus2::huffman::RLDecoder & decoder, uint64_t const b, ::libmaus2::util::TempFileNameGenerator & rtmpgen) : n(decoder.getN()) { if ( n ) { ::libmaus2::wavelet::ImpExternalWaveletGenerator IEWG(b,rtmpgen); for ( uint64_t i = 0; i < n; ++i ) IEWG.putSymbol(decoder.decode()); std::string const tmpfilename = rtmpgen.getFileName(); IEWG.createFinalStream(tmpfilename); std::ifstream istr(tmpfilename.c_str(),std::ios::binary); wt_ptr_type tW(new wt_type(istr)); W = UNIQUE_PTR_MOVE(tW); istr.close(); remove ( tmpfilename.c_str() ); D = ::libmaus2::autoarray::AutoArray < uint64_t >((1ull<<W->getB())+1); for ( uint64_t i = 0; i < (1ull<<W->getB()); ++i ) D [ i ] = W->rank(i,n-1); D.prefixSums(); } }