void term() { genc.encode(0); genc.encode(0); genc.flush(); SGO.flush(); SGOout.flush(); indexout.clear(); indexout.seekg(0,std::ios::beg); // uint64_t const indexpos = SGO.getWrittenBytes(); indexout.clear(); indexout.seekg(0,std::ios::beg); libmaus2::util::GetFileSize::copy(indexout,SGOout,2*sizeof(uint64_t)*indexentries); libmaus2::util::NumberSerialisation::serialiseNumber(SGOout,indexentries ? prevkey : 0); // highest key in file libmaus2::util::NumberSerialisation::serialiseNumber(SGOout,indexentries); SGOout.flush(); }
void encode(uint64_t const key, uint64_t const val) { // start of next block if ( ! blockleft ) { uint64_t const ikey = key; uint64_t const ibitoff = genc.getOffset(); libmaus2::util::NumberSerialisation::serialiseNumber(indexout,ikey); libmaus2::util::NumberSerialisation::serialiseNumber(indexout,ibitoff); indexentries++; // std::cerr << "ikey=" << ikey << " ibitoff=" << ibitoff << std::endl; blockleft = blocksize; } int64_t const dif = (static_cast<int64_t>(key)-prevkey)-1; genc.encode(dif); prevkey = key; assert ( val ); genc.encode(val); --blockleft; }
void implicitFlush() { uint64_t const bs = pc-pa; if ( bs ) { uint64_t acc = 0; uint64_t const pos = SGO.getWrittenBytes(); GE.encode(bs); for ( uint64_t i = 0; i < bs; ++i ) { acc += pa[i].second; GE.encodeWord(pa[i].first,albits); GE.encode(pa[i].second); } GE.flush(); ::libmaus2::huffman::IndexEntry const entry(pos,bs,acc); index.push_back(entry); pc = pa; } }