diff -Nru ruby-peach-0.4/.gitignore ruby-peach-0.5.1/.gitignore --- ruby-peach-0.4/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ ruby-peach-0.5.1/.gitignore 2012-11-28 23:02:19.000000000 +0000 @@ -0,0 +1 @@ +pkg diff -Nru ruby-peach-0.4/Gemfile ruby-peach-0.5.1/Gemfile --- ruby-peach-0.4/Gemfile 1970-01-01 00:00:00.000000000 +0000 +++ ruby-peach-0.5.1/Gemfile 2012-11-28 23:02:19.000000000 +0000 @@ -0,0 +1,3 @@ +source "http://rubygems.org" + +gemspec diff -Nru ruby-peach-0.4/Gemfile.lock ruby-peach-0.5.1/Gemfile.lock --- ruby-peach-0.4/Gemfile.lock 1970-01-01 00:00:00.000000000 +0000 +++ ruby-peach-0.5.1/Gemfile.lock 2012-11-28 23:02:19.000000000 +0000 @@ -0,0 +1,22 @@ +PATH + remote: . + specs: + peach (0.5.1) + +GEM + remote: http://rubygems.org/ + specs: + rake (0.9.2.2) + shoulda (3.0.1) + shoulda-context (~> 1.0.0) + shoulda-matchers (~> 1.0.0) + shoulda-context (1.0.0) + shoulda-matchers (1.0.0) + +PLATFORMS + ruby + +DEPENDENCIES + peach! + rake + shoulda diff -Nru ruby-peach-0.4/Rakefile ruby-peach-0.5.1/Rakefile --- ruby-peach-0.4/Rakefile 2011-07-28 07:44:15.000000000 +0000 +++ ruby-peach-0.5.1/Rakefile 2012-11-28 23:02:19.000000000 +0000 @@ -1,3 +1,6 @@ +require 'bundler' +Bundler::GemHelper.install_tasks + require 'rake' require 'rake/testtask' diff -Nru ruby-peach-0.4/debian/changelog ruby-peach-0.5.1/debian/changelog --- ruby-peach-0.4/debian/changelog 2012-06-29 21:55:27.000000000 +0000 +++ ruby-peach-0.5.1/debian/changelog 2013-05-07 13:48:59.000000000 +0000 @@ -1,3 +1,16 @@ +ruby-peach (0.5.1-1) unstable; urgency=low + + * New upstream release + * debian/control: + + add myself to Uploaders + + bump Standards-Version to 3.9.4 (no changes needed) + + use canonical URLs in Vcs-* fields + * debian/ruby-tests + + do not modify the LOAD_PATH before running the tests + + restrict to the test/ directory + + -- Cédric Boutillier Tue, 07 May 2013 15:32:28 +0200 + ruby-peach (0.4-2) unstable; urgency=low * Team upload. diff -Nru ruby-peach-0.4/debian/control ruby-peach-0.5.1/debian/control --- ruby-peach-0.4/debian/control 2012-06-29 21:55:27.000000000 +0000 +++ ruby-peach-0.5.1/debian/control 2013-05-07 13:31:21.000000000 +0000 @@ -2,12 +2,11 @@ Section: ruby Priority: optional Maintainer: Debian Ruby Extras Maintainers -Uploaders: Lucas Nussbaum -DM-Upload-Allowed: yes +Uploaders: Lucas Nussbaum , Cédric Boutillier Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.3.0~), ruby-shoulda -Standards-Version: 3.9.3 -Vcs-Git: git://git.debian.org/pkg-ruby-extras/ruby-peach.git -Vcs-Browser: http://git.debian.org/?p=pkg-ruby-extras/ruby-peach.git;a=summary +Standards-Version: 3.9.4 +Vcs-Git: git://anonscm.debian.org/pkg-ruby-extras/ruby-peach.git +Vcs-Browser: http://anonscm.debian.org/gitweb?p=pkg-ruby-extras/ruby-peach.git;a=summary Homepage: http://peach.rubyforge.org XS-Ruby-Versions: all diff -Nru ruby-peach-0.4/debian/ruby-tests.rb ruby-peach-0.5.1/debian/ruby-tests.rb --- ruby-peach-0.4/debian/ruby-tests.rb 2012-05-17 22:28:14.000000000 +0000 +++ ruby-peach-0.5.1/debian/ruby-tests.rb 2013-05-07 13:32:15.000000000 +0000 @@ -1,2 +1 @@ -$: << 'lib' << '.' -Dir['{spec,test}/**/*.rb'].each { |f| require f } +Dir['test/**/*.rb'].each { |f| require f } diff -Nru ruby-peach-0.4/lib/peach/version.rb ruby-peach-0.5.1/lib/peach/version.rb --- ruby-peach-0.4/lib/peach/version.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-peach-0.5.1/lib/peach/version.rb 2012-11-28 23:02:19.000000000 +0000 @@ -0,0 +1,3 @@ +module Peach + VERSION = "0.5.1" +end diff -Nru ruby-peach-0.4/lib/peach.rb ruby-peach-0.5.1/lib/peach.rb --- ruby-peach-0.4/lib/peach.rb 2011-07-28 07:44:15.000000000 +0000 +++ ruby-peach-0.5.1/lib/peach.rb 2012-11-28 23:02:19.000000000 +0000 @@ -1,70 +1,54 @@ -module Peach - def peach(pool = nil, &b) - pool ||= $peach_default_threads || size - raise "Thread pool size less than one?" unless pool >= 1 - div = (size/pool).to_i # should already be integer - div = 1 unless div >= 1 # each thread better do something! - - threads = (0...size).step(div).map do |chunk| - Thread.new(chunk, [chunk+div,size].min) do |lower, upper| - (lower...upper).each{|j| yield(slice(j))} +# monkey patch Enumerable by reopening it. Enumerable.send(:include, Peach) +# doesn't seem to work as it should. +module Enumerable + def _peach_run(pool = nil, &b) + pool ||= $peach_default_threads || count + pool = 1 unless pool >= 1 + div = (count/pool).to_i # should already be integer + div = 1 unless div >= 1 # each thread better do something! + + threads = [] + each_slice(div).with_index do |slice, idx| + threads << Thread.new(slice) do |thread_slice| + yield thread_slice, idx, div end end - threads.each { |t| t.join } + threads.each{|t| t.join } self end + def peach(pool = nil, &b) + _peach_run(pool) do |thread_slice, idx, div| + thread_slice.each{|elt| yield elt} + end + end + def pmap(pool = nil, &b) - pool ||= $peach_default_threads || size - raise "Thread pool size less than one?" unless pool >= 1 - div = (size/pool).to_i # should already be integer - div = 1 unless div >= 1 # each thread better do something! - - result = Array.new(size) - - threads = (0...size).step(div).map do |chunk| - Thread.new(chunk, [chunk+div,size].min) do |lower, upper| - (lower...upper).each{|j| result[j] = yield(slice(j))} + result = Array.new(count) + lock = Mutex.new + + _peach_run(pool) do |thread_slice, idx, div| + thread_slice.each_with_index do |elt, offset| + local_result = yield elt + lock.synchronize do + result[(idx*div)+offset] = local_result + end end end - threads.each { |t| t.join } result end - def pselect(n = nil, &b) - peach_run(:select, b, n) - end - - - - protected - def peach_run(meth, b, n = nil) - threads, results, result = [],[],[] - peach_divvy(n).each_with_index do |x,i| - threads << Thread.new { results[i] = x.send(meth, &b)} + def pselect(pool = nil, &b) + results, result = [],[] + lock = Mutex.new + + _peach_run(pool) do |thread_slice, idx, div| + local_result = thread_slice.select(&b) + lock.synchronize do + results[idx] = local_result + end end - threads.each {|t| t.join } results.each {|x| result += x if x} result end - - def peach_divvy(n = nil) - return [] if size == 0 - - n ||= $peach_default_threads || size - n = size if n > size - - lists = [] - - div = (size/n).floor - offset = 0 - for i in (0...n-1) - lists << slice(offset, div) - offset += div - end - lists << slice(offset...size) - lists - end end - -Array.send(:include, Peach) diff -Nru ruby-peach-0.4/metadata.yml ruby-peach-0.5.1/metadata.yml --- ruby-peach-0.4/metadata.yml 2011-07-28 07:44:15.000000000 +0000 +++ ruby-peach-0.5.1/metadata.yml 2012-11-28 23:02:19.000000000 +0000 @@ -1,70 +1,99 @@ ---- !ruby/object:Gem::Specification +--- !ruby/object:Gem::Specification name: peach -version: !ruby/object:Gem::Version - prerelease: false - segments: - - 0 - - 4 - version: "0.4" +version: !ruby/object:Gem::Version + version: 0.5.1 + prerelease: platform: ruby -authors: - - Ben Hughes +authors: +- Ben Hughes autorequire: bindir: bin cert_chain: [] - -date: 2010-11-17 00:00:00 -05:00 -default_executable: -dependencies: [] - +date: 2012-07-03 00:00:00.000000000 Z +dependencies: +- !ruby/object:Gem::Dependency + name: rake + requirement: !ruby/object:Gem::Requirement + none: false + requirements: + - - ! '>=' + - !ruby/object:Gem::Version + version: '0' + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + none: false + requirements: + - - ! '>=' + - !ruby/object:Gem::Version + version: '0' +- !ruby/object:Gem::Dependency + name: shoulda + requirement: !ruby/object:Gem::Requirement + none: false + requirements: + - - ! '>=' + - !ruby/object:Gem::Version + version: '0' + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + none: false + requirements: + - - ! '>=' + - !ruby/object:Gem::Version + version: '0' description: email: ben@pixelmachine.org executables: [] - extensions: [] - extra_rdoc_files: [] - -files: - - README - - LICENSE - - Rakefile - - lib/peach.rb - - bn/peach_bn.rb - - bn/peach_test.rb - - test/test_helper.rb - - test/peach_test.rb - - web/index.html - - web/Peach.sketch.png -has_rdoc: true +files: +- .gitignore +- Gemfile +- Gemfile.lock +- LICENSE +- README +- Rakefile +- bn/peach_bn.rb +- bn/peach_test.rb +- lib/peach.rb +- lib/peach/version.rb +- peach.gemspec +- test/peach_test.rb +- test/test_helper.rb +- web/Peach.sketch.png +- web/index.html homepage: http://peach.rubyforge.org licenses: [] - post_install_message: rdoc_options: [] - -require_paths: - - lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - segments: - - 0 - version: "0" -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - segments: - - 0 - version: "0" +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ! '>=' + - !ruby/object:Gem::Version + version: '0' + segments: + - 0 + hash: 2784794470947016613 +required_rubygems_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ! '>=' + - !ruby/object:Gem::Version + version: '0' + segments: + - 0 + hash: 2784794470947016613 requirements: [] - rubyforge_project: -rubygems_version: 1.3.6 +rubygems_version: 1.8.24 signing_key: specification_version: 3 summary: Parallel Each and other parallel things -test_files: [] - +test_files: +- test/peach_test.rb +- test/test_helper.rb diff -Nru ruby-peach-0.4/peach.gemspec ruby-peach-0.5.1/peach.gemspec --- ruby-peach-0.4/peach.gemspec 1970-01-01 00:00:00.000000000 +0000 +++ ruby-peach-0.5.1/peach.gemspec 2012-11-28 23:02:19.000000000 +0000 @@ -0,0 +1,20 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "peach/version" + +Gem::Specification.new do |s| + s.name = 'peach' + s.version = Peach::VERSION + s.authors = ['Ben Hughes'] + s.email = 'ben@pixelmachine.org' + s.summary = 'Parallel Each and other parallel things' + s.homepage = 'http://peach.rubyforge.org' + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + s.add_development_dependency('rake') + s.add_development_dependency('shoulda') +end diff -Nru ruby-peach-0.4/test/peach_test.rb ruby-peach-0.5.1/test/peach_test.rb --- ruby-peach-0.4/test/peach_test.rb 2011-07-28 07:44:15.000000000 +0000 +++ ruby-peach-0.5.1/test/peach_test.rb 2012-11-28 23:02:19.000000000 +0000 @@ -10,12 +10,17 @@ normal_f = f.to_s[1..-1].to_sym setup do - @data = [1, 2, 3, 5, 8] + @data = [1, 2, 3, 5, 8]*1001 @block = lambda{|i| i**2} end should "return the same result as #{normal_f}" do assert_equal @data.send(normal_f, &@block), - @data.send(f, nil, &@block) + @data.send(f, 100, &@block) + end + + should "return the same result as #{normal_f} for empty list" do + assert_equal [].send(normal_f, &@block), + [].send(f, nil, &@block) end end end @@ -38,39 +43,4 @@ end end - context "divvy" do - setup do - @data = [1, 2, 3, 4, 5] - end - - context "on empty list" do - should "return empty list" do - assert_equal [], [].send(:peach_divvy) - end - end - - context "when n is nil" do - should "put 1 element into each division" do - assert_equal @data.size, @data.send(:peach_divvy).size - end - end - - context "when n is less than array size" do - should "put create n divisions" do - assert_equal 2, @data.send(:peach_divvy, 2).size - end - - should "not lose any array elements" do - assert_equal @data.size, @data.send(:peach_divvy, 2).inject(0) {|sum, i| - sum + i.size - } - end - end - - context "when n is greater than array size" do - should "only create 'array size' divisions" do - assert_equal @data.size, @data.send(:peach_divvy, 42).size - end - end - end end