Class: DbmsBuffers::LRUBuffer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#sizeObject (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

Returns:

  • (Boolean)


26
27
28
# File 'lib/dbms_buffers/lru.rb', line 26

def contains?(value)
  @buffer.any? { |entry| value == entry.value }
end

#entriesObject



22
23
24
# File 'lib/dbms_buffers/lru.rb', line 22

def entries
  @buffer.clone
end

#usedObject



30
31
32
# File 'lib/dbms_buffers/lru.rb', line 30

def used
  @buffer.size
end