Class: DbmsBuffers::GClockBuffer
- Inherits:
-
Object
- Object
- DbmsBuffers::GClockBuffer
- Defined in:
- lib/dbms_buffers/gclock.rb
Overview
The generalized clock buffer arranges entries in a logical clock and a single hand. When the buffer is full and a not-yet-inserted entry needs space, the hand goes clockwise until it finds an entry with clock_value = 0. The found entry is evicted, removed from the buffer, and the new values is inserted with clock_value 1. All entries the hand passes where clock_value = 1, this value is decremented, but they are not replaced yet (they have a second chance). When an element is accessed, its value is incremented by 1.
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #access(value) ⇒ Object
- #clock_value_of(value) ⇒ Object
- #contains?(value) ⇒ Boolean
- #entries ⇒ Object
-
#initialize(size) ⇒ GClockBuffer
constructor
A new instance of GClockBuffer.
- #used ⇒ Object
Constructor Details
#initialize(size) ⇒ GClockBuffer
Returns a new instance of GClockBuffer.
17 18 19 20 21 |
# File 'lib/dbms_buffers/gclock.rb', line 17 def initialize(size) @size = size @buffer = [] @pointer = 0 end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
15 16 17 |
# File 'lib/dbms_buffers/gclock.rb', line 15 def pointer @pointer end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
15 16 17 |
# File 'lib/dbms_buffers/gclock.rb', line 15 def size @size end |
Instance Method Details
#access(value) ⇒ Object
23 24 25 |
# File 'lib/dbms_buffers/gclock.rb', line 23 def access(value) try_touch(value) || try_insert_new(value) || try_replace(value) end |
#clock_value_of(value) ⇒ Object
27 28 29 |
# File 'lib/dbms_buffers/gclock.rb', line 27 def clock_value_of(value) @buffer[index(value)].clock_value end |
#contains?(value) ⇒ Boolean
35 36 37 |
# File 'lib/dbms_buffers/gclock.rb', line 35 def contains?(value) @buffer.any? { |entry| value == entry.value } end |
#entries ⇒ Object
31 32 33 |
# File 'lib/dbms_buffers/gclock.rb', line 31 def entries @buffer.clone end |
#used ⇒ Object
39 40 41 |
# File 'lib/dbms_buffers/gclock.rb', line 39 def used @buffer.size end |