pmap 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in pmap.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rake'
8
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- pmap
1
+ pmap [![Build Status](https://secure.travis-ci.org/bruceadams/pmap.png)](http://travis-ci.org/bruceadams/pmap) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/bruceadams/pmap)
2
2
  ====
3
3
 
4
4
  This Ruby gem adds two methods to any Enumerable (notably including
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ task :default => [:test]
5
+
6
+ task :test do
7
+ ruby "test/pmap_test.rb"
8
+ end
@@ -4,21 +4,30 @@ require 'thread' unless defined?(Mutex)
4
4
  $pmap_default_thread_count ||= 64
5
5
 
6
6
  module PMap
7
+ class DummyOutput
8
+ def []=(idx)
9
+ end
10
+ end
11
+
7
12
  def self.included(base)
8
13
  base.class_eval do
9
14
  # Parallel "map" for any Enumerable.
10
15
  # Requires a block of code to run for each Enumerable item.
11
16
  # [thread_count] is number of threads to create. Optional.
12
17
  def pmap(thread_count=nil, &proc)
13
- raise ArgumentError, "thread_count must be at least one." unless
14
- thread_count.nil? or (thread_count.respond_to?(:>=) and thread_count >= 1)
15
- # This seems overly fussy... (code smell)
16
18
  in_array = self.to_a # I'm not sure how expensive this is...
19
+ out_array = Array.new(in_array.size)
20
+ process_core(thread_count, in_array, out_array, &proc)
21
+ out_array
22
+ end
23
+
24
+ def process_core(thread_count, in_array, out_array, &proc)
25
+ thread_count = thread_count(thread_count, in_array)
17
26
  size = in_array.size
18
- thread_count = [thread_count||$pmap_default_thread_count, size].min
19
- out_array = Array.new(size)
27
+
20
28
  semaphore = Mutex.new
21
29
  index = -1 # Our use of index is protected by semaphore
30
+
22
31
  threads = (0...thread_count).map {
23
32
  Thread.new {
24
33
  i = nil
@@ -28,17 +37,22 @@ module PMap
28
37
  }
29
38
  }
30
39
  threads.each {|t| t.join}
31
- out_array
32
40
  end
41
+ private :process_core
42
+
43
+ def thread_count(user_requested_count, items)
44
+ user_requested_count ||= $pmap_default_thread_count
45
+ raise ArgumentError, "thread_count must be at least one." unless
46
+ user_requested_count.respond_to?(:>=) && user_requested_count >= 1
47
+ [user_requested_count, items.size].min
48
+ end
49
+ private :thread_count
33
50
 
34
51
  # Parallel "each" for any Enumerable.
35
52
  # Requires a block of code to run for each Enumerable item.
36
53
  # [thread_count] is number of threads to create. Optional.
37
54
  def peach(thread_count=nil, &proc)
38
- # This is doing some extra work: building a return array that is
39
- # thrown away. How can I share the core code of "pmap" here and omit
40
- # the output array creation?
41
- pmap(thread_count, &proc)
55
+ process_core(thread_count, self.to_a, DummyOutput.new, &proc)
42
56
  self
43
57
  end
44
58
  end
@@ -1,3 +1,3 @@
1
1
  module Pmap
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = 'pmap'
7
7
  s.version = Pmap::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ['Bruce Adams']
10
- s.email = ['bruce.adams@acm.org']
9
+ s.authors = ['Bruce Adams', 'Jake Goulding']
10
+ s.email = ['bruce.adams@acm.org', 'jake.goulding@gmail.com']
11
11
  s.homepage = 'https://github.com/bruceadams/pmap'
12
12
  s.summary = %q{Add parallel methods into Enumerable: pmap and peach}
13
13
  s.description = %q{Add parallel methods into Enumerable: pmap and peach}
metadata CHANGED
@@ -1,30 +1,27 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pmap
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
4
5
  prerelease:
5
- version: 0.1.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bruce Adams
9
+ - Jake Goulding
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2011-05-09 00:00:00 -04:00
14
- default_executable:
13
+ date: 2013-01-29 00:00:00.000000000 Z
15
14
  dependencies: []
16
-
17
- description: "Add parallel methods into Enumerable: pmap and peach"
18
- email:
15
+ description: ! 'Add parallel methods into Enumerable: pmap and peach'
16
+ email:
19
17
  - bruce.adams@acm.org
18
+ - jake.goulding@gmail.com
20
19
  executables: []
21
-
22
20
  extensions: []
23
-
24
21
  extra_rdoc_files: []
25
-
26
- files:
22
+ files:
27
23
  - .gitignore
24
+ - .travis.yml
28
25
  - Gemfile
29
26
  - LICENSE
30
27
  - README.md
@@ -33,33 +30,34 @@ files:
33
30
  - lib/pmap/version.rb
34
31
  - pmap.gemspec
35
32
  - test/pmap_test.rb
36
- has_rdoc: true
37
33
  homepage: https://github.com/bruceadams/pmap
38
34
  licenses: []
39
-
40
35
  post_install_message:
41
36
  rdoc_options: []
42
-
43
- require_paths:
37
+ require_paths:
44
38
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
39
+ required_ruby_version: !ruby/object:Gem::Requirement
46
40
  none: false
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: "0"
51
- required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ segments:
46
+ - 0
47
+ hash: 2137837020685364568
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
49
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
55
+ - 0
56
+ hash: 2137837020685364568
57
57
  requirements: []
58
-
59
58
  rubyforge_project:
60
- rubygems_version: 1.6.2
59
+ rubygems_version: 1.8.24
61
60
  signing_key:
62
61
  specification_version: 3
63
- summary: "Add parallel methods into Enumerable: pmap and peach"
62
+ summary: ! 'Add parallel methods into Enumerable: pmap and peach'
64
63
  test_files: []
65
-