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];
70 for (
size_t j = 0; j < l; j++) {
72 value +=
Tree[j][sequence_idx];
75 Tree[l][node >> (l + 1)] = value;
80 virtual uint64_t
prefix(
size_t idx) {
84 const int height =
rho(idx);
85 size_t level_idx = idx >> (1 + height);
86 sum +=
Tree[height][level_idx];
94 virtual void add(
size_t idx, int64_t inc) {
96 const int height =
rho(idx);
97 size_t level_idx = idx >> (1 + height);
98 Tree[height][level_idx] += inc;
105 virtual size_t find(uint64_t *val) {
106 size_t node = 0, idx = 0;
108 for (
size_t height =
Levels - 1; height != SIZE_MAX; height--) {
113 if (pos >=
Tree[height].
size())
continue;
115 uint64_t value =
Tree[height][pos];
119 node += 1ULL << height;
123 return min(node,
Size);
128 size_t node = 0, idx = 0;
130 for (
size_t height =
Levels - 1; height != SIZE_MAX; height--) {
135 if (pos >=
Tree[height].
size())
continue;
137 uint64_t value = (BOUND << height) -
Tree[height][pos];
141 node += 1ULL << height;
145 return min(node,
Size);
148 virtual void push(uint64_t val) {
152 size_t level_idx =
Size >> (1 + height);
155 Tree[height][level_idx] = val;
157 size_t idx = level_idx << 1;
158 for (
size_t h = height - 1; h != SIZE_MAX; h--) {
159 Tree[height][level_idx] +=
Tree[h][idx];
160 idx = (idx << 1) + 1;
169 virtual void grow(
size_t space) {
170 size_t levels =
lambda(space) + 1;
171 for (
size_t i = 0; i < levels; i++)
Tree[i].
grow((space + (1ULL << i)) / (1ULL << (i + 1)));
175 size_t levels =
lambda(space) + 1;
176 for (
size_t i = 0; i < levels; i++)
Tree[i].
reserve((space + (1ULL << i)) / (1ULL << (i + 1)));
180 virtual void trim(
size_t space) {
181 size_t levels =
lambda(space) + 1;
182 for (
size_t i = 0; i < levels; i++)
Tree[i].
trim((space + (1ULL << i)) / (1ULL << (i + 1)));
186 size_t levels =
lambda(space) + 1;
187 for (
size_t i = 0; i < levels; i++)
Tree[i].
resize((space + (1ULL << i)) / (1ULL << (i + 1)));
190 virtual void size(
size_t space) {
191 size_t levels =
lambda(space) + 1;
192 for (
size_t i = 0; i < levels; i++)
Tree[i].
size((space + (1ULL << i)) / (1ULL << (i + 1)));
198 size_t ret =
sizeof(*this) * 8;
199 for (
size_t i = 0; i < 64; i++) ret +=
Tree[i].
bitCount() -
sizeof(
Tree[i]) * 8;
205 os.write((
char *)&ft.
Size,
sizeof(uint64_t));
206 os.write((
char *)&ft.
Levels,
sizeof(uint64_t));
207 for (
size_t i = 0; i < 64; i++) os << ft.
Tree[i];
212 is.read((
char *)&ft.
Size,
sizeof(uint64_t));
213 is.read((
char *)&ft.
Levels,
sizeof(uint64_t));
214 for (
size_t i = 0; i < ft.
Levels; i++) is >> ft.
Tree[i];
virtual void push(uint64_t val)
Definition: FenwickFixedL.hpp:148
virtual void add(size_t idx, int64_t inc)
Definition: FenwickFixedL.hpp:94
int rho(uint64_t word)
Definition: common.hpp:168
Definition: Expandable.hpp:37
virtual size_t find(uint64_t *val)
Definition: FenwickFixedL.hpp:105
void trimToFit()
Definition: Expandable.hpp:93
Definition: Expandable.hpp:43
virtual size_t compFind(uint64_t *val)
Definition: FenwickFixedL.hpp:127
virtual size_t find(uint64_t *val)=0
virtual size_t bitCount() const
Definition: FenwickFixedL.hpp:197
virtual uint64_t prefix(size_t idx)
Definition: FenwickFixedL.hpp:80
virtual void resize(size_t space)
Definition: FenwickFixedL.hpp:185
static constexpr size_t BOUNDSIZE
Definition: FenwickFixedL.hpp:44
virtual void trim(size_t space)
Definition: FenwickFixedL.hpp:180
constexpr size_t ceil_log2_plus1(size_t n)
Definition: common.hpp:100
size_t Levels
Definition: FenwickFixedL.hpp:49
virtual void size(size_t space)
Definition: FenwickFixedL.hpp:190
Definition: FenwickFixedL.hpp:42
uint64_t clear_rho(uint64_t word)
Definition: common.hpp:194
size_t Size
Definition: FenwickFixedL.hpp:49
int lambda(uint64_t word)
Definition: common.hpp:178
FenwickFixedL(uint64_t sequence[], size_t size)
Definition: FenwickFixedL.hpp:63
Definition: SearchablePrefixSums.hpp:53
FenwickFixedL()
Definition: FenwickFixedL.hpp:53
virtual void grow(size_t space)
Definition: FenwickFixedL.hpp:169
Vector< uint64_t, AT > Tree[64]
Definition: FenwickFixedL.hpp:45
void resize(size_t size)
Definition: Vector.hpp:166
friend std::ostream & operator<<(std::ostream &os, const FenwickFixedL< BOUND, AT > &ft)
Definition: FenwickFixedL.hpp:204
virtual void pop()
Definition: FenwickFixedL.hpp:164
uint64_t mask_rho(uint64_t word)
Definition: common.hpp:208
friend std::istream & operator>>(std::istream &is, FenwickFixedL< BOUND, AT > &ft)
Definition: FenwickFixedL.hpp:211
T popBack()
Definition: Vector.hpp:200
virtual void reserve(size_t space)
Definition: FenwickFixedL.hpp:174
virtual size_t compFind(uint64_t *val)=0
virtual size_t size() const
Definition: FenwickFixedL.hpp:195