Skip to content

Commit

Permalink
Add documentation for bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ecnerwala committed Aug 25, 2020
1 parent 2cd5f2e commit 7a1b456
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
#include <vector>
#include <cassert>

/** Binary-indexed tree
*
* A binary indexed tree with N nodes of type T implicitly provides the
* following two functions for 0 <= i <= N:
*
* prefix(int i) -> list<T&>
* suffix(int i) -> list<T&>
*
* such that size(suffix(i) intersect prefix(j)) = (1 if i < j else 0).
* Furthermore, the resulting lists always have size at most log_2(N).
*
* This can be used to implement either point-update/(prefix|suffix)-query or
* (prefix|suffix)-update/point-query over a virtual array of size N of a
* commutative monoid. This can be generalized to implement
* point-update/range-query or range-update/point-query over a virtual array
* of size N of a commutative group.
*
* With 0-indexed data, prefixes are more natural:
* * For range update/query, use for_prefix for the ranges and for_suffix for the points.
* * For prefix update/query, no change.
* * For suffix update/query, use for_prefix(point + 1); 1-index the data.
*/
template <typename T> struct bit {
private:
std::vector<T> dat;
Expand Down

0 comments on commit 7a1b456

Please sign in to comment.