Class: DbmsBuffers::LRUBuffer
- Inherits:
-
Object
- Object
- DbmsBuffers::LRUBuffer
- Defined in:
- lib/dbms_buffers/lru.rb
Overview
The LRUBuffer applies least recently used as eviction strategy. For this, it saves the time of the last access with each buffered value.
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #access(value) ⇒ Object
- #contains?(value) ⇒ Boolean
- #entries ⇒ Object
-
#initialize(size) ⇒ LRUBuffer
constructor
A new instance of LRUBuffer.
- #used ⇒ Object
Constructor Details
#initialize(size) ⇒ LRUBuffer
Returns a new instance of LRUBuffer.
11 12 13 14 15 |
# File 'lib/dbms_buffers/lru.rb', line 11 def initialize(size) @size = size @buffer = [] @time = 0 end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/dbms_buffers/lru.rb', line 9 def size @size end |
Instance Method Details
#access(value) ⇒ Object
17 18 19 20 |
# File 'lib/dbms_buffers/lru.rb', line 17 def access(value) @time += 1 try_touch(value) || try_insert_new(value) || try_replace(value) end |
#contains?(value) ⇒ Boolean
26 27 28 |
# File 'lib/dbms_buffers/lru.rb', line 26 def contains?(value) @buffer.any? { |entry| value == entry.value } end |
#entries ⇒ Object
22 23 24 |
# File 'lib/dbms_buffers/lru.rb', line 22 def entries @buffer.clone end |
#used ⇒ Object
30 31 32 |
# File 'lib/dbms_buffers/lru.rb', line 30 def used @buffer.size end |