5 #include <sdsl/bits.hpp> 10 namespace tdc {
namespace int_vector {
17 using DynamicIntValueType = uint64_t;
19 struct DynamicWidthMemRw {
20 inline static void write_int(uint64_t* word, uint64_t x, uint8_t offset,
const uint8_t
len) {
21 sdsl::bits::write_int(word, x, offset, len);
23 inline static uint64_t read_int(
const uint64_t* word, uint8_t offset,
const uint8_t len) {
24 return sdsl::bits::read_int(word, offset, len);
27 struct BitWidthMemRw {
28 inline static void write_int(uint64_t* word, uint64_t v, uint8_t o,
const uint8_t) {
30 const auto mask = uint64_t(1) << o;
34 p |= (uint64_t(v) << o);
36 inline static uint64_t read_int(
const uint64_t* word, uint8_t o,
const uint8_t) {
38 const auto mask = uint64_t(1) << o;
40 return (p & mask) != 0;
43 template<
class MB,
class MemRw>
45 typedef MB SelfMaxBit;
47 template<
class Ref,
class V>
48 inline static void assign(Ref&
self, V v) {
52 self.m_ptr.m_bit_offset,
53 self.m_ptr.data_bit_size()
57 template<
class Ref,
class R>
58 inline static R cast_for_op(
const Ref&
self) {
59 return MemRw::read_int(
61 self.m_ptr.m_bit_offset,
62 self.m_ptr.data_bit_size()
66 template<
typename const_qual_ptr_t,
size_t N>
67 class IntPtrFixedWidthRepr {
69 const_qual_ptr_t m_ptr;
74 IntPtrFixedWidthRepr(const_qual_ptr_t ptr, uint8_t offset, uint8_t ):
75 m_ptr(ptr), m_bit_offset(offset) {}
76 inline uint8_t data_bit_size()
const {
return N; }
77 inline void set_data_bit_size(uint8_t x) { }
78 inline IntPtrFixedWidthRepr data_offset_to(const_qual_ptr_t ptr, uint8_t offset)
const {
79 return IntPtrFixedWidthRepr(ptr, offset, this->data_bit_size());
82 template<
typename const_qual_ptr_t>
83 class IntPtrDynamicWidthRepr {
85 const_qual_ptr_t m_ptr;
90 IntPtrDynamicWidthRepr(const_qual_ptr_t ptr, uint8_t offset, uint8_t size):
91 m_ptr(ptr), m_bit_offset(offset), m_bit_size(size) {}
92 inline uint8_t data_bit_size()
const {
return m_bit_size; }
93 inline void set_data_bit_size(uint8_t x) { m_bit_size = x; }
94 inline IntPtrDynamicWidthRepr data_offset_to(const_qual_ptr_t ptr, uint8_t offset)
const {
95 return IntPtrDynamicWidthRepr(ptr, offset, this->data_bit_size());
99 struct FixedBitPackingVectorRepr {
100 using internal_data_type = DynamicIntValueType;
102 std::vector<internal_data_type> m_vec;
103 uint64_t m_real_size;
105 inline FixedBitPackingVectorRepr():
106 m_vec(), m_real_size(0) {}
107 inline FixedBitPackingVectorRepr(
const FixedBitPackingVectorRepr& other):
108 m_vec(other.m_vec), m_real_size(other.m_real_size) {}
109 inline FixedBitPackingVectorRepr(FixedBitPackingVectorRepr&& other):
110 m_vec(std::move(other.m_vec)), m_real_size(other.m_real_size) {}
112 inline uint8_t raw_width()
const {
return N; }
113 inline void set_width_raw(uint8_t) { }
115 struct DynamicBitPackingVectorRepr {
116 using internal_data_type = DynamicIntValueType;
118 std::vector<internal_data_type> m_vec;
119 uint64_t m_real_size;
122 inline DynamicBitPackingVectorRepr():
123 m_vec(), m_real_size(0), m_width(64) {}
124 inline DynamicBitPackingVectorRepr(
const DynamicBitPackingVectorRepr& other):
125 m_vec(other.m_vec), m_real_size(other.m_real_size), m_width(other.m_width) {}
126 inline DynamicBitPackingVectorRepr(DynamicBitPackingVectorRepr&& other):
127 m_vec(std::move(other.m_vec)), m_real_size(other.m_real_size), m_width(other.m_width) {}
129 inline uint8_t raw_width()
const {
return m_width; }
130 inline void set_width_raw(uint8_t width) { m_width = width; }
133 template<
typename T,
typename X =
void>
137 struct IntRepr<uint_impl_t<N>, typename std::enable_if_t<(N > 1) && (N <= 32)>> {
139 using mem_rw = DynamicWidthMemRw;
140 using IntOpDispatch = RefDispatch<uint32_t, mem_rw>;
142 using ConstIntPtrBase = IntPtrFixedWidthRepr<DynamicIntValueType const*, N>;
143 using IntPtrBase = IntPtrFixedWidthRepr<DynamicIntValueType*, N>;
145 using BitPackingVectorRepr = FixedBitPackingVectorRepr<N>;
149 struct IntRepr<uint_impl_t<N>, typename std::enable_if_t<(N > 32) && (N <= 64)>> {
151 using mem_rw = DynamicWidthMemRw;
152 using IntOpDispatch = RefDispatch<uint64_t, mem_rw>;
154 using ConstIntPtrBase = IntPtrFixedWidthRepr<DynamicIntValueType const*, N>;
155 using IntPtrBase = IntPtrFixedWidthRepr<DynamicIntValueType*, N>;
157 using BitPackingVectorRepr = FixedBitPackingVectorRepr<N>;
161 struct IntRepr<bool> {
162 using value_type = bool;
163 using mem_rw = BitWidthMemRw;
164 using IntOpDispatch = RefDispatch<uint32_t, mem_rw>;
166 using ConstIntPtrBase = IntPtrFixedWidthRepr<DynamicIntValueType const*, 1>;
167 using IntPtrBase = IntPtrFixedWidthRepr<DynamicIntValueType*, 1>;
169 using BitPackingVectorRepr = FixedBitPackingVectorRepr<1>;
173 struct IntRepr<dynamic_t> {
174 using value_type = uint64_t;
175 using mem_rw = DynamicWidthMemRw;
176 using IntOpDispatch = RefDispatch<uint64_t, mem_rw>;
178 using ConstIntPtrBase = IntPtrDynamicWidthRepr<DynamicIntValueType const*>;
179 using IntPtrBase = IntPtrDynamicWidthRepr<DynamicIntValueType*>;
181 using BitPackingVectorRepr = DynamicBitPackingVectorRepr;
185 struct IntRepr<uint_impl_t<N>, typename std::enable_if_t<(N <= 1)>>;
188 struct IntRepr<uint_impl_t<N>, typename std::enable_if_t<(N > 64)>>;
Contains the text compression and encoding framework.
Custom integer type for storing values of arbitrary bit size bits.