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: c7fb91f6158a358309e3a072704afe54e6c1b090
4
- data.tar.gz: 8e4bc2cbc54300101e3333853e229a21d889c649
3
+ metadata.gz: b706e2d85061322d3acfdca760293f4f6a56029a
4
+ data.tar.gz: 1dbc8f2d1cf9652d05b2b78e7dc3658dece7ea5e
5
5
  SHA512:
6
- metadata.gz: 0fcba7fd2564eb6ade7cb8fb8a9409a4a88e67287f1377bdb6edfd6514c56ecfb8cd1b8c16a8bac1b026cd6a96cd4a2e593479e74618a533eb8d0e27cd79af8d
7
- data.tar.gz: 5fd3fc1ea446f8b1c2da7a18b0ed87e023baef177f4d4862510fa859418babf90509d90669f8984087eb2e6486a7dd448f6f006cbcd920d762879e9dfc090a6f
6
+ metadata.gz: 553538201c8c359742f0432c14cea0be9e4e03e12b114921867f26be8765978ca1a1a336d61693704a583674f7d27b3114a566e5f4650f84b3826266b0f0c167
7
+ data.tar.gz: 4839ef8d7196f56935220e891fc3f977c49bd28ce47ee52977e4c8ee3fecc3c62e87eedda4c6cefa4a4c1e5e4669855885d5a2113214cc00c0764d474689fb18
@@ -2,7 +2,7 @@ module DataStructures101
2
2
 
3
3
  class ChainedHashTable < Hash::BaseHashTable
4
4
 
5
- def initialize(capacity = 31, prime = 109345121, hash_lambda = nil)
5
+ def initialize(capacity: 31, prime: 109345121, hash_lambda: nil)
6
6
  super
7
7
  end
8
8
 
@@ -5,20 +5,19 @@ module DataStructures101
5
5
 
6
6
  attr_reader :size, :hash_lambda, :capacity
7
7
 
8
- def initialize(capacity, prime, hash_lambda = nil)
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
- random = Random.new
14
- scale = random.rand(prime - 1) + 1
15
- shift = random.rand(prime)
16
-
17
- @hash_lambda = if hash_lambda.nil?
18
- ->(key) { return (((key.hash * scale + shift) % prime) % @capacity).abs }
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 = 31, prime = 109345121,
9
- hash_lambda = nil, probe_lambda = nil)
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 }
@@ -1,3 +1,3 @@
1
1
  module DataStructures101
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_structures_101
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - aegis