ostore.util
Class LruMap

java.lang.Object
  |
  +--ostore.util.LruMap

public class LruMap
extends Object

LruMap is a Map with an attached LRU ordering.

Version:
$Id: LruMap.java,v 1.1 2004/03/23 08:21:52 hweather Exp $
Author:
Sean C. Rhea

Constructor Summary
LruMap(int cap, Map backing_map)
          Constructor: Creates a new LruMap.
 
Method Summary
 Map backing_map()
          backing_up
 int capacity()
          capacity returns max capacity for the LruMap.
 boolean containsKey(Object key)
          Specified by java.util.Map
 Object get(Object key)
          Specified by java.util.Map
 boolean isEmpty()
          Specified by java.util.Map
 boolean isFull()
          isFull returns true if LruMap is at full capacity; otherwise, false.
 Iterator iterator()
          iterator returns an Iterator that walks through the set of items in the Map, starting with the most recently added to the least recently used.
 Set keySet()
          Specified by java.util.Map
 Object lastKey()
           
 Pair put(Object key, Object value)
          If the LruMap isFull (i.e. at full capacity(), than put returns a Pair of victim key/value; otherwise, put returns null.
 Object remove(Object key)
          Specified by java.util.Map
 int size()
          Specified by java.util.Map
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LruMap

public LruMap(int cap,
              Map backing_map)
Constructor: Creates a new LruMap.

Parameters:
cap - Maximum capacity for Map.
backing_map - Actual Map used to store entries.
Method Detail

capacity

public int capacity()
capacity returns max capacity for the LruMap.

Returns:
max capacity for LruMap.

size

public int size()
Specified by java.util.Map


keySet

public Set keySet()
Specified by java.util.Map


containsKey

public boolean containsKey(Object key)
Specified by java.util.Map


isEmpty

public boolean isEmpty()
Specified by java.util.Map


isFull

public boolean isFull()
isFull returns true if LruMap is at full capacity; otherwise, false.

Returns:
true if LruMap is at full capacity; otherwise, false.

backing_map

public Map backing_map()
backing_up

Returns:
The actual Map used to store entries.

iterator

public Iterator iterator()
iterator returns an Iterator that walks through the set of items in the Map, starting with the most recently added to the least recently used.

Returns:
The Iterator with an attached LRU ordering.

put

public Pair put(Object key,
                Object value)
If the LruMap isFull (i.e. at full capacity(), than put returns a Pair of victim key/value; otherwise, put returns null. In either case the new key/value pair is placed in the LruMap

Parameters:
key - Key to place in LruMap.
value - Value to place in LruMap.
Returns:
Pair of victim key/ value if LruMap was full; otherwise, return null.

get

public Object get(Object key)
Specified by java.util.Map


lastKey

public Object lastKey()

remove

public Object remove(Object key)
Specified by java.util.Map