Release v2.0.0
Release Notes: 2.0.0
Date: 2025-10-14
This document summarizes the changes included in the v2.0.0 release. It highlights breaking changes, new features, improvements, documentation updates, and migration guidance.
TL;DR
- Breaking: Keys with identical intervals are now bucketed into one node; value equality is by identity (or custom
equal_to). - Refactor: New
IntervalBaseabstraction; comparisons moved to instance methods; augmentation usesmerge()(no static helpers). - Features: Additional interval types (
Interval2D), iterator enhancements, better typings, BigInt support path. - DX/Docs: TypeScript-first build, TypeDoc docs with a custom theme and live RunKit examples.
Feedback and testing
Please try the alpha build and share your feedback in GitHub Discussions:
https://github.com/alexbol99/flatten-interval-tree/discussions
Breaking Changes
-
Bucketed values per key (commit: cef6055)
- Identical interval keys now share a single tree node that contains a bucket (array) of values.
exist(key)checks the presence of a node by key.exist(key, value)checks if the specific value exists in the bucket by strict equality (===) unless the value implementsequal_to(other).remove(key)removes the entire node (all values in the bucket).remove(key, value)removes only that value; if the bucket becomes empty the node is removed.- Impact: If your code depends on having separate nodes for equal keys or on value comparator semantics, adjust accordingly.
-
Interval comparison and augmentation semantics
- Removed static comparison helpers from the interval classes. Comparison is now delegated to instance-level methods on
IntervalBaseand its subclasses. - The augmented
maxfield in nodes is computed using instancemerge()rather than static helpers. - Impact: Custom interval types should extend
IntervalBaseand may overrideless_than,equal_to,not_intersect,merge, andcomparable_less_thanif needed.
- Removed static comparison helpers from the interval classes. Comparison is now delegated to instance-level methods on
New Features
-
Multiple interval types (commits: 246bb11, docs updates)
Interval(default 1D comparable endpoints: number, bigint, string, Date)Interval2D(lexicographic 2D intervals with endpoints as[x, y])- The tree accepts either an
IntervalBaseinstance or a numeric tuple[low, high]which is normalized and converted toInterval.
-
Iterator enhancements
iterate()with no arguments yields all values in ascending key order.iterate(interval)finds the lowest intersecting or forward key and iterates forward.- Optional mapper
(value, key) => outputfor bothsearchanditerate.
-
BigInt compatibility
- Default
Intervalsupports BigInt endpoints; tests demonstrate mixed usage with numbers when explicitly typed/cast.
- Default
Refactors & Internal Changes
-
Introduced
IntervalBaseand moved comparisons to instances (commit: 246bb11)Interval2Doverrides comparison and intersection logic.Nodeand tree logic rely on interval instance methods for ordering and intersection, and onmerge()for augmentedmax.
-
TypeScript-first codebase (commits: 34ebb63, ffa85bd)
- Source migrated to TypeScript.
- Build via Rollup; declaration maps emitted.
- Tests migrated from JS to TS (commit: 4c71e30).
-
Typing improvements
- Stronger generics across
IntervalTree<V>. - Overloads for
searchanditerateto infer mapper output types. - Public types
ComparableandIntervalInputexported. - Declaration shims added for bundle entry points (
dist/main*.d.ts) so editors get accurate types when importing fromdist/main.mjsduring development.
- Stronger generics across
API Behavior Clarifications
- Insert
insert(key, value?)storesvalue; if omitted, stores the key itself as the value (sosearch()returns keys by default).- Inserting an already existing key appends
valueto its bucket.
- Exist
exist(key)checks key presence;exist(key, value)checks if that value is in the bucket.
- Remove
remove(key)removes the entire bucket/node.remove(key, value)removes only the matching value; node is removed if bucket becomes empty.
- Search
search(interval, mapper?)returns matching values, or mapped outputs if a mapper is provided.
- Iterate
iterate(interval?, mapper?)yields values or mapped outputs in ascending key order.
Documentation & DX
- TypeDoc-based API docs with custom styling (commit: 7784fa2)
- Hosted output under
docs/with improved typography and auto dark mode viatypedoc.theme.css. - Top navigation includes links to GitHub and live examples.
- Hosted output under
- Live examples (RunKit) (commit: 7784fa2)
docs/examples.htmlcontains two live notebooks: numeric intervals andInterval2D.
- README updates
- Reorganized and expanded sections: Interval types, usage examples, docs links.
Performance
- The red-black tree properties and augmented max maintenance remain intact. Additional tests verify invariants after insertions and deletions under the new bucketed-node model.
Migration Guide (from 1.1.4 to 2.0.0)
- Equal keys now share a node
- If you relied on distinct nodes for identical intervals, update logic to work with value buckets.
- Use
exist(key, value)andremove(key, value)to operate on individual values.
- Custom intervals
- If you had custom interval types, refactor them to extend
IntervalBaseand override instance methods instead of using/expecting static helpers.
- If you had custom interval types, refactor them to extend
- TypeScript consumers
- Prefer importing from the package root (
@flatten-js/interval-tree) to pick up the main types. - If importing bundle paths during development (e.g.
../dist/main.mjs), declaration shims are provided to preserve accurate type hints.
- Prefer importing from the package root (
- BigInt
Intervalsupports BigInt endpoints. When mixing types in tests or apps, ensure casting where necessary to satisfy TS.
Known Issues / Notes
- Date endpoints are supported by the default
Interval; no special class is required. - 2D intervals (
Interval2D) use lexicographic ordering; ensure that matches your spatial semantics before adopting for geometry tasks.
Acknowledgements
- Thanks to contributors and issue reporters for:
Commits of interest (master..2.0.0-alpha)
- 4c71e30 test: migrate Red-Black Tree Node tests to TypeScript; convert IntervalTree tests to TypeScript; update dist outputs and declaration shims; update package scripts
- 7784fa2 docs: switch to TypeDoc with custom theme; add live examples page; align TypeScript (5.7.x) with TypeDoc 0.27; add docs build script
- 246bb11 refactor(Interval): introduce IntervalBase and instance-level comparison; remove static helpers; use merge() for augmentation
- cef6055 feat: bucket values per key; update APIs and tests; BREAKING CHANGE: equal keys share one node
- 34ebb63 chore: finalize TypeScript migration, build config, and CI
- ffa85bd TypeScript support
- cf3776b ci: run workflow on 2.0.0-alpha branch and enable manual dispatch
- e2e391f fix: unable to remove some key/value objects (#54)