
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
segment-tree
Advanced tools
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.length)
console.log(tree.pointers)
console.log(tree.values)
npm install segment-tree
var SegmentTree = require("segment-tree")
SegmentTree(length, pointers, values)SegmentTree constructor
length is the size of the segment treepointers is a sorted list of pointersvalues is a sorted list of valuesThe segment tree object has the same properties as the arguments.
SegmentTree.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.proto.slice(begin[, end])Returns a slice of the segment tree. Same semantics as Array.slice
begin is the start of the intervalend is the end of the intervalReturns A 1-level deep slice of the segment tree
SegmentTree.proto.toArray([array])Unpacks the segment tree into an array
array gets the output. If not specified a new array is allocatedReturns array
SegmentTree.zeros(size)Create an empty segment tree
size is the size of the new segment treeReturns A new segment tree
SegmentTree.fromArray(array)Encodes an array into a segment tree
array is the array to encodeReturns A new segment tree encoding array
SegmentTree.fromGenericArray(array)Encodes an array into a segment tree, except instead of using [] to access the array it uses .get()
array is the array to encodeReturns A new segment tree encoding array
(c) 2013 Mikola Lysenko. MIT License
FAQs
Segment tree data structure
The npm package segment-tree receives a total of 14 weekly downloads. As such, segment-tree popularity was classified as not popular.
We found that segment-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.