All Projects → mbuchetics → RangeTree

mbuchetics / RangeTree

Licence: other
A generic interval tree implementation in C#

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to RangeTree

rust-lapper
Rust implementation of a fast, easy, interval tree library nim-lapper
Stars: ✭ 39 (-72.92%)
Mutual labels:  tree, interval-tree
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+122.92%)
Mutual labels:  tree, generic
interval-tree
A C++ header only interval tree implementation.
Stars: ✭ 38 (-73.61%)
Mutual labels:  interval-tree
dart sealed
Dart and Flutter sealed class generator and annotations, with match methods and other utilities. There is also super_enum compatible API.
Stars: ✭ 16 (-88.89%)
Mutual labels:  generic
kirby3-bolt
Kirby 3 Plugin for a fast Page lookup even in big content trees
Stars: ✭ 24 (-83.33%)
Mutual labels:  tree
performant-array-to-tree
Converts an array of items with ids and parent ids to a nested tree in a performant O(n) way. Runs in browsers and Node.js.
Stars: ✭ 193 (+34.03%)
Mutual labels:  tree
jh-weapp-demo
微信小程序项目- 实现一些常用效果、封装通用组件和工具类
Stars: ✭ 60 (-58.33%)
Mutual labels:  tree
comment tree
Render comment tree like facebook comment - reply
Stars: ✭ 37 (-74.31%)
Mutual labels:  tree
91-days-algorithm
91天学算法-Leetcode图解题解集合(JavaScript/C++/Python) Solutions and Explainations with Hand Drawings in Chinese(JavaScript/C++/Python)
Stars: ✭ 206 (+43.06%)
Mutual labels:  tree
5itv
familytree家谱宗谱族谱 刘三才族裔刘氏族谱网源码
Stars: ✭ 23 (-84.03%)
Mutual labels:  tree
ngx-tree
A derived version of angular-tree-component without mobx, better performance.
Stars: ✭ 13 (-90.97%)
Mutual labels:  tree
Soft-Decision-Tree
PyTorch Implementation of "Distilling a Neural Network Into a Soft Decision Tree." Nicholas Frosst, Geoffrey Hinton., 2017.
Stars: ✭ 67 (-53.47%)
Mutual labels:  tree
react-tree
Hierarchical tree component for React in Typescript
Stars: ✭ 174 (+20.83%)
Mutual labels:  tree
filterCSV
Tools to manipulate CSV files in a format suitable for importing into various mindmapping programs - such as iThoughts, Freemind, and MindNode.
Stars: ✭ 29 (-79.86%)
Mutual labels:  tree
EntitasGenericAddon
Addon to Entitas that allows using generic methods instead of code generator and uses type inference to insure compile time correctness
Stars: ✭ 17 (-88.19%)
Mutual labels:  generic
Processor
Ontology-driven Linked Data processor and server for SPARQL backends. Apache License.
Stars: ✭ 54 (-62.5%)
Mutual labels:  generic
react-org-tree
😃 a simple organization tree component based on react
Stars: ✭ 72 (-50%)
Mutual labels:  tree
js-symbol-tree
Turn any collection of objects into its own efficient tree or linked list using Symbol
Stars: ✭ 86 (-40.28%)
Mutual labels:  tree
pyrubrum
An intuitive framework for creating Telegram bots.
Stars: ✭ 33 (-77.08%)
Mutual labels:  tree
bactmap
A mapping-based pipeline for creating a phylogeny from bacterial whole genome sequences
Stars: ✭ 36 (-75%)
Mutual labels:  tree

IntervalTree

Build status NuGet version

A generic interval tree

A generic implementation of a centered interval tree in C#.

From Wikipedia:

In computer science, an interval tree is an ordered tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval or point. It is often used for windowing queries, for instance, to find all roads on a computerized map inside a rectangular viewport, or to find all visible elements inside a three-dimensional scene.

Based on the Java implementation found here: http://www.sanfoundry.com/java-program-implement-interval-tree/

Queries require O(log n + m) time, with n being the total number of intervals and m being the number of reported results. Construction requires O(n log n) time, and storage requires O(n) space.

Requirements

  • Consuming this NuGet package requires .NET Framework >= 4.5 or .NET Standard >= 1.2
  • Developing this project requires Visual Studio 2017 with .NET Framework >= 4.5 and .NET Standard >= 2.0.

Simple Interface

public interface IIntervalTree<TKey, TValue> 
    : IEnumerable<RangeValuePair<TKey, TValue>>
{
    IEnumerable<TValue> Values { get; }
    int Count { get; }

    IEnumerable<TValue> Query(TKey value);
    IEnumerable<TValue> Query(TKey from, TKey to);

    void Add(TKey from, TKey to, TValue value);
    void Remove(TValue item);
    void Remove(IEnumerable<TValue> items);
    void Clear();
}

Usage

var tree = new IntervalTree<int, string>()
{
    { 0, 10, "1" },
    { 20, 30, "2" },
    { 15, 17, "3" },
    { 25, 35, "4" },
};

// Alternatively, use the Add method, for example:
// tree.Add(0, 10, "1");

var results1 = tree.Query(5);     // 1 item: [0 - 10]
var results2 = tree.Query(10);    // 1 item: [0 - 10]
var results3 = tree.Query(29);    // 2 items: [20 - 30], [25 - 35]
var results4 = tree.Query(5, 15); // 2 items: [0 - 10], [15 - 17]

The solution file contains more examples and tests, that show how to use IntervalTree with other data types.

Implementation Details

In this implementation, whenever you add or remove items from the tree, the tree goes "out of sync" internally, which means that the items are stored, but the tree-index is not updated yet. Upon the next query, the tree structure is automatically rebuild. Subsequent queries will use the cached index and be much faster. The creation of the tree-index requires O(n log n) time. Therefore, it is best suited for trees that do not change often or small trees, where the creation time is negligible.

RangeTree vs. IntervalTree

This project contains an IntervalTree (see Issue #24), but was incorrectly named RangeTree at the beginning. It was mostly renamed to IntervalTree in version 3.0.0. However, given that a large number of users are using this project, renaming the NuGet package and repository was not possible without breaking too much, so we settled with (just) renaming all occurences in the source code and documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].