A minimal implementation of a segment tree for storing run-length encoded arrays with updates.
var tree = require("segment-tree").zeros(10)
tree.set(1, 1)
tree.set(2, 1)
console.log(tree.pointers)
console.log(tree.values)
npm install segment-tree
var SegmentTree = require("segment-tree")
SegmentTree(size, pointers, values)SegmentTree constructor
size is the size of the segment treepointers is a sorted list of pointersvalues is a sorted list of valuesSegmentTree.proto.get(index)Retrieves the value index
index is the coordinate of the value to retrieveReturns The value at index
SegmentTree.proto.set(index, v)Sets the value at index to v
index is the index to updatev is the new valueReturns v
SegmentTree.zeros(size)Create an empty segment tree
size is the size of the new segment treeReturns A new segment tree
(c) 2013 Mikola Lysenko. MIT License