Releases: hexsprite/intervaltree
Releases · hexsprite/intervaltree
v1.4.0 — semantic hash + equals()
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()digestedJSON.stringify(this)— which, without atoJSON(), 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. WithtoJSON()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.xInstall: npm i intervaltree@1.4.0