106 : f_a( n , G::identity() ) , f_t( n , G::identity() ) { }
110 template< std::input_iterator I >
116 [[nodiscard]] std::size_t
size(
void )
const {
return( f_a.size() ); }
119 [[nodiscard]]
bool empty(
void )
const {
return( f_a.empty() ); }
123 [[nodiscard]]
const Value &
get( std::size_t i )
const {
148 [[nodiscard]]
Value range( std::size_t l , std::size_t r )
const
202 template< std::input_iterator I >
207 [[nodiscard]] std::size_t
period(
void )
const {
return( f_period ); }
219 [[nodiscard]]
Value node( std::size_t j )
const;
225 void counted(
void );
228 static std::size_t low( std::size_t j ) {
return( j & ( ~j + 1 ) ); }
230 std::vector< Value > f_a;
231 std::vector< Value > f_t;
232 std::size_t f_since = 0;
233 std::size_t f_period = 4096;
248 using Value =
typename G::Value;
264 requires requires(
const A & a ) {
265 { a.values() } -> std::same_as< const std::vector< Value > & >;
274 requires requires(
const A & a ) {
275 { a.values() } -> std::same_as< const std::vector< Value > & >;
279 f_f.assign( f_src->begin() , f_src->end() );
286 f_f.set( e.
h , e.
to );
293 f_f.push_back( e.
value );
299 if( ! f_stale && ! f_f.empty() )
316 f_f.assign( f_src->begin() , f_src->end() );
322 [[nodiscard]] std::size_t
size(
void )
const {
324 return( f_f.size() );
329 [[nodiscard]] Value
prefix( std::size_t r )
const {
331 return( f_f.prefix( r ) );
336 [[nodiscard]] Value
range( std::size_t l , std::size_t r )
const
340 return( f_f.range( l , r ) );
352 [[nodiscard]]
bool audit(
const A & a )
const;
357 const std::vector< Value > * f_src =
nullptr;
358 mutable bool f_stale =
false;
370#include "ADS/sequence/impl/Fenwick.tpp"
The algebra of the aggregates, beyond the book: the concepts by which a structure that keeps a combin...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
void rebuild(const A &a)
the tree built again from the array , whose vector of values a.values() it reads from now on when Reb...
Definition Fenwick.h:277
mod::Erased< std::size_t, std::size_t, Value > Erase
the last value removed
Definition Fenwick.h:257
void on(const Erase &) noexcept
the last value removed
Definition Fenwick.h:298
bool audit(const A &a) const
whether the tree has the values of the array and, when they are exact, its prefixes are those of a s...
std::size_t size(void) const
the number of values
Definition Fenwick.h:322
void on(const Insert &e)
the value appended
Definition Fenwick.h:290
Value range(std::size_t l, std::size_t r) const
the range
Definition Fenwick.h:336
mod::Inserted< std::size_t, std::size_t, Value > Insert
a value appended
Definition Fenwick.h:255
Value prefix(std::size_t r) const
the prefix [see Fenwick::prefix()]
Definition Fenwick.h:329
FenwickObserver(const A &a)
the observer of the array , its tree built from it
Definition Fenwick.h:267
void on(const mod::Cleared &) noexcept
no value
Definition Fenwick.h:304
FenwickObserver(void)=default
an observer of no array, given one later by rebuild()
const Fenwick< G > & tree(void) const
the tree
Definition Fenwick.h:344
mod::Assigned< std::size_t, Value > Assign
a value written
Definition Fenwick.h:253
void flush(void) const
the tree built again if Rebuilt came
Definition Fenwick.h:313
void on(const Assign &e)
Definition Fenwick.h:284
void on(const mod::Rebuilt &) noexcept
the tree forgotten, built again at the next query
Definition Fenwick.h:310
the prefix aggregates of values of the monoid G
Definition Fenwick.h:97
void set(std::size_t i, const Value &v)
: by the difference in time in an abelian group, by the parts of the nodes in time otherwise
typename G::Value Value
the values
Definition Fenwick.h:101
void period(std::size_t p)
sets the period of the rebuilding to
Definition Fenwick.h:211
void clear(void) noexcept
all the values removed
Definition Fenwick.h:194
std::size_t period(void) const
the updates by difference after which a group of floating point values is rebuilt from its values
Definition Fenwick.h:207
const Value & get(std::size_t i) const
the value
Definition Fenwick.h:123
bool empty(void) const
whether there is no value
Definition Fenwick.h:119
Fenwick(I first, I last)
the values of , in time
Definition Fenwick.h:111
std::size_t size(void) const
the number of values
Definition Fenwick.h:116
Value prefix(std::size_t r) const
the prefix , the identity if , in time
void pop_back(void)
the last value removed, in time, since no other node contains it
Definition Fenwick.h:187
Fenwick(std::size_t n=0)
values, all the identity
Definition Fenwick.h:105
void assign(I first, I last)
the values of in place of all the others, the nodes built in time
G Algebra
their algebra
Definition Fenwick.h:102
void push_back(const Value &v)
appended as , its node built in time
void add(std::size_t i, const Value &d)
, in time
Value range(std::size_t l, std::size_t r) const
the range , i.e., , in time
a monoid whose operation commutes, by the opt-in G::commutative
Definition Algebra.h:125
a monoid with the inverse G::inverse( a ), i.e., combine( inverse( a) , a ) and combine( a ,...
Definition Algebra.h:130
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
V to
the value after
Definition Modification.h:608
H h
< the value
Definition Modification.h:606
the structure emptied
Definition Modification.h:699
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
the item of handle , key and value inserted
Definition Modification.h:536
V value
the value
Definition Modification.h:544
H h
< the value
Definition Modification.h:542
anything may have changed: forget and recompute
Definition Modification.h:708