MCPcopy Create free account
hub / github.com/comaps/comaps / SparseVector

Class SparseVector

libs/coding/sparse_vector.hpp:10–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8/// Simple sparse vector for better memory usage.
9template <class Value>
10class SparseVector
11{
12 succinct::rs_bit_vector m_bits;
13 std::vector<Value> m_values;
14
15public:
16 SparseVector() = default;
17
18 bool Empty() const { return GetSize() == 0; }
19 uint64_t GetSize() const { return m_bits.size(); }
20 bool Has(uint64_t i) const { return m_bits[i]; }
21 Value const & Get(uint64_t i) const { return m_values[m_bits.rank(i)]; }
22
23 size_t GetMemorySize() const { return m_values.capacity() * sizeof(Value) + m_bits.size() / 8; }
24
25private:
26 SparseVector(std::vector<Value> && values, succinct::bit_vector_builder & bitsBuilder)
27 : m_bits(&bitsBuilder)
28 , m_values(std::move(values))
29 {}
30
31 template <class T>
32 friend class SparseVectorBuilder;
33};
34
35template <class Value>
36class SparseVectorBuilder

Callers

nothing calls this directly

Calls 1

rankMethod · 0.45

Tested by

no test coverage detected