-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for FenwickTree (#492)
Add documentation for FenwickTree
- Loading branch information
1 parent
e0cc5d0
commit 640379b
Showing
4 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Fenwick Tree | ||
|
||
The `FenwickTree` type is data structures which is used for handling increment and decrement to prefix-sums of an array efficiently. | ||
|
||
Usage: | ||
|
||
```julia | ||
FenwickTree{T}(n) # Constructs a Fenwick Tree of length `n` | ||
FenwickTree{T}(counts) # Constructs a Fenwick Tree from an array of `counts` | ||
inc!(ft, ind, val) # Increases the value of the FenwickTree `ft` by `val` from the index `ind` upto the length of `ft` | ||
dec!(ft, ind, val) # Decreases the value of the FenwickTree `ft` by `val` from the index `ind` upto the length of `ft` | ||
incdec!(ft, left, right, val) # Increases the value of the FenwickTree `ft` by `val` from the indices from `left` and decreases it from the `right` | ||
prefixsum(ft, ind) # Return the cumulative sum from index 1 upto `ind` of the FenwickTree `ft` | ||
``` | ||
|
||
Examples: | ||
|
||
```julia | ||
julia> f = FenwickTree{Int}(6) | ||
julia> inc!(f, 2, 5) | ||
julia> prefixsum(f, 1) | ||
0 | ||
julia> prefixsum(f, 3) | ||
5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters