algorithmable 0.14.0 → 0.15.0

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: 2819e21aacb2d64cd559ea000b1e91a3e522ed64
4
- data.tar.gz: 2c44dfea8b1f9552fd28d0de362b7c4617d9772f
3
+ metadata.gz: 7cc55555926e43646d71cbee211f801060920888
4
+ data.tar.gz: 14adcb09b5e3cd5f656ec0a8790991497079a66f
5
5
  SHA512:
6
- metadata.gz: 7518a1f6a826af9f6a232f77ec85dd4e09d2f93ac1c272d01d3aa20a6ea1c1a25950ba81abcd28ce62c752ed15c599bb3e9de25321f9a1f8e1d0de32240647fc
7
- data.tar.gz: 912456f9bb48de78827502407b6967c48321f4a8066d1e667f58db0cfca4f4ec16fddbe1408a065e517803f94a982964ed5359019556e890cb7ed2b43ffb1e56
6
+ metadata.gz: e6baa727db4733da616191809992a85be13518dbdc41e086e4c5497537fec2baf6f3f13743cc3e7f68db37cd0841b66950167937629c3c91dfb6915c56881b3e
7
+ data.tar.gz: fbabc1308ccc5b6774889d1b6b96b6fe9301d8de5c300b99cdeec13678fe6c6fe8b4ce2b6cb8747af36597d159f947ac859bb1fb7608f239da3337fbf4871972
@@ -1,9 +1,12 @@
1
1
  module Algorithmable
2
2
  module Cache
3
3
  autoload :Imp, 'algorithmable/cache/imp'
4
+ autoload :Methods, 'algorithmable/cache/methods'
4
5
  autoload :PrimitiveMinHeap, 'algorithmable/cache/primitive_min_heap'
5
6
  autoload :PrimitiveMaxHeap, 'algorithmable/cache/primitive_max_heap'
6
7
 
8
+ private_constant :Imp
9
+
7
10
  def new_lru_cache(size, heap = PrimitiveMaxHeap.new)
8
11
  Imp.new size, heap
9
12
  end
@@ -3,7 +3,7 @@ module Algorithmable
3
3
  class Imp
4
4
  extend Forwardable
5
5
 
6
- def_delegators :@heap, :size, :empty?, :[]
6
+ def_delegators :@heap, :size, :empty?, :[], :key?, :clear
7
7
 
8
8
  def initialize(max_size, heap)
9
9
  @max_size = max_size
@@ -0,0 +1,16 @@
1
+ module Algorithmable
2
+ module Cache
3
+ module Methods
4
+ def clear
5
+ @storage = {}
6
+ @index = []
7
+ self
8
+ end
9
+
10
+ def pop
11
+ key = @index.delete @index.last
12
+ @storage.delete key
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,9 +1,11 @@
1
1
  module Algorithmable
2
2
  module Cache
3
3
  class PrimitiveMaxHeap
4
+ include Algorithmable::Cache::Methods
4
5
  extend Forwardable
5
6
 
6
7
  def_delegators :@index, :size, :empty?
8
+ def_delegators :@storage, :key?
7
9
 
8
10
  def initialize(index = [])
9
11
  @storage = {}
@@ -21,11 +23,6 @@ module Algorithmable
21
23
  end
22
24
  end
23
25
 
24
- def pop
25
- key = @index.delete @index.last
26
- @storage.delete key
27
- end
28
-
29
26
  private
30
27
 
31
28
  def swim(key)
@@ -1,9 +1,11 @@
1
1
  module Algorithmable
2
2
  module Cache
3
3
  class PrimitiveMinHeap
4
+ include Algorithmable::Cache::Methods
4
5
  extend Forwardable
5
6
 
6
7
  def_delegators :@index, :size, :empty?
8
+ def_delegators :@storage, :key?
7
9
 
8
10
  def initialize(index = [])
9
11
  @storage = {}
@@ -21,11 +23,6 @@ module Algorithmable
21
23
  end
22
24
  end
23
25
 
24
- def pop
25
- key = @index.delete @index.last
26
- @storage.delete key
27
- end
28
-
29
26
  private
30
27
 
31
28
  def sink(key)
@@ -1,3 +1,3 @@
1
1
  module Algorithmable
2
- VERSION = '0.14.0'
2
+ VERSION = '0.15.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algorithmable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Lishtaba
@@ -156,6 +156,7 @@ files:
156
156
  - lib/algorithmable.rb
157
157
  - lib/algorithmable/cache.rb
158
158
  - lib/algorithmable/cache/imp.rb
159
+ - lib/algorithmable/cache/methods.rb
159
160
  - lib/algorithmable/cache/primitive_max_heap.rb
160
161
  - lib/algorithmable/cache/primitive_min_heap.rb
161
162
  - lib/algorithmable/cups.rb