setfu 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/setfu.rb +153 -75
- data/lib/setfu/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86cb17462d85ca1892275124d15b258e39500a81
|
4
|
+
data.tar.gz: 0c6b22148997f47f43494269c18fe78de5cec4fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba3a1ecece8183f14ce227512e19b89fcda2724bcc84e7e5ec67e81b7c781013375ac29cd777370411dc9aaf499117fcc6100857211e06d9bc92713a360ffa89
|
7
|
+
data.tar.gz: c4f64253c8796b4e917aa09a0ff93eeefe9e2a05b39e5f212968aa51e02c8f123dfb662707f646c06362f79d7cf3ba9ac912e0f13f4649622a5bb66d6ee2dfb9
|
data/lib/setfu.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "setfu/version"
|
2
2
|
|
3
|
-
class
|
3
|
+
class BitSet
|
4
4
|
attr_reader :entropy
|
5
5
|
|
6
6
|
def entropy=(ent) # entropy only gets bigger, just like the universe!
|
@@ -8,42 +8,42 @@ class Set
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.uppercase_chars
|
11
|
-
set =
|
11
|
+
set = BitSet.new
|
12
12
|
set.set_bits!(2475880041677272402379145216)
|
13
13
|
set.entropy=91
|
14
14
|
return set
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.lowercase_chars
|
18
|
-
set =
|
18
|
+
set = BitSet.new
|
19
19
|
set.set_bits!(10633823807823001954701781295154855936)
|
20
20
|
set.entropy=123
|
21
21
|
return set
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.letter_chars
|
25
|
-
set =
|
25
|
+
set = BitSet.new
|
26
26
|
set.set_bits!(10633823810298881996379053697534001152)
|
27
27
|
set.entropy=123
|
28
28
|
return set
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.digit_chars
|
32
|
-
set =
|
32
|
+
set = BitSet.new
|
33
33
|
set.set_bits!(287948901175001088)
|
34
34
|
set.entropy=58
|
35
35
|
return set
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.parse_chars
|
39
|
-
set =
|
39
|
+
set = BitSet.new
|
40
40
|
set.set_bits!(159507359650170349735020301117175103487)
|
41
41
|
set.entropy=127
|
42
42
|
return set
|
43
43
|
end
|
44
44
|
|
45
45
|
def replace(ent)
|
46
|
-
ent = ent.
|
46
|
+
ent = ent.to_bset
|
47
47
|
@mode = ent.mode
|
48
48
|
@entropy = ent.entropy
|
49
49
|
@bits = ent.to_i
|
@@ -52,53 +52,111 @@ class Set
|
|
52
52
|
|
53
53
|
def add_parse_chars!
|
54
54
|
# add! [0..47, 58..64, 91..96, 123..126]
|
55
|
-
add!
|
55
|
+
add! BitSet.parse_chars
|
56
56
|
self
|
57
57
|
end
|
58
58
|
|
59
59
|
def add_parse_chars
|
60
|
-
return
|
60
|
+
return BitSet.parse_chars | self
|
61
61
|
end
|
62
62
|
|
63
63
|
def add_digit_chars!
|
64
|
-
add!
|
64
|
+
add! BitSet.digit_chars
|
65
65
|
self
|
66
66
|
end
|
67
67
|
|
68
68
|
def add_digit_chars
|
69
|
-
return
|
69
|
+
return BitSet.digit_chars | self
|
70
70
|
end
|
71
71
|
|
72
72
|
def add_uppercase_chars!
|
73
|
-
add!
|
73
|
+
add! BitSet.uppercase_chars
|
74
74
|
self
|
75
75
|
end
|
76
76
|
|
77
77
|
def add_uppercase_chars
|
78
|
-
return
|
78
|
+
return BitSet.uppercase_chars | self
|
79
79
|
end
|
80
80
|
|
81
81
|
def add_lowercase_chars!
|
82
|
-
add!
|
82
|
+
add! BitSet.lowercase_chars
|
83
83
|
self
|
84
84
|
end
|
85
85
|
|
86
86
|
def add_lowercase_chars
|
87
|
-
return
|
87
|
+
return BitSet.lowercase_chars | self
|
88
88
|
end
|
89
89
|
|
90
90
|
def add_letter_chars
|
91
|
-
return
|
91
|
+
return BitSet.letter_chars | self
|
92
92
|
end
|
93
93
|
|
94
94
|
def add_letter_chars!
|
95
|
-
add!
|
95
|
+
add! BitSet.letter_chars
|
96
96
|
self
|
97
97
|
end
|
98
98
|
|
99
|
+
# 01100010011111111100010101001101 ... test
|
100
|
+
# 01100010011111111100010101001101 ... left shift
|
101
|
+
# 001000000011111111000000000001000 ... and with left shift
|
102
|
+
#
|
103
|
+
# 01100010011111111100010101001101 ... test
|
104
|
+
# 00110001001111111110001010100110 ... right shift
|
105
|
+
# 00100000001111111100000000000100 ... and with right shift
|
106
|
+
#
|
107
|
+
# 001000000011111111000000000001000 ... AND with left shift
|
108
|
+
# 00100000001111111100000000000100 ... AND with right shift
|
109
|
+
# 001100000011111111100000000001100 ... OR the two ands
|
110
|
+
# 01100010011111111100010101001101 ... test original
|
111
|
+
# 01100000011111111100000000001100 ... BINGO ... original with the OR gives us the runs only
|
112
|
+
# 00000010000000000000010101000001 ... BINGO ... original XOR with OR gives us the singles!
|
113
|
+
|
114
|
+
def runs # runs << creates a set of touching elements
|
115
|
+
an_l = (@bits << 1) & @bits
|
116
|
+
an_r = (@bits >> 1) & @bits
|
117
|
+
or_lr = an_l | an_r
|
118
|
+
rtn = BitSet.new
|
119
|
+
rtn.set_bits!(or_lr & @bits)
|
120
|
+
rtn.entropy=self.entropy
|
121
|
+
return rtn
|
122
|
+
end
|
123
|
+
|
124
|
+
def singles # singles << creates a set of non-touching elements
|
125
|
+
an_l = (@bits << 1) & @bits
|
126
|
+
an_r = (@bits >> 1) & @bits
|
127
|
+
or_lr = an_l | an_r
|
128
|
+
rtn = BitSet.new
|
129
|
+
rtn.set_bits!(or_lr ^ @bits)
|
130
|
+
rtn.entropy=self.entropy
|
131
|
+
return rtn
|
132
|
+
end
|
133
|
+
|
134
|
+
def max_run # max_run << returns maximum number of consecutive numbers
|
135
|
+
return 0 if @bits==0
|
136
|
+
mx = 1
|
137
|
+
bits = @bits
|
138
|
+
loop do
|
139
|
+
bits <<= 1
|
140
|
+
bits &= @bits
|
141
|
+
break if 0 == bits
|
142
|
+
mx += 1
|
143
|
+
end
|
144
|
+
return mx
|
145
|
+
end
|
146
|
+
|
147
|
+
def runs?(cnt=2)
|
148
|
+
bits = @bits
|
149
|
+
(cnt-1).times do
|
150
|
+
bits <<= 1
|
151
|
+
bits &= @bits
|
152
|
+
return false if 0 == bits
|
153
|
+
end
|
154
|
+
return true
|
155
|
+
end
|
156
|
+
|
99
157
|
def add_opposing_case!
|
100
|
-
aa =
|
101
|
-
bb =
|
158
|
+
aa = BitSet.lowercase_chars
|
159
|
+
bb = BitSet.uppercase_chars
|
102
160
|
ka = aa & self # subset lower case
|
103
161
|
kb = bb & self # subset upper case
|
104
162
|
@bits |= ka.to_i >> 32
|
@@ -111,7 +169,7 @@ class Set
|
|
111
169
|
dup.add_opposing_case!
|
112
170
|
end
|
113
171
|
|
114
|
-
def
|
172
|
+
def to_bset
|
115
173
|
return self
|
116
174
|
end
|
117
175
|
|
@@ -119,10 +177,10 @@ class Set
|
|
119
177
|
return @mode
|
120
178
|
end
|
121
179
|
|
122
|
-
def initialize(data
|
180
|
+
def initialize(*data)
|
123
181
|
@bits = 0
|
124
182
|
@entropy = 0
|
125
|
-
add!(data)
|
183
|
+
add!(data)
|
126
184
|
self
|
127
185
|
end
|
128
186
|
|
@@ -132,6 +190,25 @@ class Set
|
|
132
190
|
self
|
133
191
|
end
|
134
192
|
|
193
|
+
def inc!
|
194
|
+
@entropy += 1
|
195
|
+
@bits <<= 1
|
196
|
+
self
|
197
|
+
end
|
198
|
+
|
199
|
+
def dec!
|
200
|
+
@bits >>= 1
|
201
|
+
self
|
202
|
+
end
|
203
|
+
|
204
|
+
def inc
|
205
|
+
return dup.inc!
|
206
|
+
end
|
207
|
+
|
208
|
+
def dec
|
209
|
+
return dup.dec!
|
210
|
+
end
|
211
|
+
|
135
212
|
def recalculate_entropy!
|
136
213
|
@entropy = 0
|
137
214
|
bits = @bits
|
@@ -165,17 +242,17 @@ class Set
|
|
165
242
|
end
|
166
243
|
|
167
244
|
def dup
|
168
|
-
rtn =
|
245
|
+
rtn = BitSet.new
|
169
246
|
rtn.replace(self)
|
170
247
|
return rtn
|
171
248
|
end
|
172
249
|
|
173
250
|
def ^(item)
|
174
251
|
rtn = self.dup
|
175
|
-
if(item.class==
|
252
|
+
if(item.class==BitSet)
|
176
253
|
rtn.set_bits!(rtn.to_i ^ item.to_i)
|
177
254
|
else
|
178
|
-
rtn =
|
255
|
+
rtn = BitSet.new(item)
|
179
256
|
rtn.set_bits!(@bits ^ rtn.to_i)
|
180
257
|
end
|
181
258
|
rtn
|
@@ -183,11 +260,11 @@ class Set
|
|
183
260
|
|
184
261
|
def |(item)
|
185
262
|
rtn = self.dup
|
186
|
-
if(item.class==
|
263
|
+
if(item.class==BitSet)
|
187
264
|
rtn.set_bits!(rtn.to_i | item.to_i)
|
188
265
|
self.entropy=item.entropy
|
189
266
|
else
|
190
|
-
rtn =
|
267
|
+
rtn = BitSet.new(item)
|
191
268
|
rtn.set_bits!(@bits | rtn.to_i)
|
192
269
|
end
|
193
270
|
rtn
|
@@ -195,24 +272,24 @@ class Set
|
|
195
272
|
|
196
273
|
def &(item)
|
197
274
|
rtn = self.dup
|
198
|
-
if(item.class==
|
275
|
+
if(item.class==BitSet)
|
199
276
|
rtn.set_bits!(rtn.to_i & item.to_i)
|
200
277
|
else
|
201
|
-
rtn =
|
278
|
+
rtn = BitSet.new(item)
|
202
279
|
rtn.set_bits!(@bits & rtn.to_i)
|
203
280
|
end
|
204
281
|
rtn
|
205
282
|
end
|
206
283
|
|
207
284
|
def -(item)
|
208
|
-
rtn =
|
285
|
+
rtn = BitSet.new
|
209
286
|
rtn.entropy = self.entropy
|
210
287
|
a = self.to_i
|
211
|
-
if(item.class==
|
288
|
+
if(item.class==BitSet)
|
212
289
|
b = item.to_i
|
213
290
|
rtn.entropy = item.entropy
|
214
291
|
else
|
215
|
-
b =
|
292
|
+
b = BitSet.new(item)
|
216
293
|
rtn.entropy = b.entropy
|
217
294
|
b = b.to_i
|
218
295
|
end
|
@@ -223,26 +300,26 @@ class Set
|
|
223
300
|
end
|
224
301
|
|
225
302
|
def **(item) # intersection test
|
226
|
-
set_item =
|
303
|
+
set_item = BitSet.new(item)
|
227
304
|
return false if (self & set_item).empty?
|
228
305
|
return true
|
229
306
|
end
|
230
307
|
|
231
308
|
# comparison operators:
|
232
309
|
def ==(item)
|
233
|
-
if(item.class==
|
310
|
+
if(item.class==BitSet)
|
234
311
|
rtn = item.to_i == self.to_i
|
235
312
|
else
|
236
|
-
rtn =
|
313
|
+
rtn = BitSet.new(item).to_i == self.to_i
|
237
314
|
end
|
238
315
|
rtn
|
239
316
|
end
|
240
317
|
|
241
318
|
def !=(item)
|
242
|
-
if(item.class==
|
319
|
+
if(item.class==BitSet)
|
243
320
|
rtn = item.to_i != self.to_i
|
244
321
|
else
|
245
|
-
rtn =
|
322
|
+
rtn = BitSet.new(item).to_i != self.to_i
|
246
323
|
end
|
247
324
|
rtn
|
248
325
|
end
|
@@ -257,7 +334,7 @@ class Set
|
|
257
334
|
# item ... case clause ... case(item)
|
258
335
|
# Note: coerce does not work in this context ...
|
259
336
|
|
260
|
-
md = item.
|
337
|
+
md = item.to_bset.mode || @mode
|
261
338
|
|
262
339
|
case md
|
263
340
|
when :mode_intersection
|
@@ -276,18 +353,18 @@ class Set
|
|
276
353
|
end
|
277
354
|
|
278
355
|
def <=(item)
|
279
|
-
si =
|
356
|
+
si = BitSet.new item
|
280
357
|
return si.include?(self)
|
281
358
|
end
|
282
359
|
|
283
360
|
def <(item)
|
284
|
-
si =
|
361
|
+
si = BitSet.new item
|
285
362
|
return false if (si == self) # not a 'proper' subset
|
286
363
|
return si.include?(self)
|
287
364
|
end
|
288
365
|
|
289
366
|
def add!(items)
|
290
|
-
if(items.class==
|
367
|
+
if(items.class==BitSet)
|
291
368
|
@bits |= items.to_i
|
292
369
|
entropy = items.entropy
|
293
370
|
elsif(items.class==Range)
|
@@ -325,8 +402,9 @@ class Set
|
|
325
402
|
end
|
326
403
|
|
327
404
|
def include?(items)
|
405
|
+
return false if items.nil? # sets never include nil
|
328
406
|
return false if @bits == 0 # empty sets include nothing including other empty sets
|
329
|
-
if(items.class==
|
407
|
+
if(items.class==BitSet)
|
330
408
|
tmp = @bits & items.to_i
|
331
409
|
return false if tmp==0
|
332
410
|
return (tmp) == items.to_i
|
@@ -458,17 +536,17 @@ class Set
|
|
458
536
|
end
|
459
537
|
end
|
460
538
|
unless idx.nil?
|
461
|
-
raise "Negative indexes are illegal for
|
539
|
+
raise "Negative indexes are illegal for BitSet" if idx < 0
|
462
540
|
self.entropy = idx+1
|
463
541
|
y = @bits & (1<<idx)
|
464
542
|
return true if y > 0
|
465
543
|
return false
|
466
544
|
end
|
467
|
-
return pset.
|
545
|
+
return pset.to_bset & self
|
468
546
|
end
|
469
547
|
|
470
548
|
def []=(*pset,value) # pset goes in the box, value after '='
|
471
|
-
pset = pset.
|
549
|
+
pset = pset.to_bset
|
472
550
|
state = value ? true : false
|
473
551
|
if state
|
474
552
|
replace pset | self # add elements to set
|
@@ -529,47 +607,47 @@ class Set
|
|
529
607
|
end
|
530
608
|
return rtn.join ""
|
531
609
|
else # :set
|
532
|
-
return ary.
|
610
|
+
return ary.to_bset
|
533
611
|
end
|
534
612
|
end
|
535
613
|
|
536
|
-
end # end
|
614
|
+
end # end BitSet
|
537
615
|
|
538
616
|
module SetFuMixinBinaryAndOperator
|
539
617
|
def &(item)
|
540
|
-
a =
|
541
|
-
b =
|
618
|
+
a = BitSet.new(self)
|
619
|
+
b = BitSet.new(item)
|
542
620
|
return a & b
|
543
621
|
end
|
544
622
|
end
|
545
623
|
|
546
624
|
module SetFuMixinBinaryOrOperator
|
547
625
|
def |(item)
|
548
|
-
a =
|
549
|
-
b =
|
626
|
+
a = BitSet.new(self)
|
627
|
+
b = BitSet.new(item)
|
550
628
|
return a | b
|
551
629
|
end
|
552
630
|
end
|
553
631
|
|
554
632
|
module SetFuMixinBinaryXorOperator
|
555
633
|
def ^(item)
|
556
|
-
a =
|
557
|
-
b =
|
634
|
+
a = BitSet.new(self)
|
635
|
+
b = BitSet.new(item)
|
558
636
|
return a ^ b
|
559
637
|
end
|
560
638
|
end
|
561
639
|
|
562
640
|
module SetFuMixinBinaryIntersectionOperator
|
563
641
|
def **(item) # intersection test
|
564
|
-
a =
|
565
|
-
b =
|
642
|
+
a = BitSet.new(self)
|
643
|
+
b = BitSet.new(item)
|
566
644
|
return a ** b
|
567
645
|
end
|
568
646
|
end
|
569
647
|
|
570
648
|
module SetFuMixinToSetMethod
|
571
|
-
def
|
572
|
-
rtn =
|
649
|
+
def to_bset
|
650
|
+
rtn = BitSet.new(self)
|
573
651
|
# byebug
|
574
652
|
return rtn
|
575
653
|
end
|
@@ -578,31 +656,31 @@ end
|
|
578
656
|
module SetFuMixinTrippleEqualsOperator
|
579
657
|
alias_method :old_triple_equal4Set, :===
|
580
658
|
def ===(item)
|
581
|
-
return old_triple_equal4Set(item) unless (item.class==
|
582
|
-
return self.
|
659
|
+
return old_triple_equal4Set(item) unless (item.class==BitSet)
|
660
|
+
return self.to_bset === item
|
583
661
|
end
|
584
662
|
end
|
585
663
|
|
586
664
|
module SetFuMixinBinarySubtractOperator
|
587
665
|
def -(item)
|
588
|
-
a =
|
589
|
-
b =
|
666
|
+
a = BitSet.new(self)
|
667
|
+
b = BitSet.new(item)
|
590
668
|
return a - b
|
591
669
|
end
|
592
670
|
end
|
593
671
|
|
594
672
|
module SetFuMixinBinarySubsetOperator
|
595
673
|
def <=(item)
|
596
|
-
a =
|
597
|
-
b =
|
674
|
+
a = BitSet.new(self)
|
675
|
+
b = BitSet.new(item)
|
598
676
|
return a <= b
|
599
677
|
end
|
600
678
|
end
|
601
679
|
|
602
680
|
module SetFuMixinBinaryProperOperator
|
603
681
|
def <(item)
|
604
|
-
a =
|
605
|
-
b =
|
682
|
+
a = BitSet.new(self)
|
683
|
+
b = BitSet.new(item)
|
606
684
|
return a < b
|
607
685
|
end
|
608
686
|
end
|
@@ -621,14 +699,14 @@ class String
|
|
621
699
|
|
622
700
|
def <=(item)
|
623
701
|
return old_string_lte4set(item) if (item.class==String)
|
624
|
-
a =
|
625
|
-
b =
|
702
|
+
a = BitSet.new(self)
|
703
|
+
b = BitSet.new(item)
|
626
704
|
return a <= b
|
627
705
|
end
|
628
706
|
def <(item)
|
629
707
|
return old_string_lt4set(item) if (item.class==String)
|
630
|
-
a =
|
631
|
-
b =
|
708
|
+
a = BitSet.new(self)
|
709
|
+
b = BitSet.new(item)
|
632
710
|
return a < b
|
633
711
|
end
|
634
712
|
end
|
@@ -647,20 +725,20 @@ class Array
|
|
647
725
|
|
648
726
|
def -(item)
|
649
727
|
return old_subtract_method4set(item) if (item.class==Array)
|
650
|
-
a =
|
651
|
-
b =
|
728
|
+
a = BitSet.new(self)
|
729
|
+
b = BitSet.new(item)
|
652
730
|
return a - b
|
653
731
|
end
|
654
732
|
def &(item)
|
655
733
|
return old_and_method4set(item) if (item.class==Array)
|
656
|
-
a =
|
657
|
-
b =
|
734
|
+
a = BitSet.new(self)
|
735
|
+
b = BitSet.new(item)
|
658
736
|
return a & b
|
659
737
|
end
|
660
738
|
def |(item)
|
661
739
|
return old_or_method4set(item) if (item.class==Array)
|
662
|
-
a =
|
663
|
-
b =
|
740
|
+
a = BitSet.new(self)
|
741
|
+
b = BitSet.new(item)
|
664
742
|
return a | b
|
665
743
|
end
|
666
744
|
end
|
data/lib/setfu/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: setfu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Colvin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|