1.0.0 • Published 8 years ago

nd-binary-indexed-tree v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

N-dimensional Binary Indexed Tree

Provides logarithmic time prefix-sums and updates to numeric data sets in 1, 2, 3, or more dimensions.

Check out Stack Overflow, Wikipedia, and TopCoder for an overview of the data structure in one dimension. GeeksForGeeks has a useful explanation of multi-dimensional generalization, but beware of buggy code.

NPM version Build Status

Getting Started

Install from NPM

$ npm install nd-binary-indexed-tree

Examples

const BITree = require('nd-binary-indexed-tree');
let biTree = new BITree({initialValues: [
  [3,  1, 5  ],
  [0, -1, 9.5],
  [4,  4, 90 ]
]});
biTree.sumPrefix([2, 1]); // 11
biTree.adjust([1, 1], +2);
biTree.sumPrefix([2, 1]); // 13
;

See tests for more examples.