diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2019-04-15 18:28:54 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2019-04-22 18:47:33 +0300 |
commit | 01c771fe7f945a53581a7badb0a6b840e98f572a (patch) | |
tree | a747713bde42905d1d99698a9fb59b2e7ccb2c21 /coding | |
parent | 2397d5d659b53cd7d7f4787ba6ae5e24189302f2 (diff) |
[booking][search] booking filter improvement. review fixes
Diffstat (limited to 'coding')
-rw-r--r-- | coding/compressed_bit_vector.hpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/coding/compressed_bit_vector.hpp b/coding/compressed_bit_vector.hpp index aaf7a710c0..6440e2ac4c 100644 --- a/coding/compressed_bit_vector.hpp +++ b/coding/compressed_bit_vector.hpp @@ -5,6 +5,7 @@ #include "coding/writer.hpp" #include "base/assert.hpp" +#include "base/control_flow.hpp" #include "base/ref_counted.hpp" #include <cstddef> @@ -102,15 +103,19 @@ public: size_t NumBitGroups() const { return m_bitGroups.size(); } - template <typename TFn> - void ForEach(TFn && f) const + template <typename Fn> + void ForEach(Fn && f) const { + base::ControlFlowWrapper<Fn> wrapper(std::forward<Fn>(f)); for (size_t i = 0; i < m_bitGroups.size(); ++i) { for (size_t j = 0; j < kBlockSize; ++j) { if (((m_bitGroups[i] >> j) & 1) > 0) - f(kBlockSize * i + j); + { + if (wrapper(kBlockSize * i + j) == base::ControlFlow::Break) + return; + } } } } @@ -146,11 +151,15 @@ public: // Returns the position of the i'th set bit. uint64_t Select(size_t i) const; - template <typename TFn> - void ForEach(TFn && f) const + template <typename Fn> + void ForEach(Fn && f) const { + base::ControlFlowWrapper<Fn> wrapper(std::forward<Fn>(f)); for (auto const & position : m_positions) - f(position); + { + if (wrapper(position) == base::ControlFlow::Break) + return; + } } // CompressedBitVector overrides: @@ -225,8 +234,8 @@ class CompressedBitVectorEnumerator public: // Executes f for each bit that is set to one using // the bit's 0-based position as argument. - template <typename TFn> - static void ForEach(CompressedBitVector const & cbv, TFn && f) + template <typename Fn> + static void ForEach(CompressedBitVector const & cbv, Fn && f) { CompressedBitVector::StorageStrategy strat = cbv.GetStorageStrategy(); switch (strat) |