muflax 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/muflax/reservoir.rb +57 -0
- data/muflax.gemspec +1 -1
- metadata +5 -24
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9b07c2ad54ab3fb8c72ca2fb0f5b7e329e9f0d22c66e935a53340079fdab7e2
|
4
|
+
data.tar.gz: d0eeaf16563dfc127cacd0f5726967c4934442af1861cc4b0b25ca9e9d745b1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ac6a3aaad1add82d5346a48d06c6a1293d23007d6308a4d9a75c0ad5450394cad6fa8d94c5115768a5582d25a3cb460de0accc06c62944978a16de22384ae6a
|
7
|
+
data.tar.gz: 8af8fc0380a982d6f7a31d6524d1670b5c612e3948385a6b1c0fc0b662480b36069212e45fffec409053ad8e47ff55f9e639cbe60a735f78bd5f1e82fe14d2e2
|
data/Gemfile.lock
CHANGED
@@ -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
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
|
+
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
|
-
MIIDLDCCAhSgAwIBAgIBBTANBgkqhkiG9w0BAQsFADA8MQ0wCwYDVQQDDARtYWls
|
14
|
-
MRYwFAYKCZImiZPyLGQBG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RPCblyBDtl7Ved3uX8izfU9LItVY+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.
|
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
|