data_structures_101 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b706e2d85061322d3acfdca760293f4f6a56029a
|
4
|
+
data.tar.gz: 1dbc8f2d1cf9652d05b2b78e7dc3658dece7ea5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553538201c8c359742f0432c14cea0be9e4e03e12b114921867f26be8765978ca1a1a336d61693704a583674f7d27b3114a566e5f4650f84b3826266b0f0c167
|
7
|
+
data.tar.gz: 4839ef8d7196f56935220e891fc3f977c49bd28ce47ee52977e4c8ee3fecc3c62e87eedda4c6cefa4a4c1e5e4669855885d5a2113214cc00c0764d474689fb18
|
@@ -5,20 +5,19 @@ module DataStructures101
|
|
5
5
|
|
6
6
|
attr_reader :size, :hash_lambda, :capacity
|
7
7
|
|
8
|
-
def initialize(capacity
|
8
|
+
def initialize(capacity:, prime:, hash_lambda:)
|
9
9
|
@capacity = capacity
|
10
10
|
@size = 0
|
11
11
|
@table = Array.new(@capacity)
|
12
|
+
|
13
|
+
@hash_lambda = hash_lambda
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
hash_lambda
|
21
|
-
end
|
15
|
+
if @hash_lambda.nil?
|
16
|
+
random = Random.new
|
17
|
+
scale = random.rand(prime - 1) + 1
|
18
|
+
shift = random.rand(prime)
|
19
|
+
@hash_lambda = ->(key) { return (((key.hash * scale + shift) % prime) % @capacity).abs }
|
20
|
+
end
|
22
21
|
end
|
23
22
|
|
24
23
|
def []=(key, value)
|
@@ -5,9 +5,8 @@ module DataStructures101
|
|
5
5
|
|
6
6
|
attr_reader :probe_lambda
|
7
7
|
|
8
|
-
def initialize(capacity
|
9
|
-
|
10
|
-
super(capacity, prime, hash_lambda)
|
8
|
+
def initialize(capacity: 31, prime: 109345121, hash_lambda: nil, probe_lambda: nil)
|
9
|
+
super(capacity: capacity, prime: prime, hash_lambda: hash_lambda)
|
11
10
|
|
12
11
|
@probe_lambda = if probe_lambda.nil?
|
13
12
|
->(h, i) { return (h + i) % @capacity }
|