No release in over 3 years
Low commit activity in last 3 years
A Ruby implementation of the Centered Interval Tree data structure. See also: http://en.wikipedia.org/wiki/Interval_tree
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.0.1
~> 3.10
 Project Readme

IntervalTree

Tests

An implementation of the centered interval tree algorithm in Ruby.

See also

Maintainers Wanted!

We are not currently using interval-tree at GreenSync; however, we recognize that it may still be useful to some. With our efforts currently focused elsewhere, we are seeking a new maintainer(s) to be the primary maintainer for the project. Please get in touch with @maddymarkovitz or @ZimbiX if you are interested.

ChangeLog

2020-11-09, contribution by Brendan Weibrecht, Chris Nankervis and Thomas van der Pol

  • Substantially improved performance when supplied with a large range as the search query.

2017-05-12, contribution by Sam Davies

  • User can specify an option in search unique: false if s/he wants multiple matches to be returned.

2015-11-02, contribution by Carlos Alonso

  • Improved centering
  • Fixed searching: With some use cases with very large trees, the library fails to find intervals.
  • Added rubygems structure to be able to be pushed as a gem

2013-04-06, contribution by Simeon Simeonov

  • Range factory: The current design allows for Range-compatible elements to be added except for the case where Tree#ensure_exclusive_end constructs a Range in a private method. In keeping with good design practices of containers such as Hash, this pull requests allows for a custom range factory to be provided to Tree#initialize while maintaining perfect backward compatibility. Search in empty trees failing
  • Adds a nil guard in Tree#search to protect against empty tree searches failing.
  • Cosmetic improvements: Language & whitespace in specs, Gemfile addition, and .gitignore update

Install

$ gem install fast_interval_tree

Usage

See spec/interval_tree_spec.rb for details.

require "interval_tree"

itv = [(0...3), (1...4), (3...5), (0...3)]
t = IntervalTree::Tree.new(itv)
p t.search(2)     #=> [0...3, 1...4]
p t.search(2, unique: false) #=> [0...3, 0...3, 1...4]
p t.search(1...4) #=> [0...3, 1...4, 3...5]

Note

Result intervals are always returned in the "left-closed and right-open" style that can be expressed by three-dotted Range object literals (first...last)

Two-dotted full-closed intervals (first..last) are also accepted and internally converted to half-closed intervals.

Copyright

Author: MISHIMA, Hiroyuki ( https://github.com/misshie ), Simeon Simeonov ( https://github.com/ssimeonov ), Carlos Alonso ( https://github.com/calonso ), Sam Davies ( https://github.com/samphilipd ), Brendan Weibrecht (https://github.com/ZimbiX), Chris Nankervis (https://github.com/chrisnankervis), Thomas van der Pol (https://github.com/tvanderpol).

Copyright: (c) 2011-2020 MISHIMA, Hiroyuki; Simeon Simeonov; Carlos Alonsol; Sam Davies; Brendan Weibrecht; Chris Nankervis; Thomas van der Pol

License: The MIT/X11 license