data_structures_101 0.2.1 → 0.2.2

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: f215d1362121ff577224993028a8870cd3fd1b82
4
- data.tar.gz: 9785b4159ec72926f1fb81c5baeda8281d2840cb
3
+ metadata.gz: 9a5ee7c74cd4fd38e119bb0058e562d7e8b165a9
4
+ data.tar.gz: bd3ee1e47e446c1a1030c2fb691af1347ffe18e0
5
5
  SHA512:
6
- metadata.gz: 005a8f910dad00e6db443761b725eac89b384e1f6f79a0deb94d526c511d791b1b110d111159c80d202d142f3b0d2cb11aac984e925e468e25158fd3416f89e3
7
- data.tar.gz: f477fe15da1f404dc753690b7d0ae27861f9785d81bcf6725ce2d8f862a8ad491075871e2883ac122d0a6f29edbe35ce35477975c1657afe39995b4df952b5b2
6
+ metadata.gz: ac3297439e7fc41529aa29c6657765dfbcdf56bec8c6e17454ff8ad607baca4a24f5f922ed85a12eae9aea9f950c5cb7b5432f4b0142f4f6c9c0670ed0b665f5
7
+ data.tar.gz: d28997562681c7028e9793fc1bad0fbdff5e27fa2194809ced10f6cc5fd9dff75d64e9e089da19259aab5a34ad68404f0a146a891e583c6e656b4d3fd02421d4
@@ -36,5 +36,15 @@ module DataStructures101
36
36
 
37
37
  value
38
38
  end
39
+
40
+ def bucket_each
41
+ @table.each do |bucket|
42
+ next if bucket.nil?
43
+
44
+ bucket.each do |key, value|
45
+ yield(key, value)
46
+ end
47
+ end
48
+ end
39
49
  end
40
50
  end
@@ -1,8 +1,9 @@
1
1
  module DataStructures101
2
2
  module Hash
3
3
  class BaseHashTable
4
+ include Enumerable
4
5
 
5
- attr_reader :size, :hash_lambda
6
+ attr_reader :size, :hash_lambda, :capacity
6
7
 
7
8
  def initialize(capacity, prime, hash_lambda = nil)
8
9
  @capacity = capacity
@@ -41,6 +42,14 @@ module DataStructures101
41
42
  bucket_delete(hash_lambda.call(key), key)
42
43
  end
43
44
 
45
+ def each
46
+ return enum_for(:each) unless block_given?
47
+
48
+ bucket_each do |key, value|
49
+ yield(key, value)
50
+ end
51
+ end
52
+
44
53
  private
45
54
 
46
55
  def new_capacity()
@@ -28,7 +28,7 @@ module DataStructures101
28
28
  end
29
29
  end
30
30
 
31
- def size()
31
+ def size
32
32
  @table.size
33
33
  end
34
34
 
@@ -47,6 +47,13 @@ module DataStructures101
47
47
  value
48
48
  end
49
49
 
50
+ def each
51
+ return enum_for(:each) unless block_given?
52
+
53
+ @table.each do |key, value|
54
+ yield(key, value)
55
+ end
56
+ end
50
57
  end
51
58
  end
52
59
  end
@@ -54,6 +54,14 @@ module DataStructures101
54
54
  value
55
55
  end
56
56
 
57
+ def bucket_each
58
+ @table.each do |elem|
59
+ next if elem.nil? || elem == Sentinel.instance
60
+
61
+ yield(elem.first, elem.last)
62
+ end
63
+ end
64
+
57
65
  def find_slot(h, key)
58
66
  idx = -1
59
67
 
@@ -1,3 +1,3 @@
1
1
  module DataStructures101
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aegis