Title: | Binary Indexed Tree |
Version: | 1.0.0 |
Author: | Jialun Zhang, Zhilan Fan, Hang Zhang |
Maintainer: | Jialun Zhang <reatank@foxmail.com> |
Description: | A simple implementation of Binary Indexed Tree by R. The BinaryIndexedTree class supports construction of Binary Indexed Tree from a vector, update of a value in the vector and query for the sum of a interval of the vector. |
License: | MIT + file LICENSE |
LazyData: | true |
Imports: | R6 |
Encoding: | UTF-8 |
RoxygenNote: | 6.0.1 |
NeedsCompilation: | no |
Packaged: | 2018-07-20 08:38:26 UTC; Konata |
Repository: | CRAN |
Date/Publication: | 2018-07-22 13:50:03 UTC |
A simple implementation of Binary Indexed Tree as an R6 class.
Description
Methods:
-
new(init)
Initializes from a vector init. -
update(location, new.val)
Replaces the item at location with new.val. -
query(l, r)
Returns the sum of the interval [l, r]. -
show.BIT ()
Returns the Binary Indexed Tree. -
show.origin()
Returns the vector.
Usage
BinaryIndexedTree
Format
An object of class R6ClassGenerator
of length 24.
Examples
tmp <- BinaryIndexedTree$new(c(2,3,2,5,1))
tmp$update(1,3)
tmp$query(1,5)
tmp$show.origin()
tmp$show.BIT()