X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=incbwt%2Fbits%2Fbitvector.cpp;h=b2ed324aee2f65142be6c5fa991272a76bbd670c;hb=f3f5b4a7e58ca81c9542ac50f0103af37f13f662;hp=b76fa9d1b82cd0dcf00dd4d65e0d4dc7faa9587a;hpb=5d74bc076c9d15d607d183c16ff8468ea961a0f9;p=SXSI%2FTextCollection.git diff --git a/incbwt/bits/bitvector.cpp b/incbwt/bits/bitvector.cpp index b76fa9d..b2ed324 100644 --- a/incbwt/bits/bitvector.cpp +++ b/incbwt/bits/bitvector.cpp @@ -26,6 +26,25 @@ BitVector::BitVector(std::ifstream& file) : this->indexForSelect(); } +BitVector::BitVector(std::FILE * file) : + rank_index(0), select_index(0) +{ + std::fread(&(this->size), sizeof(this->size), 1, file); + std::fread(&(this->items), sizeof(this->items), 1, file); + std::fread(&(this->number_of_blocks), sizeof(this->number_of_blocks), 1, file); + std::fread(&(this->block_size), sizeof(this->block_size), 1, file); + + this->array = new usint[this->block_size * this->number_of_blocks]; + std::fread(this->array, sizeof(usint), this->block_size * this->number_of_blocks, file); + this->buffer = new FastBitBuffer(this->array, this->block_size); + + this->integer_bits = length(this->size); + this->samples = new FastBitBuffer(file, 2 * (this->number_of_blocks + 1), this->integer_bits); + + this->indexForRank(); + this->indexForSelect(); +} + BitVector::BitVector(VectorEncoder& encoder, usint universe_size) : size(universe_size), items(encoder.items), block_size(encoder.block_size), @@ -87,6 +106,18 @@ BitVector::writeTo(std::ofstream& file) this->samples->writeBuffer(file, false); } +void +BitVector::writeTo(FILE* file) +{ + std::fwrite(&(this->size), sizeof(this->size), 1, file); + std::fwrite(&(this->items), sizeof(this->items), 1, file); + std::fwrite(&(this->number_of_blocks), sizeof(this->number_of_blocks), 1, file); + std::fwrite(&(this->block_size), sizeof(this->block_size), 1, file); + std::fwrite(this->array, sizeof(usint), this->block_size * this->number_of_blocks, file); + this->samples->writeBuffer(file, false); +} + + //-------------------------------------------------------------------------- usint