blob: b52ff839f6da2b652a3a2d76ce47b47cb5ce3df3 (
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
|
#pragma once
#include "coding/compressed_bit_vector.hpp"
#include "base/ref_counted.hpp"
#include "std/function.hpp"
#include "std/utility.hpp"
namespace search
{
// A wrapper around coding::CompressedBitVector that augments the
// latter with the "full" state and uses reference counting for
// ownership sharing.
class CBV
{
public:
CBV() = default;
explicit CBV(unique_ptr<coding::CompressedBitVector> p);
CBV(CBV const & cbv) = default;
CBV(CBV && cbv);
inline operator bool() const { return !IsEmpty(); }
CBV & operator=(unique_ptr<coding::CompressedBitVector> p);
CBV & operator=(CBV const & rhs) = default;
CBV & operator=(CBV && rhs);
void SetFull();
void Reset();
inline bool IsEmpty() const { return !m_isFull && coding::CompressedBitVector::IsEmpty(m_p.Get()); }
inline bool IsFull() const { return m_isFull; }
bool HasBit(uint64_t id) const;
uint64_t PopCount() const;
template <class TFn>
void ForEach(TFn && fn) const
{
ASSERT(!m_isFull, ());
if (!IsEmpty())
coding::CompressedBitVectorEnumerator::ForEach(*m_p, forward<TFn>(fn));
}
CBV Union(CBV const & rhs) const;
CBV Intersect(CBV const & rhs) const;
// Takes first set |n| bits.
CBV Take(uint64_t n) const;
uint64_t Hash() const;
private:
my::RefCountPtr<coding::CompressedBitVector> m_p;
// True iff all bits are set to one.
bool m_isFull = false;
};
} // namespace search
|