Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2015-07-16 14:32:32 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:57:12 +0300
commit1540281383893c5ae1eeec648390ed8a00e2d0f0 (patch)
treee3f1e90a2297a022a69d6b03dfd5bda7bc7daca4 /indexer/unique_index.hpp
parent8fdd97d52366659ec16cf4d4edf3ab98f96b0874 (diff)
Distinguish feature’s ids storing policy according to mwm version (bits or raw set).
Diffstat (limited to 'indexer/unique_index.hpp')
-rw-r--r--indexer/unique_index.hpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/indexer/unique_index.hpp b/indexer/unique_index.hpp
index 9578045fe1..41865773d0 100644
--- a/indexer/unique_index.hpp
+++ b/indexer/unique_index.hpp
@@ -2,39 +2,54 @@
#include "../base/base.hpp"
+#include "../std/unordered_set.hpp"
#include "../std/vector.hpp"
class CheckUniqueIndexes
{
+ unordered_set<uint32_t> m_s;
vector<bool> m_v;
+ bool m_useBits;
-public:
/// Add index to the set.
/// @return true If index was absent.
bool Add(uint32_t ind)
{
- if (m_v.size() <= ind)
- m_v.resize(ind + 1);
- bool const ret = !m_v[ind];
- m_v[ind] = true;
- return ret;
+ if (m_useBits)
+ {
+ if (m_v.size() <= ind)
+ m_v.resize(ind + 1);
+ bool const ret = !m_v[ind];
+ m_v[ind] = true;
+ return ret;
+ }
+ else
+ return m_s.insert(ind).second;
}
/// Remove index from the set.
/// @return true If index was present.
bool Remove(uint32_t ind)
{
- if (m_v.size() > ind)
+ if (m_useBits)
{
- bool const ret = m_v[ind];
- m_v[ind] = false;
- return ret;
+ if (m_v.size() > ind)
+ {
+ bool const ret = m_v[ind];
+ m_v[ind] = false;
+ return ret;
+ }
+ else
+ return false;
}
else
- return false;
+ return (m_s.erase(ind) > 0);
}
+public:
+ explicit CheckUniqueIndexes(bool useBits) : m_useBits(useBits) {}
+
bool operator()(uint32_t ind)
{
return Add(ind);