0.1.2 • Published 12 years ago
segment-tree v0.1.2
segment-tree
A minimal implementation of a segment tree for storing run-length encoded arrays with updates.
Example
var tree = require("segment-tree").zeros(10)
tree.set(1, 1)
tree.set(2, 1)
console.log(tree.pointers)
console.log(tree.values)Install
npm install segment-treeAPI
var SegmentTree = require("segment-tree")SegmentTree(size, pointers, values)
SegmentTree constructor
sizeis the size of the segment treepointersis a sorted list of pointersvaluesis a sorted list of values
SegmentTree.proto.get(index)
Retrieves the value index
indexis the coordinate of the value to retrieve
Returns The value at index
SegmentTree.proto.set(index, v)
Sets the value at index to v
indexis the index to updatevis the new value
Returns v
SegmentTree.zeros(size)
Create an empty segment tree
sizeis the size of the new segment tree
Returns A new segment tree
Credits
(c) 2013 Mikola Lysenko. MIT License