Class: Lru
- Inherits:
-
Object
- Object
- Lru
- Defined in:
- lib/lrjew/lru.rb
Instance Attribute Summary collapse
-
#evictions ⇒ Object
readonly
Returns the value of attribute evictions.
-
#gets ⇒ Object
readonly
Returns the value of attribute gets.
-
#hits ⇒ Object
readonly
Returns the value of attribute hits.
-
#misses ⇒ Object
readonly
Returns the value of attribute misses.
Instance Method Summary collapse
- #include?(item) ⇒ Boolean
-
#initialize(indexed_bounded_stack) ⇒ Lru
constructor
A new instance of Lru.
- #inspect ⇒ Object
Constructor Details
#initialize(indexed_bounded_stack) ⇒ Lru
Returns a new instance of Lru.
4 5 6 7 |
# File 'lib/lrjew/lru.rb', line 4 def initialize(indexed_bounded_stack) @stack = indexed_bounded_stack @gets = @hits = @misses = @evictions = 0 end |
Instance Attribute Details
#evictions ⇒ Object (readonly)
Returns the value of attribute evictions.
2 3 4 |
# File 'lib/lrjew/lru.rb', line 2 def evictions @evictions end |
#gets ⇒ Object (readonly)
Returns the value of attribute gets.
2 3 4 |
# File 'lib/lrjew/lru.rb', line 2 def gets @gets end |
#hits ⇒ Object (readonly)
Returns the value of attribute hits.
2 3 4 |
# File 'lib/lrjew/lru.rb', line 2 def hits @hits end |
#misses ⇒ Object (readonly)
Returns the value of attribute misses.
2 3 4 |
# File 'lib/lrjew/lru.rb', line 2 def misses @misses end |
Instance Method Details
#include?(item) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lrjew/lru.rb', line 9 def include?(item) @gets += 1 if included = @stack.include?(item) @hits += 1 @stack.delete(item) @stack.push(item) else @misses += 1 node, shifted = @stack.push(item) @evictions += 1 if shifted end included end |
#inspect ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/lrjew/lru.rb', line 23 def inspect [ "gets", @gets, "hits", @hits, "misses", @misses, "evictions", @evictions, "rate", @hits.to_f / @gets ].join("\t") end |