blob: 405db9c5b382019ab3138bc878faad9184bec9e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include "search/v2/cbv_ptr.hpp"
namespace search
{
namespace v2
{
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 v2
} // namespace search
|