xor_reverse_bitswap 0.1.0 → 0.3.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/xor_reverse_bitswap/version.rb +1 -1
- data/lib/xor_reverse_bitswap.rb +21 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c4f84e853e259548cdee96fa12ec29414e9eae0760d53d64103821927787e7a
|
4
|
+
data.tar.gz: c0b8c0133120a5aa99336c13a320e376d3e35e9b5d7fc6b9785409d5daca563c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 985581c86d84420a7078b9cbbd4fd4ce49411c8eadd7ea23119efaa1ff29883623492facc28b20b276e3590c5a237694a32c32f058f6c22592c74c642ec23a9a
|
7
|
+
data.tar.gz: bb5355721632e1f44340bb658820fb5e1aed3dc4f8c185e00f68f751d39a1f22b914addd0e0e0d8e363163b2c0b4c56ffc899776c7c176c554b679c911e53900
|
data/Gemfile.lock
CHANGED
data/lib/xor_reverse_bitswap.rb
CHANGED
@@ -21,17 +21,30 @@ module XorReverseBitswap
|
|
21
21
|
|
22
22
|
def self.ranger(start_range:, end_range:, step_size: 1)
|
23
23
|
range_size = (end_range - start_range) / step_size
|
24
|
-
offset = (end_range - start_range)
|
25
24
|
raise "range_size must be full 1s binary" unless range_size.to_s(2).count("0").zero?
|
26
25
|
|
27
26
|
bit_range_size = range_size.to_s(2).size
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
if step_size > 1
|
28
|
+
(0..range_size).lazy.map do |n|
|
29
|
+
value = (n ^ range_size).to_s(2).rjust(bit_range_size, "0").reverse.to_i(2)
|
30
|
+
[
|
31
|
+
start_range + (value * step_size),
|
32
|
+
start_range + ((value + 1) * step_size) - 1
|
33
|
+
].tap do |r1, r2|
|
34
|
+
raise "range #{r1} is out of bounds" unless (start_range..end_range).cover?(r1)
|
35
|
+
raise "range #{r2} is out of bounds" unless (start_range..end_range).cover?(r2)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
else
|
39
|
+
(1..range_size).lazy.map do |n|
|
40
|
+
value = (n ^ range_size).to_s(2).rjust(bit_range_size, "0").reverse.to_i(2)
|
41
|
+
[
|
42
|
+
start_range + (value * step_size),
|
43
|
+
start_range + ((value + 1) * step_size)
|
44
|
+
].tap do |r1, r2|
|
45
|
+
raise "range #{r1} is out of bounds" unless (start_range..end_range).cover?(r1)
|
46
|
+
raise "range #{r2} is out of bounds" unless (start_range..end_range).cover?(r2)
|
47
|
+
end
|
35
48
|
end
|
36
49
|
end
|
37
50
|
end
|