diff options
-rw-r--r-- | coding/coding_tests/compressed_bit_vector_test.cpp | 88 | ||||
-rw-r--r-- | search/v2/features_filter.cpp | 4 | ||||
-rw-r--r-- | search/v2/features_filter.hpp | 4 | ||||
-rw-r--r-- | search/v2/geocoder.cpp | 11 | ||||
-rw-r--r-- | search/v2/mwm_context.cpp | 7 | ||||
-rw-r--r-- | search/v2/mwm_context.hpp | 5 |
6 files changed, 50 insertions, 69 deletions
diff --git a/coding/coding_tests/compressed_bit_vector_test.cpp b/coding/coding_tests/compressed_bit_vector_test.cpp index b0b800ea5e..f539704559 100644 --- a/coding/coding_tests/compressed_bit_vector_test.cpp +++ b/coding/coding_tests/compressed_bit_vector_test.cpp @@ -62,6 +62,23 @@ void CheckUnion(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2, { CheckBinaryOp(&Union, setBits1, setBits2, cbv); } + +void CheckUnion(vector<uint64_t> & setBits1, coding::CompressedBitVector::StorageStrategy strategy1, + vector<uint64_t> & setBits2, coding::CompressedBitVector::StorageStrategy strategy2, + coding::CompressedBitVector::StorageStrategy resultStrategy) +{ + auto cbv1 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits1); + auto cbv2 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits2); + TEST(cbv1.get(), ()); + TEST(cbv2.get(), ()); + TEST_EQUAL(strategy1, cbv1->GetStorageStrategy(), ()); + TEST_EQUAL(strategy2, cbv2->GetStorageStrategy(), ()); + + auto cbv3 = coding::CompressedBitVector::Union(*cbv1, *cbv2); + TEST(cbv3.get(), ()); + TEST_EQUAL(resultStrategy, cbv3->GetStorageStrategy(), ()); + CheckUnion(setBits1, setBits2, *cbv3); +} } // namespace UNIT_TEST(CompressedBitVector_Intersect1) @@ -227,17 +244,9 @@ UNIT_TEST(CompressedBitVector_Union_Smoke) vector<uint64_t> setBits1 = {}; vector<uint64_t> setBits2 = {}; - auto cbv1 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits1); - auto cbv2 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits2); - TEST(cbv1.get(), ()); - TEST(cbv2.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv1->GetStorageStrategy(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv2->GetStorageStrategy(), ()); - - auto cbv3 = coding::CompressedBitVector::Union(*cbv1, *cbv2); - TEST(cbv3.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv3->GetStorageStrategy(), ()); - CheckUnion(setBits1, setBits2, *cbv3); + CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */, + setBits2, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */, + coding::CompressedBitVector::StorageStrategy::Sparse /* resultStrategy */); } UNIT_TEST(CompressedBitVector_Union1) @@ -245,17 +254,9 @@ UNIT_TEST(CompressedBitVector_Union1) vector<uint64_t> setBits1 = {}; vector<uint64_t> setBits2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto cbv1 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits1); - auto cbv2 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits2); - TEST(cbv1.get(), ()); - TEST(cbv2.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv1->GetStorageStrategy(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, cbv2->GetStorageStrategy(), ()); - - auto cbv3 = coding::CompressedBitVector::Union(*cbv1, *cbv2); - TEST(cbv3.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, cbv3->GetStorageStrategy(), ()); - CheckUnion(setBits1, setBits2, *cbv3); + CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */, + setBits2, coding::CompressedBitVector::StorageStrategy::Dense /* strategy2 */, + coding::CompressedBitVector::StorageStrategy::Dense /* resultStrategy */); } UNIT_TEST(CompressedBitVector_Union2) @@ -263,17 +264,9 @@ UNIT_TEST(CompressedBitVector_Union2) vector<uint64_t> setBits1 = {256, 1024}; vector<uint64_t> setBits2 = {0, 32, 64}; - auto cbv1 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits1); - auto cbv2 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits2); - TEST(cbv1.get(), ()); - TEST(cbv2.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv1->GetStorageStrategy(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv2->GetStorageStrategy(), ()); - - auto cbv3 = coding::CompressedBitVector::Union(*cbv1, *cbv2); - TEST(cbv3.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv3->GetStorageStrategy(), ()); - CheckUnion(setBits1, setBits2, *cbv3); + CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */, + setBits2, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */, + coding::CompressedBitVector::StorageStrategy::Sparse /* resultStrategy */); } UNIT_TEST(CompressedBitVector_Union3) @@ -284,17 +277,9 @@ UNIT_TEST(CompressedBitVector_Union3) for (int i = 0; i < 256; ++i) setBits2.push_back(i); - auto cbv1 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits1); - auto cbv2 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits2); - TEST(cbv1.get(), ()); - TEST(cbv2.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, cbv1->GetStorageStrategy(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, cbv2->GetStorageStrategy(), ()); - - auto cbv3 = coding::CompressedBitVector::Union(*cbv1, *cbv2); - TEST(cbv3.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, cbv3->GetStorageStrategy(), ()); - CheckUnion(setBits1, setBits2, *cbv3); + CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Dense /* strategy1 */, + setBits2, coding::CompressedBitVector::StorageStrategy::Dense /* strategy2 */, + coding::CompressedBitVector::StorageStrategy::Dense /* resultStrategy */); } UNIT_TEST(CompressedBitVector_Union4) @@ -305,18 +290,9 @@ UNIT_TEST(CompressedBitVector_Union4) vector<uint64_t> setBits2 = {1000000000}; - auto cbv1 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits1); - auto cbv2 = coding::CompressedBitVectorBuilder::FromBitPositions(setBits2); - TEST(cbv1.get(), ()); - TEST(cbv2.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, cbv1->GetStorageStrategy(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv2->GetStorageStrategy(), ()); - - auto cbv3 = coding::CompressedBitVector::Union(*cbv1, *cbv2); - TEST(cbv3.get(), ()); - TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, cbv3->GetStorageStrategy(), ()); - - CheckUnion(setBits1, setBits2, *cbv3); + CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Dense /* strategy1 */, + setBits2, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */, + coding::CompressedBitVector::StorageStrategy::Sparse /* resultStrategy */); } UNIT_TEST(CompressedBitVector_SerializationDense) diff --git a/search/v2/features_filter.cpp b/search/v2/features_filter.cpp index 10c83e9da8..0a31de1669 100644 --- a/search/v2/features_filter.cpp +++ b/search/v2/features_filter.cpp @@ -11,13 +11,13 @@ FeaturesFilter::FeaturesFilter(unique_ptr<coding::CompressedBitVector> filter, u { } -bool FeaturesFilter::NeedToFilter(coding::CompressedBitVector & cbv) const +bool FeaturesFilter::NeedToFilter(coding::CompressedBitVector const & cbv) const { return cbv.PopCount() > m_threshold; } unique_ptr<coding::CompressedBitVector> FeaturesFilter::Filter( - coding::CompressedBitVector & cbv) const + coding::CompressedBitVector const & cbv) const { if (!m_filter) return make_unique<coding::SparseCBV>(); diff --git a/search/v2/features_filter.hpp b/search/v2/features_filter.hpp index 63542c0f69..77b14e061a 100644 --- a/search/v2/features_filter.hpp +++ b/search/v2/features_filter.hpp @@ -21,8 +21,8 @@ public: inline void SetFilter(unique_ptr<coding::CompressedBitVector> filter) { m_filter = move(filter); } inline void SetThreshold(uint32_t threshold) { m_threshold = threshold; } - bool NeedToFilter(coding::CompressedBitVector & features) const; - unique_ptr<coding::CompressedBitVector> Filter(coding::CompressedBitVector & cbv) const; + bool NeedToFilter(coding::CompressedBitVector const & features) const; + unique_ptr<coding::CompressedBitVector> Filter(coding::CompressedBitVector const & cbv) const; private: unique_ptr<coding::CompressedBitVector> m_filter; diff --git a/search/v2/geocoder.cpp b/search/v2/geocoder.cpp index f1b5e4e9c3..8acbae840d 100644 --- a/search/v2/geocoder.cpp +++ b/search/v2/geocoder.cpp @@ -125,7 +125,7 @@ void Geocoder::Go(vector<FeatureID> & results) // it's ok to save MwmId. m_worldId = handle.GetId(); if (HasSearchIndex(value)) - FillLocalitiesTable(MwmContext(value, m_worldId)); + FillLocalitiesTable(move(handle)); } } @@ -240,7 +240,7 @@ void Geocoder::ForEachCountry(vector<shared_ptr<MwmInfo>> const & infos, TFn && auto & value = *handle.GetValue<MwmValue>(); if (!HasSearchIndex(value) || !HasGeometryIndex(value)) continue; - fn(make_unique<MwmContext>(value, handle.GetId())); + fn(make_unique<MwmContext>(move(handle))); } } @@ -360,9 +360,9 @@ void Geocoder::DoGeocoding(size_t curToken) // Try to consume first n tokens starting at |curToken|. for (size_t n = 1; curToken + n <= m_numTokens && !m_usedTokens[curToken + n - 1]; ++n) { - // At this point |intersection| is an intersection of + // At this point |intersection| is the intersection of // m_features[curToken], m_features[curToken + 1], ..., - // m_features[curToken + n - 1], except the case when n equals to 1. + // m_features[curToken + n - 2], iff n > 2. BailIfCancelled(static_cast<my::Cancellable const &>(*this)); @@ -386,7 +386,8 @@ void Geocoder::DoGeocoding(size_t curToken) intersection = coding::CompressedBitVector::Intersect(*m_features[curToken + n - 2], *m_features[curToken + n - 1]); features = intersection.get(); - } else + } + else { intersection = coding::CompressedBitVector::Intersect(*intersection, *m_features[curToken + n - 1]); diff --git a/search/v2/mwm_context.cpp b/search/v2/mwm_context.cpp index 7382fe54fa..23ad49bf6d 100644 --- a/search/v2/mwm_context.cpp +++ b/search/v2/mwm_context.cpp @@ -6,8 +6,11 @@ namespace search { namespace v2 { -MwmContext::MwmContext(MwmValue & value, MwmSet::MwmId const & id) - : m_value(value), m_id(id), m_vector(m_value.m_cont, m_value.GetHeader(), m_value.m_table) +MwmContext::MwmContext(MwmSet::MwmHandle handle) + : m_handle(move(handle)) + , m_value(*m_handle.GetValue<MwmValue>()) + , m_id(m_handle.GetId()) + , m_vector(m_value.m_cont, m_value.GetHeader(), m_value.m_table) { } } // namespace v2 diff --git a/search/v2/mwm_context.hpp b/search/v2/mwm_context.hpp index 1a90586e31..b987256c8e 100644 --- a/search/v2/mwm_context.hpp +++ b/search/v2/mwm_context.hpp @@ -13,10 +13,11 @@ namespace v2 { struct MwmContext { - MwmContext(MwmValue & value, MwmSet::MwmId const & id); + MwmContext(MwmSet::MwmHandle handle); + MwmSet::MwmHandle m_handle; MwmValue & m_value; - MwmSet::MwmId const m_id; + MwmSet::MwmId const & m_id; FeaturesVector m_vector; DISALLOW_COPY_AND_MOVE(MwmContext); |