Skip to content

Repository files navigation

Immutable Interval Tree (Pre-alpha)

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:

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

Install

# proposed# npm install immutable-interval-tree

Common usage patterns

  • 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)

Types

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};}

Other notes

About

Immutable Interval Tree for Javascript / Typescript

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages