Skip to content
A Ruby implementation of augmented interval tree
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Version 0.1.1: A pull-request by samphilipd to allow for duplicate ra… May 12, 2017
spec Version 0.1.1: A pull-request by samphilipd to allow for duplicate ra… May 12, 2017
.document Initial commit to interval_tree. May 24, 2011
.gitignore prepared gemspec for RubyGems upload Nov 5, 2015
.rspec
.travis.yml
Gemfile prepared to be deployed to rubygems Sep 18, 2015
Gemfile.lock
LICENSE Version 0.1.1: A pull-request by samphilipd to allow for duplicate ra… May 12, 2017
README.md
Rakefile
augmented_interval_tree.gemspec

README.md

IntervalTree vesion 0.1.1

An implementation of the augmented interval tree algorithm in Ruby

See also

ChanegLog

2017-05-12, contribution by Sam Davies ( https://github.com/samphilipd )

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

2015-11-02, contribution by Carlos Alonso ( https://github.com/calonso )

  • 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 ( https://github.com/ssimeonov )

  • 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 augmented_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, 1...4, 0...3]
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 ).

Copyright: (c) 2011-2017 MISHIMA, Hiroyuki; Simeon Simeonov; Carlos Alonsol; Sam Davies

License: The MIT/X11 license

You can’t perform that action at this time.