An implementation of a binary indexed tree (or Fenwick tree) data structure in Rust.
fenwick-tree
provides simple implementation of the Fenwick tree that can be used as a building block in some of the algorithms (e.g. weighted random).
The basic API is simple and consists of add
and sum
methods (both take O(log n) time). Here is a quick example:
```rust
use fenwick_tree::FenwickTree;
let mut tree = FenwickTree::
for i in 0..5 { tree.add(i, i as i32)?; }
asserteq!(tree.sum(0..5)?, 0 + 1 + 2 + 3 + 4); asserteq!(tree.sum(2..5)?, 2 + 3 + 4); ```
For more details see documentation.
The package is licensed under the MIT license.
There are no strict rules for contributing. Feel free to open an issue or submit a pull request.