huge_enumerable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24da8d4e8288431fd7c8b9c59a59bf1dce237f17e7e6f14445e06dcfd3131207
4
- data.tar.gz: 8ab8fffbb899039ddacc3115908c18529eb9743a18a2db311670462f48ca7369
3
+ metadata.gz: a31b89b4c2cdd80273c579549e27b093fa1723f737dcb5dcf67c8609a930ebc9
4
+ data.tar.gz: 8de5ac7d85dd81a51349b763768e3d44dba188590c61802b6fb1d8182a5894c2
5
5
  SHA512:
6
- metadata.gz: 045a5d7a9789e496eac4e3ebaf30e7d3407acbfe4fe837ab25ae1e52d8471865ba579bebe01c0357c88bebc4b552a882d11b6c69d426b87b94ca7476f3a8d4af
7
- data.tar.gz: 9fda898074669e730b2f993a74e3dae21e349102d2af651ea99adfa49b41f51261a23845cdd0a3ca03a379fc451fa55429756c6e90010ec22f18d4e60bed9cf7
6
+ metadata.gz: 06d6d73e2c3c2218f0b820a64ee9ee8714cfbdff0350fefcb061b9f965692eab828ec38a1dc159d6b7c38027cb40475525e47491a4adad4dd1770a93919935e6
7
+ data.tar.gz: 4a1e0cbde30ab90bf71c9da8a1d3a180062205ec37e85c21bddbd594401d62ed68c15f4aecb570c60bd5ec385ff14ce0f1ad570adb4b810eb524228c665b4119
@@ -1,3 +1,3 @@
1
1
  class HugeEnumerable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -106,11 +106,13 @@ class HugeEnumerable
106
106
  # If no block is given, an HugeCombination is returned instead.
107
107
  # === Caveat
108
108
  # max_array_size is currently inherited by the generated HugeCombination. This may change in the future.
109
- def combination(n) # :yields: element
110
- random_number_generator = rng != self.method(:rand) ? rng : nil
111
- combo = HugeCombination.new(self.dup.reset!, n, max_array_size, random_number_generator)
112
- if block_given?
113
- combo.each { |x| yield x }
109
+ def combination(n, &block) # :yields: element
110
+ # Check to see if we have a specific random number generator to use.
111
+ # Using hash comparison as dups, clones, and other actions can make == and eql? return false when it is actually the same method
112
+ random_number_generator = rng.hash != method(:rand).hash ? rng : nil
113
+ combo = HugeCombination.new(self.clone.reset!, n, max_array_size, random_number_generator)
114
+ if block
115
+ combo.each(&block)
114
116
  self
115
117
  else
116
118
  combo
@@ -118,9 +120,15 @@ class HugeEnumerable
118
120
  end
119
121
 
120
122
  # Calls the given block once for each element in the next array of the collection, passing that element as a parameter.
121
- def each # :yields: element
123
+ def each(&block) # :yields: element
122
124
  # TODO: Return an Enumerator if no block is given
123
- remaining_or(max_array_size).times { |i| yield _fetch(i) }
125
+ remaining_or(max_array_size).times(&(block << method(:_fetch)))
126
+ # remaining_or(max_array_size).times { |i| yield _fetch(i) }
127
+ end
128
+
129
+ def initialize_copy(orig)
130
+ super
131
+ @rng = @rng.unbind.bind(self) if @rng.respond_to?(:unbind) # Make sure this is bound to self if it is a method
124
132
  end
125
133
 
126
134
  def max_array_size #:nodoc:
@@ -142,11 +150,13 @@ class HugeEnumerable
142
150
  # If no block is given, a HugePermutation is returned instead.
143
151
  # === Caveat
144
152
  # max_array_size is currently inherited by the generated HugePermutation. This may change in the future.
145
- def permutation(n) # :yields: element
146
- random_number_generator = rng != self.method(:rand) ? rng : nil
147
- perm = HugePermutation.new(self.dup.reset!, n, max_array_size, random_number_generator)
148
- if block_given?
149
- perm.each { |x| yield x }
153
+ def permutation(n, &block) # :yields: element
154
+ # Check to see if we have a specific random number generator to use.
155
+ # Using hash comparison as dups, clones, and other actions can make == and eql? return false when it is actually the same method
156
+ random_number_generator = rng.hash != method(:rand).hash ? rng : nil
157
+ perm = HugePermutation.new(self.clone.reset!, n, max_array_size, random_number_generator)
158
+ if block
159
+ perm.each(&block)
150
160
  self
151
161
  else
152
162
  perm
@@ -165,12 +175,14 @@ class HugeEnumerable
165
175
  # === Caveat
166
176
  # max_array_size is currently inherited by the generated HugeProduct. This may change in the future.
167
177
  # other_enumerable is duped and reset if it is a HugeEnumerable. This may change in the future.
168
- def product(other_enumerable) # :yields: element
169
- other_enumerable = other_enumerable.dup.reset! if other_enumerable.is_a?(HugeEnumerable)
170
- random_number_generator = rng != self.method(:rand) ? rng : nil
171
- prod = HugeProduct.new(self.dup.reset!, other_enumerable, max_array_size, random_number_generator)
172
- if block_given?
173
- prod.each { |x| yield x }
178
+ def product(other_enumerable, &block) # :yields: element
179
+ other_enumerable = other_enumerable.clone.reset! if other_enumerable.is_a?(HugeEnumerable)
180
+ # Check to see if we have a specific random number generator to use.
181
+ # Using hash comparison as dups, clones, and other actions can make == and eql? return false when it is actually the same method
182
+ random_number_generator = rng.hash != method(:rand).hash ? rng : nil
183
+ prod = HugeProduct.new(self.clone.reset!, other_enumerable, max_array_size, random_number_generator)
184
+ if block
185
+ prod.each(&block)
174
186
  self
175
187
  else
176
188
  prod
@@ -221,7 +233,7 @@ class HugeEnumerable
221
233
  # ==== Side Effects
222
234
  # The new collection is reset to the current collection's original size and elements before shuffling.
223
235
  def shuffle(rng=nil)
224
- self.dup.shuffle!(rng)
236
+ self.clone.shuffle!(rng)
225
237
  end
226
238
 
227
239
  # Randomly reorders the elements of the collection.
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huge_enumerable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Hall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prime_miller_rabin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 0.1.0
@@ -21,6 +24,9 @@ dependencies:
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 0.1.0
@@ -103,7 +109,7 @@ licenses:
103
109
  - MIT
104
110
  metadata:
105
111
  homepage_uri: https://github.com/ChapterHouse/huge_enumerable
106
- source_code_uri: https://github.com/ChapterHouse/huge_enumerable/tree/v0.1.0
112
+ source_code_uri: https://github.com/ChapterHouse/huge_enumerable/tree/v0.1.1
107
113
  post_install_message:
108
114
  rdoc_options: []
109
115
  require_paths:
@@ -119,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
125
  - !ruby/object:Gem::Version
120
126
  version: '0'
121
127
  requirements: []
122
- rubygems_version: 3.2.32
128
+ rubygems_version: 3.2.33
123
129
  signing_key:
124
130
  specification_version: 4
125
131
  summary: Enumerate, sample, shuffle, combine, permutate, and create products of massive