Class: Hashery::LRUHash::Node

Inherits:
Struct
  • Object
show all
Defined in:
lib/hashery/lru_hash.rb

Overview

A single node in the doubly linked LRU list of nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (private)

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



337
338
339
# File 'lib/hashery/lru_hash.rb', line 337

def key
  @key
end

#predObject (private)

Returns the value of attribute pred

Returns:

  • (Object)

    the current value of pred



337
338
339
# File 'lib/hashery/lru_hash.rb', line 337

def pred
  @pred
end

#succObject (private)

Returns the value of attribute succ

Returns:

  • (Object)

    the current value of succ



337
338
339
# File 'lib/hashery/lru_hash.rb', line 337

def succ
  @succ
end

#valueObject (private)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



337
338
339
# File 'lib/hashery/lru_hash.rb', line 337

def value
  @value
end

Instance Method Details

#insert_after(node) ⇒ Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/hashery/lru_hash.rb', line 345

def insert_after(node)
  raise 'Cannot insert after self' if equal? node
  return self if node.succ.equal? self

  unlink

  self.succ = node.succ
  self.pred = node

  node.succ.pred = self if node.succ
  node.succ = self

  self
end


338
339
340
341
342
343
# File 'lib/hashery/lru_hash.rb', line 338

def unlink
  pred.succ = succ if pred
  succ.pred = pred if succ
  self.succ = self.pred = nil
  self
end