README.md in ruby_collections-0.0.6 vs README.md in ruby_collections-0.0.7

- old
+ new

@@ -1,8 +1,8 @@ # RubyCollections -Welcome to ruby_collections gem. This gem will provide you with an easy access to common data structures to be used in ruby language. +Welcome to ruby_collections gem. This gem will provide you with an easy access to common data structures to be used in Ruby Language. ## Installation Add this line to your application's Gemfile: @@ -18,11 +18,11 @@ $ gem install ruby_collections ## Usage -Supported Data Structures: Max Heap, Min Heap, Stack, LinkedList, Deque +Supported Data Structures: Max Heap, Min Heap, Stack, LinkedList, Deque, UnionFind ### RubyCollections::MaxHeap ```ruby @@ -151,9 +151,33 @@ list.remove_first # list: [10, 2, 6] # remove last element list.remove_last # list: [10, 2] + +``` + +### RubyCollections::UnionFind + +```ruby + +# initialization takes an array argument. each element should have a to_s method defined which should return uniq val + +uf = RubyCollections::UnionFind.new (1..8).to_a + +uf.union(1,3) # joins 1 and 3 and returns the leader + +uf.union(5,6) # joins 5 and 6 and returns the leader + +uf.union(2,4) # joins 2 and 4 and returns the leader + +uf.union(1,7) # joins 1 and 7 and returns the leader + +uf.find(7) # leader of the cluster containing 7 + +uf.to_a # => [[1, 3, 7], [2, 4], [5, 6], [8]] i.e. returns array of all clusters + +uf.cluster(1) # => [1, 3, 7] i.e. returns all elements in same cluster as of 1 ``` ## Development