DisjointSet
Disjoint-set data structure library.
Installation
Add this line to your application's Gemfile:
gem 'disjoint_set'
And then execute:
$ bundle
Or install it yourself as:
$ gem install disjoint_set
Usage
initialize:
d = DisjointSet::DisjointSet.new [1, 2, 3, 4]
make_set:
d.make_set 5
union:
d.union 1, 2
d.union 3, 4
d.union 1, 3
find:
d.find 1
=> 1
d.find 2
=> 1
d.find 4
=> 1
same?:
d.same? 1, 2
=> true
d.same? 1, 5
=> false
Contributing
- Fork it ( https://github.com/[my-github-username]/disjoint_set/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request