-
Notifications
You must be signed in to change notification settings - Fork 25
/
bitvector_collection.hpp
91 lines (75 loc) · 2.51 KB
/
bitvector_collection.hpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include <succinct/bit_vector.hpp>
#include "compact_elias_fano.hpp"
namespace ds2i {
class bitvector_collection {
public:
bitvector_collection()
: m_size(0)
{}
class builder {
public:
builder(global_parameters const& params)
: m_params(params)
{
m_endpoints.push_back(0);
}
void append(succinct::bit_vector_builder& bvb)
{
m_bitvectors.append(bvb);
m_endpoints.push_back(m_bitvectors.size());
}
void build(bitvector_collection& sq)
{
sq.m_size = m_endpoints.size() - 1;
succinct::bit_vector(&m_bitvectors).swap(sq.m_bitvectors);
succinct::bit_vector_builder bvb;
compact_elias_fano::write(bvb, m_endpoints.begin(),
m_bitvectors.size(), sq.m_size,
m_params);
succinct::bit_vector(&bvb).swap(sq.m_endpoints);
}
private:
global_parameters m_params;
std::vector<uint64_t> m_endpoints;
succinct::bit_vector_builder m_bitvectors;
};
size_t size() const
{
return m_size;
}
succinct::bit_vector const& bits() const
{
return m_bitvectors;
}
succinct::bit_vector::enumerator
get(global_parameters const& params, size_t i) const
{
assert(i < size());
compact_elias_fano::enumerator endpoints(m_endpoints, 0,
m_bitvectors.size(), m_size,
params);
auto endpoint = endpoints.move(i).second;
return succinct::bit_vector::enumerator(m_bitvectors, endpoint);
}
void swap(bitvector_collection& other)
{
std::swap(m_size, other.m_size);
m_endpoints.swap(other.m_endpoints);
m_bitvectors.swap(other.m_bitvectors);
}
template <typename Visitor>
void map(Visitor& visit)
{
visit
(m_size, "m_size")
(m_endpoints, "m_endpoints")
(m_bitvectors, "m_bitvectors")
;
}
private:
size_t m_size;
succinct::bit_vector m_endpoints;
succinct::bit_vector m_bitvectors;
};
}