rs-collections-fenwick 0.1.0
Fenwick tree and segment tree for range sum, min and max with point and range updates
Install
cargo add rs-collections-fenwick --registry rupm
In Ruststudio: Packages, search for rs-collections-fenwick, Install.
Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.
Versions
- 0.1.0 2026-11-23
README
# rs-collections-fenwick
A Fenwick (binary indexed) tree for prefix and range sums with point updates, plus a lazy segment tree for range sum, min and max with point and range updates. Out-of-range queries return empty results instead of panicking.
## Install
Add it with `rupm add rs-collections-fenwick` (or `cargo add rs-collections-fenwick --registry rupm`).
## Usage
```rust
use rs_collections_fenwick::{Fenwick, SegmentTree};
let mut f = Fenwick::from_slice(&[1, 2, 3, 4]);
f.add(0, 10);
assert_eq!(f.range_sum(0, 2), 13);
let mut s = SegmentTree::new(&[5, 1, 4, 2]);
s.range_add(0, 2, 10);
assert_eq!(s.max(0, 4), Some(15));
```
## API overview
- `Fenwick`: `new`, `from_slice`, `add`, `prefix_sum`, `range_sum`, `get`, `len`
- `SegmentTree`: `new`, `range_add`, `point_add`, `point_set`, `get`, `sum`, `min`, `max`, `len`
- Ranges are half-open (`start..end`).