Permalink
Browse files

minor tweaks, README correction

  • Loading branch information...
1 parent d65a050 commit e614d01ff715d0c594ff22e844f53041e1e9d478 @defunkt committed Apr 26, 2008
Showing with 8 additions and 11 deletions.
  1. +4 −3 README
  2. +3 −6 mapreduce_enumerable.rb
  3. +1 −2 mapreduce_runner.rb
View
7 README
@@ -2,14 +2,15 @@ By Blaine Cook.
http://romeda.org/blog/2007/04/mapreduce-in-36-lines-of-ruby.html
-If you want to add `dinject` (reduce) please do.
+If you want to add `dinject` (reduce) please do:
+http://github.com/defunkt/mapreducerb
In your shell:
$ sudo gem install RingyDingy
$ sudo gem install ruby2ruby
$ ring_server &
-$ ruby mapreduce_runner &
-$ ruby mapreduce_runner &
+$ ruby mapreduce_runner.rb &
+$ ruby mapreduce_runner.rb &
In IRB:
>> require 'mapreduce_enumerable'
View
@@ -4,12 +4,12 @@
module Enumerable
def dmap(&block)
- self.each_with_index do |element,idx|
+ each_with_index do |element,idx|
ring_server.write([:dmap, Process.pid, block.to_ruby, element, idx])
end
results = []
- while results.size < self.size
+ while results.size < size
result, idx = ring_server.take([:dmap, Process.pid, nil, nil]).last(2)
results[idx] = result
end
@@ -18,9 +18,6 @@ def dmap(&block)
end
def ring_server
- return @ring_server if @ring_server
-
- ringy_dingy = RingyDingy.new nil
- @ring_server = ringy_dingy.ring_server
+ @ring_server ||= RingyDingy.new(nil).ring_server
end
end
View
@@ -2,8 +2,7 @@
require 'ruby2ruby'
require 'ringy_dingy'
-ringy_dingy = RingyDingy.new nil
-ring_server = ringy_dingy.ring_server
+ring_server = RingyDingy.new(nil).ring_server
loop do
pid, block, element, idx = ring_server.take([:dmap, nil, nil, nil, nil]).last(4)

0 comments on commit e614d01

Please sign in to comment.