Go to the documentation of this file.
67 for (
size_t idx = 1; idx <=
Size; idx++) addToPartialFrequency(idx, sequence[idx - 1]);
69 for (
size_t m = 2; m <=
Size; m <<= 1)
70 for (
size_t idx = m; idx <=
Size; idx += m) addToPartialFrequency(idx, getPartialFrequency(idx - m / 2));
73 virtual uint64_t
prefix(
size_t idx) {
77 sum += getPartialFrequency(idx);
84 virtual void add(
size_t idx, int64_t inc) {
86 addToPartialFrequency(idx, inc);
92 virtual size_t find(uint64_t *val) {
96 if (node + m >
Size)
continue;
98 const uint64_t value = getPartialFrequency(node + m);
114 if (node + m >
Size)
continue;
116 const int height =
rho(node + m);
117 const uint64_t value = (BOUND << height) - getPartialFrequency(node + m);
128 virtual void push(uint64_t val) {
130 addToPartialFrequency(
Size, val);
132 if ((
Size & 1) == 0) {
156 inline static size_t holes(
size_t idx) {
return STARTING_OFFSET + (idx >> 14) * 64; }
158 inline static size_t first_bit_after(
size_t idx) {
return (
BOUNDSIZE + 1) * idx -
nu(idx) + holes(idx); }
160 inline uint64_t getPartialFrequency(
size_t idx)
const {
161 const uint64_t mask = (UINT64_C(1) << (
BOUNDSIZE +
rho(idx))) - 1;
163 const uint64_t prod = (
BOUNDSIZE + 1) * idx;
164 const uint64_t pos = prod -
nu(idx) + holes(idx);
167 if ((prod + (
BOUNDSIZE + 1)) % 64 == 0) {
168 memcpy(&t, (uint64_t *)&
Tree[0] + pos / 64, 8);
169 return t >> (pos % 64) & mask;
171 memcpy(&t, &
Tree[0] + pos / 8, 8);
172 return t >> (pos % 8) & mask;
176 inline void addToPartialFrequency(
size_t idx, uint64_t value) {
178 const uint64_t prod = (
BOUNDSIZE + 1) * idx;
179 const uint64_t pos = prod -
nu(idx) + holes(idx);
182 if ((prod + (
BOUNDSIZE + 1)) % 64 == 0) {
183 uint64_t *
const p = (uint64_t *)&
Tree[0] + pos / 64;
185 t += value << (pos % 64);
188 uint8_t *
const p = &
Tree[0] + pos / 8;
190 t += value << (pos % 8);
196 os.write((
char *)&ft.
Size,
sizeof(uint64_t));
197 return os << ft.
Tree;
201 is.read((
char *)&ft.
Size,
sizeof(uint64_t));
202 return is >> ft.
Tree;
virtual void add(size_t idx, int64_t inc)
Definition: FenwickBitF.hpp:84
FenwickBitF(uint64_t sequence[], size_t size)
Definition: FenwickBitF.hpp:66
int rho(uint64_t word)
Definition: common.hpp:168
friend std::istream & operator>>(std::istream &is, FenwickBitF< BOUND, AT > &ft)
Definition: FenwickBitF.hpp:200
Definition: Expandable.hpp:37
virtual void size(size_t space)
Definition: FenwickBitF.hpp:149
Definition: Expandable.hpp:43
virtual void trimToFit()
Definition: FenwickBitF.hpp:145
virtual void push(uint64_t val)
Definition: FenwickBitF.hpp:128
virtual size_t find(uint64_t *val)=0
uint64_t mask_lambda(uint64_t word)
Definition: common.hpp:216
virtual void reserve(size_t space)
Definition: FenwickBitF.hpp:141
virtual size_t compFind(uint64_t *val)
Definition: FenwickBitF.hpp:110
void reserve(size_t capacity)
Definition: Vector.hpp:141
virtual void grow(size_t space)
Definition: FenwickBitF.hpp:139
void size(size_t size)
Definition: Vector.hpp:178
static constexpr size_t STARTING_OFFSET
Definition: FenwickBitF.hpp:45
void grow(size_t capacity)
Definition: Vector.hpp:153
virtual void trim(size_t space)
Definition: FenwickBitF.hpp:143
Definition: FenwickBitF.hpp:42
virtual size_t find(uint64_t *val)
Definition: FenwickBitF.hpp:92
static constexpr size_t END_PADDING
Definition: FenwickBitF.hpp:46
constexpr size_t ceil_log2_plus1(size_t n)
Definition: common.hpp:100
Vector< uint8_t, AT > Tree
Definition: FenwickBitF.hpp:47
size_t bitCount() const
Definition: Vector.hpp:231
uint64_t clear_rho(uint64_t word)
Definition: common.hpp:194
Definition: SearchablePrefixSums.hpp:53
int nu(uint64_t word)
Definition: common.hpp:339
void resize(size_t size)
Definition: Vector.hpp:166
FenwickBitF()
Definition: FenwickBitF.hpp:55
virtual size_t bitCount() const
Definition: FenwickBitF.hpp:153
virtual void resize(size_t space)
Definition: FenwickBitF.hpp:147
uint64_t mask_rho(uint64_t word)
Definition: common.hpp:208
static constexpr size_t BOUNDSIZE
Definition: FenwickBitF.hpp:44
size_t Size
Definition: FenwickBitF.hpp:51
virtual size_t size() const
Definition: FenwickBitF.hpp:151
void trim(size_t capacity)
Definition: Vector.hpp:127
virtual void pop()
Definition: FenwickBitF.hpp:137
friend std::ostream & operator<<(std::ostream &os, const FenwickBitF< BOUND, AT > &ft)
Definition: FenwickBitF.hpp:195
virtual size_t compFind(uint64_t *val)=0
virtual uint64_t prefix(size_t idx)
Definition: FenwickBitF.hpp:73