Go to the documentation of this file.
66 for (
size_t l = 0; l <
Levels; l++) {
67 for (
size_t node = 1ULL << l; node <=
Size; node += 1ULL << (l + 1)) {
68 size_t sequence_idx = node - 1;
69 uint64_t value = sequence[sequence_idx];
71 for (
size_t j = 0; j < l; j++) {
73 size_t lowpos = heightsize(j) * sequence_idx;
77 size_t highpos = heightsize(l) * (node >> (l + 1));
83 virtual uint64_t
prefix(
size_t idx) {
87 const int height =
rho(idx);
88 const size_t isize = heightsize(height);
89 const size_t pos = (idx >> (1 + height)) * isize;
98 virtual void add(
size_t idx, int64_t inc) {
100 int height =
rho(idx);
101 size_t isize = heightsize(height);
102 size_t pos = (idx >> (1 + height)) * isize;
110 virtual size_t find(uint64_t *val) {
111 size_t node = 0, idx = 0;
113 for (
size_t height =
Levels - 1; height != SIZE_MAX; height--) {
114 const size_t isize = heightsize(height);
115 const size_t pos = idx * heightsize(height);
119 if (pos >=
Tree[height].
size() - 8)
continue;
121 const uint64_t value =
byteread(&
Tree[height][pos], isize);
126 node += 1ULL << height;
130 return min(node,
Size);
135 size_t node = 0, idx = 0;
137 for (
size_t height =
Levels - 1; height != SIZE_MAX; height--) {
138 const size_t isize = heightsize(height);
139 const size_t pos = idx * heightsize(height);
143 if (pos >=
Tree[height].
size() - 8)
continue;
145 const uint64_t value = (BOUND << height) -
byteread(&
Tree[height][pos], isize);
150 node += 1ULL << height;
154 return min(node,
Size);
157 virtual void push(uint64_t val) {
161 size_t idx =
Size >> (1 + height);
162 size_t hisize = heightsize(height);
163 size_t highpos = idx * hisize;
169 for (
size_t h = height - 1; h != SIZE_MAX; h--) {
170 size_t losize = heightsize(h);
171 size_t lowpos = idx * losize;
177 idx = (idx << 1) + 1;
183 Tree[height].
resize((
Size >> (1 + height)) * heightsize(height) + 7);
187 virtual void grow(
size_t space) {
188 size_t levels =
lambda(space) + 1;
189 for (
size_t i = 0; i < levels; i++)
Tree[i].
grow(((space + (1ULL << i)) / (1ULL << (i + 1))) * heightsize(i) + 8);
193 size_t levels =
lambda(space) + 1;
194 for (
size_t i = 0; i < levels; i++)
Tree[i].
reserve(((space + (1ULL << i)) / (1ULL << (i + 1))) * heightsize(i) + 8);
198 virtual void trim(
size_t space) {
199 size_t levels =
lambda(space) + 1;
200 for (
size_t i = 0; i < levels; i++)
Tree[i].
trim(((space + (1ULL << i)) / (1ULL << (i + 1))) * heightsize(i) + 8);
204 size_t levels =
lambda(space) + 1;
205 for (
size_t i = 0; i < levels; i++)
Tree[i].
resize(((space + (1ULL << i)) / (1ULL << (i + 1))) * heightsize(i) + 8);
208 virtual void size(
size_t space) {
209 size_t levels =
lambda(space) + 1;
210 for (
size_t i = 0; i < levels; i++)
Tree[i].
size(((space + (1ULL << i)) / (1ULL << (i + 1))) * heightsize(i) + 8);
216 size_t ret =
sizeof(*this) * 8;
217 for (
size_t i = 0; i < 64; i++) ret +=
Tree[i].
bitCount() -
sizeof(
Tree[i]) * 8;
222 static inline size_t heightsize(
size_t height) {
return ((height +
BOUNDSIZE - 1) >> 3) + 1; }
225 os.write((
char *)&ft.
Size,
sizeof(uint64_t));
226 os.write((
char *)&ft.
Levels,
sizeof(uint64_t));
227 for (
size_t i = 0; i < ft.
Levels; i++) os << ft.
Tree[i];
232 is.read((
char *)&ft.
Size,
sizeof(uint64_t));
233 is.read((
char *)&ft.
Levels,
sizeof(uint64_t));
234 for (
size_t i = 0; i < ft.
Levels; i++) is >> ft.
Tree[i];
int rho(uint64_t word)
Definition: common.hpp:168
Definition: Expandable.hpp:37
FenwickByteL(uint64_t sequence[], size_t size)
Definition: FenwickByteL.hpp:63
void trimToFit()
Definition: Expandable.hpp:93
virtual void size(size_t space)
Definition: FenwickByteL.hpp:208
Definition: Expandable.hpp:43
friend std::ostream & operator<<(std::ostream &os, const FenwickByteL< BOUND, AT > &ft)
Definition: FenwickByteL.hpp:224
virtual size_t find(uint64_t *val)=0
void bytewrite(void *const word, int length, uint64_t val)
Definition: common.hpp:265
static constexpr size_t BOUNDSIZE
Definition: FenwickByteL.hpp:44
size_t Levels
Definition: FenwickByteL.hpp:49
FenwickByteL()
Definition: FenwickByteL.hpp:53
virtual size_t size() const
Definition: FenwickByteL.hpp:213
virtual void reserve(size_t space)
Definition: FenwickByteL.hpp:192
constexpr size_t ceil_log2_plus1(size_t n)
Definition: common.hpp:100
virtual size_t find(uint64_t *val)
Definition: FenwickByteL.hpp:110
virtual size_t bitCount() const
Definition: FenwickByteL.hpp:215
virtual uint64_t prefix(size_t idx)
Definition: FenwickByteL.hpp:83
virtual void push(uint64_t val)
Definition: FenwickByteL.hpp:157
uint64_t clear_rho(uint64_t word)
Definition: common.hpp:194
int lambda(uint64_t word)
Definition: common.hpp:178
Definition: SearchablePrefixSums.hpp:53
virtual void pop()
Definition: FenwickByteL.hpp:181
virtual size_t compFind(uint64_t *val)
Definition: FenwickByteL.hpp:134
void resize(size_t size)
Definition: Vector.hpp:166
Definition: FenwickByteL.hpp:42
virtual void grow(size_t space)
Definition: FenwickByteL.hpp:187
virtual void trim(size_t space)
Definition: FenwickByteL.hpp:198
uint64_t mask_rho(uint64_t word)
Definition: common.hpp:208
virtual void add(size_t idx, int64_t inc)
Definition: FenwickByteL.hpp:98
void bytewrite_inc(void *const word, uint64_t inc)
Definition: common.hpp:273
friend std::istream & operator>>(std::istream &is, FenwickByteL< BOUND, AT > &ft)
Definition: FenwickByteL.hpp:231
virtual void resize(size_t space)
Definition: FenwickByteL.hpp:203
virtual size_t compFind(uint64_t *val)=0
size_t Size
Definition: FenwickByteL.hpp:49
uint64_t byteread(const void *const word, int length)
Definition: common.hpp:259
Vector< uint8_t, AT > Tree[64]
Definition: FenwickByteL.hpp:45