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 const size_t lowpos = (
BOUNDSIZE + j) * sequence_idx;
77 const size_t highpos = (
BOUNDSIZE + l) * (node >> (l + 1));
83 virtual uint64_t
prefix(
size_t idx) {
87 const int height =
rho(idx);
88 const size_t pos = (idx >> (1 + height)) * (
BOUNDSIZE + height);
97 virtual void add(
size_t idx, int64_t inc) {
99 const int height =
rho(idx);
100 const size_t pos = (idx >> (1 + height)) * (
BOUNDSIZE + height);
108 virtual size_t find(uint64_t *val) {
109 size_t node = 0, idx = 0;
111 for (
size_t height =
Levels - 1; height != SIZE_MAX; height--) {
112 const size_t pos = idx * (
BOUNDSIZE + height);
123 node += 1ULL << height;
127 return min(node,
Size);
132 size_t node = 0, idx = 0;
134 for (
size_t height =
Levels - 1; height != SIZE_MAX; height--) {
135 const size_t pos = idx * (
BOUNDSIZE + height);
141 const uint64_t value = (BOUND << height) -
bitread(&
Tree[height][pos / 8], pos % 8,
BOUNDSIZE + height);
146 node += 1ULL << height;
150 return min(node,
Size);
153 virtual void push(uint64_t val) {
157 size_t idx =
Size >> (1 + height);
158 size_t hipos = (
BOUNDSIZE + height) * idx;
164 for (
size_t h = height - 1; h != SIZE_MAX; h--) {
169 idx = (idx << 1) + 1;
180 virtual void grow(
size_t space) {
181 size_t levels =
lambda(space) + 1;
182 for (
size_t i = 0; i < levels; i++)
Tree[i].
grow(((space + (1ULL << i)) / (1ULL << (i + 1))) * (
BOUNDSIZE + i) / 8 + 8);
186 size_t levels =
lambda(space) + 1;
187 for (
size_t i = 0; i < levels; i++)
Tree[i].
reserve(((space + (1ULL << i)) / (1ULL << (i + 1))) * (
BOUNDSIZE + i) / 8 + 8);
191 virtual void trim(
size_t space) {
192 size_t levels =
lambda(space) + 1;
193 for (
size_t i = 0; i < levels; i++)
Tree[i].
trim(((space + (1ULL << i)) / (1ULL << (i + 1))) * (
BOUNDSIZE + i) / 8 + 8);
197 size_t levels =
lambda(space) + 1;
198 for (
size_t i = 0; i < levels; i++)
Tree[i].
resize(((space + (1ULL << i)) / (1ULL << (i + 1))) * (
BOUNDSIZE + i) / 8 + 8);
201 virtual void size(
size_t space) {
202 size_t levels =
lambda(space) + 1;
203 for (
size_t i = 0; i < levels; i++)
Tree[i].
size(((space + (1ULL << i)) / (1ULL << (i + 1))) * (
BOUNDSIZE + i) / 8 + 8);
209 size_t ret =
sizeof(*this) * 8;
210 for (
size_t i = 0; i < 64; i++) ret +=
Tree[i].
bitCount() -
sizeof(
Tree[i]) * 8;
216 os.write((
char *)&ft.
Size,
sizeof(uint64_t));
217 os.write((
char *)&ft.
Levels,
sizeof(uint64_t));
218 for (
size_t i = 0; i < ft.
Levels; i++) os << ft.
Tree[i];
223 is.read((
char *)&ft.
Size,
sizeof(uint64_t));
224 is.read((
char *)&ft.
Levels,
sizeof(uint64_t));
225 for (
size_t i = 0; i < ft.
Levels; i++) is >> ft.
Tree[i];
FenwickBitL(uint64_t sequence[], size_t size)
Definition: FenwickBitL.hpp:63
void bitwrite_inc(void *const word, int from, int length, uint64_t inc)
Definition: common.hpp:315
int rho(uint64_t word)
Definition: common.hpp:168
Vector< uint8_t, AT > Tree[64]
Definition: FenwickBitL.hpp:45
Definition: Expandable.hpp:37
void trimToFit()
Definition: Expandable.hpp:93
Definition: Expandable.hpp:43
virtual size_t find(uint64_t *val)=0
Definition: FenwickBitL.hpp:42
size_t Size
Definition: FenwickBitL.hpp:49
static constexpr size_t BOUNDSIZE
Definition: FenwickBitL.hpp:44
void size(size_t size)
Definition: Vector.hpp:178
constexpr size_t ceil_log2_plus1(size_t n)
Definition: common.hpp:100
friend std::ostream & operator<<(std::ostream &os, const FenwickBitL< BOUND, AT > &ft)
Definition: FenwickBitL.hpp:215
uint64_t bitread(const void *const word, int from, int length)
Definition: common.hpp:280
uint64_t clear_rho(uint64_t word)
Definition: common.hpp:194
virtual void size(size_t space)
Definition: FenwickBitL.hpp:201
int lambda(uint64_t word)
Definition: common.hpp:178
virtual void push(uint64_t val)
Definition: FenwickBitL.hpp:153
virtual void reserve(size_t space)
Definition: FenwickBitL.hpp:185
Definition: SearchablePrefixSums.hpp:53
virtual void pop()
Definition: FenwickBitL.hpp:173
void resize(size_t size)
Definition: Vector.hpp:166
virtual size_t find(uint64_t *val)
Definition: FenwickBitL.hpp:108
size_t Levels
Definition: FenwickBitL.hpp:49
friend std::istream & operator>>(std::istream &is, FenwickBitL< BOUND, AT > &ft)
Definition: FenwickBitL.hpp:222
virtual void add(size_t idx, int64_t inc)
Definition: FenwickBitL.hpp:97
virtual void trim(size_t space)
Definition: FenwickBitL.hpp:191
uint64_t mask_rho(uint64_t word)
Definition: common.hpp:208
virtual size_t size() const
Definition: FenwickBitL.hpp:206
virtual size_t bitCount() const
Definition: FenwickBitL.hpp:208
virtual uint64_t prefix(size_t idx)
Definition: FenwickBitL.hpp:83
FenwickBitL()
Definition: FenwickBitL.hpp:53
virtual size_t compFind(uint64_t *val)
Definition: FenwickBitL.hpp:131
virtual void grow(size_t space)
Definition: FenwickBitL.hpp:180
virtual size_t compFind(uint64_t *val)=0
virtual void resize(size_t space)
Definition: FenwickBitL.hpp:196