This repository is still in development. Intervals can be inserted and queried, but there is still work to be done to remove nodes.
Changes to be made:
- Fix deletion
- Height should be 0 if no children, thinking depth
- Pass test(ish) cases from https://www.hackerrank.com/challenges/self-balancing-tree/forum
Similar to davidisaaclee/interval-tree, I wanted an type-safe interval tree with immutable functional interface.
The primary motivations for this project was to be:
- Immutable (to store in Redux)
- Use Typescript
- Dependency free
# proposed# npm install immutable-interval-tree- Add / remove a number of intervals
constintervalsToAdd: IIntervalNode[]=[]constintervalsToRemove: string[]=[]lettree: IIntervalTree=IntervalTree.empty()// insert intervalstree=intervalsToAdd.reduce((tr,int)=>IntervalTree.insert_node(tr,int),tree)// remove intervalstree=intervalsToRemove.reduce((tr,identifier)=>IntervalTree.remove(tr,identifier),tree)The primary types you must consider are:
exportinterfaceIInterval{low: number;high: number;}/* Note that the IIntervalNode doesn't store children, this is stored on the IIntervalTree*/interfaceIIntervalNodeextendsIInterval{identifier: string;data?: any;}exportinterfaceIIntervalTree{index: {[identifier: string]: IIntervalNode};root: string|null;children: {[identifier: string]: IPotentialChildren};}- Based on the Geeks for Geek guide.
- The repository was setup using: Step by step: Building and publishing an NPM Typescript package.