intperm 1.1.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/intperm.rb +60 -0
  3. data/lib/parameters.yaml +276 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3be50da5bdab13dfe4e3deddfe2a10e5d5d1bfd2
4
+ data.tar.gz: 4e8eac9842b1c8970edd5e5344f71024df860752
5
+ SHA512:
6
+ metadata.gz: f0a7cc68ba546612b613d304c87e1a8cc66eb361cb3486c2d4b51b0dadf61a0f87cdf8a6190370a400ced56a24fac0322c5a58bb09cd92200902e99ff0886c88
7
+ data.tar.gz: 9458c0aae42963fff8edf5f7bde4c2239c9b9df469f2ccf9bbc01620b907a9f9ce56c960410aad5da53b3b4526ab61a8de3f471eff93ccde4234e95fb0f0c44d
data/lib/intperm.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'yaml'
2
+
3
+ # Main permutation class.
4
+ class Permutation
5
+ def initialize(seed, bit_length = 64)
6
+ @mask = (1 << bit_length) - 1
7
+ xorshift = XORShift.new seed, @mask
8
+ @masks = (0.upto bit_length * 2).map do |i|
9
+ xorshift.next & ((1 << (i >> 1)) ^ @mask)
10
+ end
11
+ @bit_length = bit_length
12
+ end
13
+
14
+ def map_to(num)
15
+ permutate num, (0.upto @bit_length - 1)
16
+ end
17
+
18
+ def map_from(num)
19
+ permutate num, ((@bit_length - 1).downto 0)
20
+ end
21
+
22
+ private
23
+
24
+ def permutate(num, range)
25
+ range.each do |i|
26
+ num ^= bitmask_at_bit num, i
27
+ end
28
+ num
29
+ end
30
+
31
+ def bitmask_at_bit(num, bit)
32
+ bit_mask = 1 << bit
33
+ if (bit_mask & num) >> bit == 0
34
+ num = @mask ^ (@masks[(bit << 1) +
35
+ ((bit_mask & num) >> bit)] | (bit_mask ^ bit_mask & num))
36
+ else
37
+ num = @mask ^ (@masks[(bit << 1) +
38
+ ((bit_mask & num) >> bit)] | (bit_mask & num))
39
+ end
40
+ num
41
+ end
42
+ end
43
+
44
+ TRIPLETS = YAML.load_file File.join File.dirname(__FILE__), 'parameters.yaml'
45
+
46
+ # XOR shift helper class.
47
+ # Used for expanding the seed to a random stream.
48
+ class XORShift
49
+ def initialize(seed, bitmask)
50
+ @seed = seed
51
+ @a, @b, @c = TRIPLETS[seed % TRIPLETS.length]
52
+ @bitmask = bitmask
53
+ end
54
+
55
+ def next
56
+ @seed ^= @bitmask & (@seed << @a)
57
+ @seed ^= @bitmask & (@seed >> @b)
58
+ @seed ^= @bitmask & (@seed << @c)
59
+ end
60
+ end
@@ -0,0 +1,276 @@
1
+ # Triplets from http://www.jstatsoft.org/v08/i14/paper page 3.
2
+ - [ 1, 1, 54]
3
+ - [ 1, 1, 55]
4
+ - [ 1, 3, 45]
5
+ - [ 1, 7, 9]
6
+ - [ 1, 7, 44]
7
+ - [ 1, 7, 46]
8
+ - [ 1, 9, 50]
9
+ - [ 1, 11, 35]
10
+ - [ 1, 11, 50]
11
+ - [ 1, 13, 45]
12
+ - [ 1, 15, 4]
13
+ - [ 1, 15, 63]
14
+ - [ 1, 19, 6]
15
+ - [ 1, 19, 16]
16
+ - [ 1, 23, 14]
17
+ - [ 1, 23, 29]
18
+ - [ 1, 29, 34]
19
+ - [ 1, 35, 5]
20
+ - [ 1, 35, 11]
21
+ - [ 1, 35, 34]
22
+ - [ 1, 45, 37]
23
+ - [ 1, 51, 13]
24
+ - [ 1, 53, 3]
25
+ - [ 1, 59, 14]
26
+ - [ 2, 13, 23]
27
+ - [ 2, 31, 51]
28
+ - [ 2, 31, 53]
29
+ - [ 2, 43, 27]
30
+ - [ 2, 47, 49]
31
+ - [ 3, 1, 11]
32
+ - [ 3, 5, 21]
33
+ - [ 3, 13, 59]
34
+ - [ 3, 21, 31]
35
+ - [ 3, 25, 20]
36
+ - [ 3, 25, 31]
37
+ - [ 3, 25, 56]
38
+ - [ 3, 29, 40]
39
+ - [ 3, 29, 47]
40
+ - [ 3, 29, 49]
41
+ - [ 3, 35, 14]
42
+ - [ 3, 37, 17]
43
+ - [ 3, 43, 4]
44
+ - [ 3, 43, 6]
45
+ - [ 3, 43, 11]
46
+ - [ 3, 51, 16]
47
+ - [ 3, 53, 7]
48
+ - [ 3, 61, 17]
49
+ - [ 3, 61, 26]
50
+ - [ 4, 7, 19]
51
+ - [ 4, 9, 13]
52
+ - [ 4, 15, 51]
53
+ - [ 4, 15, 53]
54
+ - [ 4, 29, 45]
55
+ - [ 4, 29, 49]
56
+ - [ 4, 31, 33]
57
+ - [ 4, 35, 15]
58
+ - [ 4, 35, 21]
59
+ - [ 4, 37, 11]
60
+ - [ 4, 37, 21]
61
+ - [ 4, 41, 19]
62
+ - [ 4, 41, 45]
63
+ - [ 4, 43, 21]
64
+ - [ 4, 43, 31]
65
+ - [ 4, 53, 7]
66
+ - [ 5, 9, 23]
67
+ - [ 5, 11, 54]
68
+ - [ 5, 15, 27]
69
+ - [ 5, 17, 11]
70
+ - [ 5, 23, 36]
71
+ - [ 5, 33, 29]
72
+ - [ 5, 41, 20]
73
+ - [ 5, 45, 16]
74
+ - [ 5, 47, 23]
75
+ - [ 5, 53, 20]
76
+ - [ 5, 59, 33]
77
+ - [ 5, 59, 35]
78
+ - [ 5, 59, 63]
79
+ - [ 6, 1, 17]
80
+ - [ 6, 3, 49]
81
+ - [ 6, 17, 47]
82
+ - [ 6, 23, 27]
83
+ - [ 6, 27, 7]
84
+ - [ 6, 43, 21]
85
+ - [ 6, 49, 29]
86
+ - [ 6, 55, 17]
87
+ - [ 7, 5, 41]
88
+ - [ 7, 5, 47]
89
+ - [ 7, 5, 55]
90
+ - [ 7, 7, 20]
91
+ - [ 7, 9, 38]
92
+ - [ 7, 11, 10]
93
+ - [ 7, 11, 35]
94
+ - [ 7, 13, 58]
95
+ - [ 7, 19, 17]
96
+ - [ 7, 19, 54]
97
+ - [ 7, 23, 8]
98
+ - [ 7, 25, 58]
99
+ - [ 7, 27, 59]
100
+ - [ 7, 33, 8]
101
+ - [ 7, 41, 40]
102
+ - [ 7, 43, 28]
103
+ - [ 7, 51, 24]
104
+ - [ 7, 57, 12]
105
+ - [ 8, 5, 59]
106
+ - [ 8, 9, 25]
107
+ - [ 8, 13, 25]
108
+ - [ 8, 13, 61]
109
+ - [ 8, 15, 21]
110
+ - [ 8, 25, 59]
111
+ - [ 8, 29, 19]
112
+ - [ 8, 31, 17]
113
+ - [ 8, 37, 21]
114
+ - [ 8, 51, 21]
115
+ - [ 9, 1, 27]
116
+ - [ 9, 5, 36]
117
+ - [ 9, 5, 43]
118
+ - [ 9, 7, 18]
119
+ - [ 9, 19, 18]
120
+ - [ 9, 21, 11]
121
+ - [ 9, 21, 20]
122
+ - [ 9, 21, 40]
123
+ - [ 9, 23, 57]
124
+ - [ 9, 27, 10]
125
+ - [ 9, 29, 12]
126
+ - [ 9, 29, 37]
127
+ - [ 9, 37, 31]
128
+ - [ 9, 41, 45]
129
+ - [10, 7, 33]
130
+ - [10, 27, 59]
131
+ - [10, 53, 13]
132
+ - [11, 5, 32]
133
+ - [11, 5, 34]
134
+ - [11, 5, 43]
135
+ - [11, 5, 45]
136
+ - [11, 9, 14]
137
+ - [11, 9, 34]
138
+ - [11, 13, 40]
139
+ - [11, 15, 37]
140
+ - [11, 23, 42]
141
+ - [11, 23, 56]
142
+ - [11, 25, 48]
143
+ - [11, 27, 26]
144
+ - [11, 29, 14]
145
+ - [11, 31, 18]
146
+ - [11, 53, 23]
147
+ - [12, 1, 31]
148
+ - [12, 3, 13]
149
+ - [12, 3, 49]
150
+ - [12, 7, 13]
151
+ - [12, 11, 47]
152
+ - [12, 25, 27]
153
+ - [12, 39, 49]
154
+ - [12, 43, 19]
155
+ - [13, 3, 40]
156
+ - [13, 3, 53]
157
+ - [13, 7, 17]
158
+ - [13, 9, 15]
159
+ - [13, 9, 50]
160
+ - [13, 13, 19]
161
+ - [13, 17, 43]
162
+ - [13, 19, 28]
163
+ - [13, 19, 47]
164
+ - [13, 21, 18]
165
+ - [13, 21, 49]
166
+ - [13, 29, 35]
167
+ - [13, 35, 30]
168
+ - [13, 35, 38]
169
+ - [13, 47, 23]
170
+ - [13, 51, 21]
171
+ - [14, 13, 17]
172
+ - [14, 15, 19]
173
+ - [14, 23, 33]
174
+ - [14, 31, 45]
175
+ - [14, 47, 15]
176
+ - [15, 1, 19]
177
+ - [15, 5, 37]
178
+ - [15, 13, 28]
179
+ - [15, 13, 52]
180
+ - [15, 17, 27]
181
+ - [15, 19, 63]
182
+ - [15, 21, 46]
183
+ - [15, 23, 23]
184
+ - [15, 45, 17]
185
+ - [15, 47, 16]
186
+ - [15, 49, 26]
187
+ - [16, 5, 17]
188
+ - [16, 7, 39]
189
+ - [16, 11, 19]
190
+ - [16, 11, 27]
191
+ - [16, 13, 55]
192
+ - [16, 21, 35]
193
+ - [16, 25, 43]
194
+ - [16, 27, 53]
195
+ - [16, 47, 17]
196
+ - [17, 15, 58]
197
+ - [17, 23, 29]
198
+ - [17, 23, 51]
199
+ - [17, 23, 52]
200
+ - [17, 27, 22]
201
+ - [17, 45, 22]
202
+ - [17, 47, 28]
203
+ - [17, 47, 29]
204
+ - [17, 47, 54]
205
+ - [18, 1, 25]
206
+ - [18, 3, 43]
207
+ - [18, 19, 19]
208
+ - [18, 25, 21]
209
+ - [18, 41, 23]
210
+ - [19, 7, 36]
211
+ - [19, 7, 55]
212
+ - [19, 13, 37]
213
+ - [19, 15, 46]
214
+ - [19, 21, 52]
215
+ - [19, 25, 20]
216
+ - [19, 41, 21]
217
+ - [19, 43, 27]
218
+ - [20, 1, 31]
219
+ - [20, 5, 29]
220
+ - [21, 1, 27]
221
+ - [21, 9, 29]
222
+ - [21, 13, 52]
223
+ - [21, 15, 28]
224
+ - [21, 15, 29]
225
+ - [21, 17, 24]
226
+ - [21, 17, 30]
227
+ - [21, 17, 48]
228
+ - [21, 21, 32]
229
+ - [21, 21, 34]
230
+ - [21, 21, 37]
231
+ - [21, 21, 38]
232
+ - [21, 21, 40]
233
+ - [21, 21, 41]
234
+ - [21, 21, 43]
235
+ - [21, 41, 23]
236
+ - [22, 3, 39]
237
+ - [23, 9, 38]
238
+ - [23, 9, 48]
239
+ - [23, 9, 57]
240
+ - [23, 13, 38]
241
+ - [23, 13, 58]
242
+ - [23, 13, 61]
243
+ - [23, 17, 25]
244
+ - [23, 17, 54]
245
+ - [23, 17, 56]
246
+ - [23, 17, 62]
247
+ - [23, 41, 34]
248
+ - [23, 41, 51]
249
+ - [24, 9, 35]
250
+ - [24, 11, 29]
251
+ - [24, 25, 25]
252
+ - [24, 31, 35]
253
+ - [25, 7, 46]
254
+ - [25, 7, 49]
255
+ - [25, 9, 39]
256
+ - [25, 11, 57]
257
+ - [25, 13, 29]
258
+ - [25, 13, 39]
259
+ - [25, 13, 62]
260
+ - [25, 15, 47]
261
+ - [25, 21, 44]
262
+ - [25, 27, 27]
263
+ - [25, 27, 53]
264
+ - [25, 33, 36]
265
+ - [25, 39, 54]
266
+ - [28, 9, 55]
267
+ - [28, 11, 53]
268
+ - [29, 27, 37]
269
+ - [31, 1, 51]
270
+ - [31, 25, 37]
271
+ - [31, 27, 35]
272
+ - [33, 31, 43]
273
+ - [33, 31, 55]
274
+ - [43, 21, 46]
275
+ - [49, 15, 61]
276
+ - [55, 9, 56]
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intperm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Attila Oláh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple pseudo-random permutation of arbitrary sized integers.
14
+ email: attila@attilaolah.eu
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/intperm.rb
20
+ - lib/parameters.yaml
21
+ homepage: https://github.com/attilaolah/intperm.rb
22
+ licenses:
23
+ - Public Domain
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.14
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Permutation
45
+ test_files: []
46
+ has_rdoc: