org.egothor.cache.lruk
Class LruKNode<K>

java.lang.Object
  extended by org.egothor.cache.AbstractNode<K,LruKNode<K>>
      extended by org.egothor.cache.lruk.LruKNode<K>
Type Parameters:
K - type of the key
All Implemented Interfaces:
java.lang.Comparable<LruKNode<K>>

public class LruKNode<K>
extends AbstractNode<K,LruKNode<K>>

Represents a node that can be used as a key for TreeMap. Uses backward-K-distance to compare nodes.


Field Summary
 
Fields inherited from class org.egothor.cache.AbstractNode
key
 
Constructor Summary
LruKNode(K key, int numberOfIds)
          Constructor for the LruKNode object.
 
Method Summary
 int compareTo(LruKNode<K> o)
          Compares this node with the specified node.
 long distance()
          Computes the backward-K-distance of this node.
 long id(int number)
          Returns the number-th last access time of the node.
 long lastId()
          Returns the oldest stored access time.
 int numberOfIds()
          Returns number of last accesses stored by the node.
 long update()
          Updates last access time of this node.
 
Methods inherited from class org.egothor.cache.AbstractNode
equals, getKey, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LruKNode

public LruKNode(K key,
                int numberOfIds)
Constructor for the LruKNode object.

Parameters:
key - key associated with the node
numberOfIds - number of last references the node should store
Method Detail

id

public long id(int number)
Returns the number-th last access time of the node.

Parameters:
number - id of the last access time
Returns:
K-th last access time of the node

lastId

public long lastId()
Returns the oldest stored access time.

Returns:
the oldest sotred access time

distance

public long distance()
Computes the backward-K-distance of this node.

Returns:
backward-K-distance of this node

update

public long update()
Updates last access time of this node.

Returns:
last access time

numberOfIds

public int numberOfIds()
Returns number of last accesses stored by the node.

Returns:
number of last accesses stored by the node

compareTo

public int compareTo(LruKNode<K> o)
Compares this node with the specified node. Uses backward-K-distance (more distant means greater) in that order to compare the nodes.

Returns:
-1 if this node is smaller than the specified node, 1 if it is greater and 0 if the are equal