muflax 0.4.2 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5fdd0ce877effb80734d2b23769e4e4fc3c5a544fcdd8260b1ca67bb93980f8
4
- data.tar.gz: 521d13886644a3b58645e2381d567b554bc1b26e4e4c66fe68d9f2671f07843d
3
+ metadata.gz: f9b07c2ad54ab3fb8c72ca2fb0f5b7e329e9f0d22c66e935a53340079fdab7e2
4
+ data.tar.gz: d0eeaf16563dfc127cacd0f5726967c4934442af1861cc4b0b25ca9e9d745b1a
5
5
  SHA512:
6
- metadata.gz: 80b4c6dc7bf8a0ea8610fef9e9613a2a36af3ff74d91c001d2f84f968fe1317dda7ef0ad127440da19fe5606321a4c7b6ccb5050ace921305d2c8c545a3db1dd
7
- data.tar.gz: 4df8425b6ec4659bb520644562f262822798ed8eaba73e08ee5fc7ec185ffa57b6dada9b058e6971a70a418ed4c5c816e5ccc9448dd87b2446a24f185e73cb24
6
+ metadata.gz: 1ac6a3aaad1add82d5346a48d06c6a1293d23007d6308a4d9a75c0ad5450394cad6fa8d94c5115768a5582d25a3cb460de0accc06c62944978a16de22384ae6a
7
+ data.tar.gz: 8af8fc0380a982d6f7a31d6524d1670b5c612e3948385a6b1c0fc0b662480b36069212e45fffec409053ad8e47ff55f9e639cbe60a735f78bd5f1e82fe14d2e2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- muflax (0.4.2)
4
+ muflax (0.5.0)
5
5
  awesome_print (~> 1)
6
6
  debug_inspector (~> 0.0)
7
7
  fast_blank (~> 1)
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Copyright Steffie Dorn <mail@muflax.com>, 2019
4
+ # License: GNU APGLv3 (or later) <http://www.gnu.org/copyleft/gpl.html>
5
+
6
+ require "forwardable"
7
+
8
+ class Reservoir
9
+ include Enumerable
10
+ extend Forwardable
11
+
12
+ attr_accessor :sample_size, :total
13
+
14
+ def initialize sample_size
15
+ @sample_size = sample_size
16
+ @total = 0
17
+ @reservoir = []
18
+ end
19
+
20
+ def <<(obj)
21
+ if @total < @sample_size
22
+ # fill empty slot in the reservoir
23
+ @reservoir << obj
24
+ else
25
+ # randomly replace elements in the reservoir with a decreasing probability
26
+ r = rand(0..@total)
27
+ @reservoir[r] = obj if r < @sample_size
28
+ end
29
+
30
+ @total += 1
31
+ end
32
+
33
+ def add list ; list.each{|x| self << x} ; end
34
+ def clear ; @reservoir.clear; @total = 0 ; end
35
+ def full? ; @reservoir.size >= @sample_size ; end
36
+
37
+ def_delegators :@reservoir, :each, :size, :empty?, :uniq
38
+ end
39
+
40
+ class HardReservoir < Reservoir
41
+ # assumes examples are pre-randomized, but ensures that all elements are unique
42
+
43
+ def initialize sample_size
44
+ @sample_size = sample_size
45
+ @total = 0
46
+ @reservoir = Set.new
47
+ end
48
+
49
+ def <<(obj)
50
+ # *only* fill empty slot in the reservoir
51
+ @reservoir << obj if @reservoir.size < @sample_size
52
+
53
+ @total += 1
54
+ end
55
+
56
+ def uniq *args, &block ; @reservoir.to_a.uniq(*args, &block) ; end
57
+ end
data/muflax.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "muflax"
3
- s.version = "0.4.2"
3
+ s.version = "0.5.0"
4
4
 
5
5
  s.authors = ["muflax"]
6
6
  s.summary = "muflax standard library"
metadata CHANGED
@@ -1,34 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muflax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - muflax
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
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fhGEJ1deAR/i8RPCblyBDtl7Ved3uX8izfU9LItVY+HOAzl69Qp0fe2TYH+y4uCO
30
- -----END CERTIFICATE-----
31
- date: 2019-06-05 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2019-06-28 00:00:00.000000000 Z
32
12
  dependencies:
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: awesome_print
@@ -172,6 +152,7 @@ files:
172
152
  - lib/muflax/objects.rb
173
153
  - lib/muflax/panes.rb
174
154
  - lib/muflax/regex.rb
155
+ - lib/muflax/reservoir.rb
175
156
  - lib/muflax/string.rb
176
157
  - lib/muflax/table.rb
177
158
  - lib/muflax/time.rb
@@ -195,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
176
  - !ruby/object:Gem::Version
196
177
  version: '0'
197
178
  requirements: []
198
- rubygems_version: 3.0.3
179
+ rubygems_version: 3.0.4
199
180
  signing_key:
200
181
  specification_version: 4
201
182
  summary: muflax standard library
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file