huge_enumerable 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/huge_enumerable/version.rb +1 -1
- data/lib/huge_enumerable.rb +31 -19
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89d12cc6df8a801fac7ebc11ca0bbbfb8b4878a5966ad861c8ffcf7599256169
|
4
|
+
data.tar.gz: 7a99114124361f229c7c75f01fe1afa694620a9bccab5fcb28d39045e2b3d957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e39021c74162b81d22e6ae66264dccef760106e5ffe43a7d16c030806d4d42269ad78320ebd404cbb7bd125d86956fd7af6ddde20b599541a8d2cd3b0eed22f
|
7
|
+
data.tar.gz: cc95c24b43c8ed59221a546bbfa24d1511593eb78432e39faf9bc3317b8300baf2d968865033fabb38a25fd6b1043e3ec5bc3ff741c5ec4a50797fd5f049518e
|
data/lib/huge_enumerable.rb
CHANGED
@@ -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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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.
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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.
|
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Hall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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.
|
112
|
+
source_code_uri: https://github.com/ChapterHouse/huge_enumerable/tree/v0.1.2
|
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.
|
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
|