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:
Diffstat (limited to 'search/cbv_ptr.cpp')
-rw-r--r--search/cbv_ptr.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/search/cbv_ptr.cpp b/search/cbv_ptr.cpp
new file mode 100644
index 0000000000..7bdf63e64a
--- /dev/null
+++ b/search/cbv_ptr.cpp
@@ -0,0 +1,67 @@
+#include "search/cbv_ptr.hpp"
+
+namespace search
+{
+CBVPtr::CBVPtr(coding::CompressedBitVector const * p, bool isOwner) { Set(p, isOwner); }
+
+void CBVPtr::Release()
+{
+ if (m_isOwner)
+ delete m_ptr;
+
+ m_ptr = nullptr;
+ m_isOwner = false;
+ m_isFull = false;
+}
+
+void CBVPtr::Set(coding::CompressedBitVector const * p, bool isOwner /* = false*/)
+{
+ Release();
+
+ m_ptr = p;
+ m_isOwner = p && isOwner;
+}
+
+void CBVPtr::Set(unique_ptr<coding::CompressedBitVector> p)
+{
+ Set(p.release(), true /* isOwner */);
+}
+
+void CBVPtr::Union(coding::CompressedBitVector const * p)
+{
+ if (!p || m_isFull)
+ return;
+
+ if (!m_ptr)
+ {
+ m_ptr = p;
+ m_isFull = false;
+ }
+ else
+ {
+ Set(coding::CompressedBitVector::Union(*m_ptr, *p).release(), true);
+ }
+}
+
+void CBVPtr::Intersect(coding::CompressedBitVector const * p)
+{
+ if (!p)
+ {
+ Release();
+ return;
+ }
+
+ if (m_ptr)
+ {
+ Set(coding::CompressedBitVector::Intersect(*m_ptr, *p).release(), true);
+ }
+ else if (m_isFull)
+ {
+ m_ptr = p;
+ m_isFull = false;
+ }
+}
+
+bool CBVPtr::IsEmpty() const { return !m_isFull && coding::CompressedBitVector::IsEmpty(m_ptr); }
+
+} // namespace search