Skip to content

Releases: hexsprite/intervaltree

v1.4.0 — semantic hash + equals()

17 Apr 03:10

Choose a tag to compare

What's new

  • equals(other) — semantic tree equality over sorted intervals + data. Short-circuits on size mismatch, then element-wise; faster than comparing hashes when inequality is likely.
  • toJSON() — canonical [start, end, data][] serialization. JSON.stringify(tree) now returns sorted intervals instead of the raw object graph.
  • hash() is now semantic. Previously, hash() digested JSON.stringify(this) — which, without a toJSON(), serialized the raw {root, _size, _dirty} object graph. Two trees with byte-identical sorted intervals but built via different op sequences produced different hashes, surfacing as false-positive "drift" in cross-tree equality checks. With toJSON() in place, hash() hashes the canonical form — same intervals ⇒ same hash.

Compatibility

No API removals. The signature of hash() is unchanged; its return values on semantically-equal trees are now stable where they weren't before. If you were (unusually) relying on JSON.stringify(tree) returning the raw object graph, that's the one subtle behavioral change.

Story

Found via a fast-check property test in a downstream scheduler, which shrunk to a single 15-min action as the minimal repro. The intervals were always identical; only the tree topology differed. Classic case of "hashing what you have, not what you mean."

const a = IntervalTree.fromTuples([[0, 10], [20, 30]])
const b = new IntervalTree()
b.addInterval(20, 30); b.addInterval(0, 10)

a.equals(b)            // true
a.hash() === b.hash()  // true — was false in 1.3.x

Install: npm i intervaltree@1.4.0

v1.2.0

20 Mar 18:43
dac7103

Choose a tag to compare

1.2.0 (2026-03-20)

Features

  • add chopAll() for batch interval removal (407a015)

v1.1.0

06 Dec 20:43
9c8d99f

Choose a tag to compare

1.1.0 (2025-12-06)

Features

  • add toSorted polyfill for Node 14 compatibility (284956d)
  • major DX improvements - generics, iterators, boolean checks, and set operations (#4) (f6cde8d)

Bug Fixes

  • use consistent undefined check in toString() (2df7fba)