diff options
author | Yuri Gorshenin <y@maps.me> | 2016-02-09 12:47:11 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:17:00 +0300 |
commit | 004d20ca90f22789b190feb1a4ad3e8da0a3807a (patch) | |
tree | d7f2feda7a8e4c42324aaeae21dc79675b724aab /coding | |
parent | df8a1a8ac690156c71c819f220236133e3891975 (diff) |
Review fixes.
Diffstat (limited to 'coding')
-rw-r--r-- | coding/coding_tests/compressed_bit_vector_test.cpp | 22 | ||||
-rw-r--r-- | coding/compressed_bit_vector.hpp | 2 |
2 files changed, 13 insertions, 11 deletions
diff --git a/coding/coding_tests/compressed_bit_vector_test.cpp b/coding/coding_tests/compressed_bit_vector_test.cpp index 3507ec0903..812a108a47 100644 --- a/coding/coding_tests/compressed_bit_vector_test.cpp +++ b/coding/coding_tests/compressed_bit_vector_test.cpp @@ -415,7 +415,7 @@ UNIT_TEST(CompressedBitVector_DenseLeaveFirstNBits) { vector<uint64_t> setBits; - for (int i = 0; i < 100; ++i) + for (uint64_t i = 0; i < 100; ++i) setBits.push_back(2 * i); auto cbv = coding::CompressedBitVectorBuilder::FromBitPositions(setBits); TEST_EQUAL(cbv->PopCount(), 100, ()); @@ -425,7 +425,7 @@ UNIT_TEST(CompressedBitVector_DenseLeaveFirstNBits) TEST_EQUAL(cbv->PopCount(), 50, ()); TEST_EQUAL(cbv->GetStorageStrategy(), coding::CompressedBitVector::StorageStrategy::Dense, ()); - for (int i = 0; i < 50; ++i) + for (uint64_t i = 0; i < 50; ++i) { TEST(cbv->GetBit(2 * i), ()); TEST(!cbv->GetBit(2 * i + 1), ()); @@ -436,15 +436,15 @@ UNIT_TEST(CompressedBitVector_DenseLeaveFirstNBits) UNIT_TEST(CompressedBitVector_SparseLeaveFirstNBits) { vector<uint64_t> setBits; - for (int p = 0; p < 20; ++p) + for (int p = 0; p < 10; ++p) setBits.push_back(static_cast<uint64_t>(1) << p); auto cbv = coding::CompressedBitVectorBuilder::FromBitPositions(setBits); - TEST_EQUAL(cbv->PopCount(), 20, ()); + TEST_EQUAL(cbv->PopCount(), 10, ()); TEST_EQUAL(cbv->GetStorageStrategy(), coding::CompressedBitVector::StorageStrategy::Sparse, ()); cbv = cbv->LeaveFirstSetNBits(100); - TEST_EQUAL(cbv->PopCount(), 20, ()); - for (uint64_t bit = 0; bit < (1 << 20); ++bit) + TEST_EQUAL(cbv->PopCount(), 10, ()); + for (uint64_t bit = 0; bit < (1 << 10); ++bit) { if (bit != 0 && (bit & (bit - 1)) == 0) TEST(cbv->GetBit(bit), (bit)); @@ -452,11 +452,11 @@ UNIT_TEST(CompressedBitVector_SparseLeaveFirstNBits) TEST(!cbv->GetBit(bit), (bit)); } - cbv = cbv->LeaveFirstSetNBits(10); - TEST_EQUAL(cbv->PopCount(), 10, ()); - for (uint64_t bit = 0; bit < (1 << 20); ++bit) + cbv = cbv->LeaveFirstSetNBits(8); + TEST_EQUAL(cbv->PopCount(), 8, ()); + for (uint64_t bit = 0; bit < (1 << 10); ++bit) { - if (bit != 0 && (bit & (bit - 1)) == 0 && bit < (1 << 10)) + if (bit != 0 && (bit & (bit - 1)) == 0 && bit < (1 << 8)) TEST(cbv->GetBit(bit), (bit)); else TEST(!cbv->GetBit(bit), (bit)); @@ -464,6 +464,6 @@ UNIT_TEST(CompressedBitVector_SparseLeaveFirstNBits) cbv = cbv->LeaveFirstSetNBits(0); TEST_EQUAL(cbv->PopCount(), 0, ()); - for (uint64_t bit = 0; bit < (1 << 20); ++bit) + for (uint64_t bit = 0; bit < (1 << 10); ++bit) TEST(!cbv->GetBit(bit), (bit)); } diff --git a/coding/compressed_bit_vector.hpp b/coding/compressed_bit_vector.hpp index 6e01ee7056..7e51b363aa 100644 --- a/coding/compressed_bit_vector.hpp +++ b/coding/compressed_bit_vector.hpp @@ -58,6 +58,8 @@ public: // Would operator[] look better? virtual bool GetBit(uint64_t pos) const = 0; + // Returns a subset of the current bit vector with first + // min(PopCount(), |n|) set bits. virtual unique_ptr<CompressedBitVector> LeaveFirstSetNBits(uint64_t n) const = 0; // Returns the strategy used when storing this bit vector. |