the prefix aggregates of \( n \) values of the monoid G
More...
#include <ADS/sequence/Fenwick.h>
|
| using | Value = typename G::Value |
| | the values
|
| using | Algebra = G |
| | their algebra
|
|
| | Fenwick (std::size_t n=0) |
| | \( n \) values, all the identity
|
| template<std::input_iterator I> |
| | Fenwick (I first, I last) |
| | the values of \( [ \mathit{first} , \mathit{last} ) \), in \( O( n ) \) time
|
| std::size_t | size (void) const |
| | the number \( n \) of values
|
| bool | empty (void) const |
| | whether there is no value
|
| const Value & | get (std::size_t i) const |
| | the value \( a_i \)
|
| Value | prefix (std::size_t r) const |
| | the prefix \( \pi_r = a_0 \oplus \cdots \oplus a_{r-1} \), the identity if \( r = 0 \), in \( O( \log n ) \) time
|
| Value | range (std::size_t l, std::size_t r) const |
| | the range \( a_l \oplus \cdots \oplus a_{r-1} \), i.e., \( \pi_l^{-1} \oplus \pi_r \), in \( O( \log n ) \) time
|
| void | set (std::size_t i, const Value &v) |
| | \( a_i \gets v \): by the difference in \( O( \log n ) \) time in an abelian group, by the parts of the nodes in \( O( \log^2 n ) \) time otherwise
|
| void | add (std::size_t i, const Value &d) |
| | \( a_i \gets a_i \oplus d \), in \( O( \log n ) \) time
|
| void | push_back (const Value &v) |
| | \( v \) appended as \( a_n \), its node built in \( O( \log n ) \) time
|
| void | pop_back (void) |
| | the last value removed, in \( O( 1 ) \) time, since no other node contains it
|
| void | clear (void) noexcept |
| | all the values removed
|
| template<std::input_iterator I> |
| void | assign (I first, I last) |
| | the values of \( [ \mathit{first} , \mathit{last} ) \) in place of all the others, the nodes built in \( O( n ) \) time
|
| std::size_t | period (void) const |
| | the updates by difference after which a group of floating point values is rebuilt from its values
|
| void | period (std::size_t p) |
| | sets the period of the rebuilding to \( p \)
|
template<Monoid G>
class ADS::Fenwick< G >
the prefix aggregates of \( n \) values of the monoid G
◆ Algebra
◆ Value
◆ Fenwick() [1/2]
\( n \) values, all the identity
◆ Fenwick() [2/2]
template<Monoid G>
template<std::input_iterator I>
the values of \( [ \mathit{first} , \mathit{last} ) \), in \( O( n ) \) time
◆ add()
\( a_i \gets a_i \oplus d \), in \( O( \log n ) \) time
- Precondition
- \( i < n \)
◆ assign()
template<Monoid G>
template<std::input_iterator I>
the values of \( [ \mathit{first} , \mathit{last} ) \) in place of all the others, the nodes built in \( O( n ) \) time
◆ clear()
◆ empty()
whether there is no value
◆ get()
the value \( a_i \)
- Precondition
- \( i < n \)
◆ period() [1/2]
sets the period of the rebuilding to \( p \)
- Precondition
- \( p \ge 1 \)
◆ period() [2/2]
the updates by difference after which a group of floating point values is rebuilt from its values
◆ pop_back()
the last value removed, in \( O( 1 ) \) time, since no other node contains it
- Precondition
- the tree is not empty
◆ prefix()
the prefix \( \pi_r = a_0 \oplus \cdots \oplus a_{r-1} \), the identity if \( r = 0 \), in \( O( \log n ) \) time
In pseudocode (Fenwick, beyond the book), \( \lambda( j ) \) the lowest bit of \( j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{prefix}( r ) \cr
2 & \quad x \gets e;\ j \gets r \cr
3 & \quad \textbf{while}\ j > 0\ \textbf{do}\ x \gets t_j \oplus x;
\ j \gets j - \lambda( j ) \cr
4 & \quad \textbf{return}\ x
\end{array}}
\]
- Precondition
- \( r \le n \)
◆ push_back()
\( v \) appended as \( a_n \), its node built in \( O( \log n ) \) time
◆ range()
the range \( a_l \oplus \cdots \oplus a_{r-1} \), i.e., \( \pi_l^{-1} \oplus \pi_r \), in \( O( \log n ) \) time
- Precondition
- \( l \le r \le n \)
◆ set()
\( a_i \gets v \): by the difference in \( O( \log n ) \) time in an abelian group, by the parts of the nodes in \( O( \log^2 n ) \) time otherwise
In pseudocode (beyond the book), \( \delta = a_i^{-1} \oplus v \) in an abelian group:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{set}( i , v ) \cr
2 & \quad \delta \gets a_i^{-1} \oplus v;\ a_i \gets v;\ j \gets i +
1 \cr
3 & \quad \textbf{while}\ j \le n\ \textbf{do}\ t_j \gets t_j \oplus
\delta\ \text{(in a group)},\ t_j \gets \mathrm{node}( j )
\ \text{(otherwise)};\ j \gets j + \lambda( j ) \cr
4 & \textbf{function}\ \mathrm{node}( j ) \cr
5 & \quad x \gets e;\ k \gets \lambda( j ) / 2 \cr
6 & \quad \textbf{while}\ k \ge 1\ \textbf{do}\ x \gets x \oplus
t_{j - k};\ k \gets k / 2 \cr
7 & \quad \textbf{return}\ x \oplus a_{j-1}
\end{array}}
\]
- Precondition
- \( i < n \)
◆ size()
the number \( n \) of values
The documentation for this class was generated from the following file: