com.tagtraum.perf.datastructures
Class RandomCache

java.lang.Object
  |
  +--com.tagtraum.perf.datastructures.RandomCache
All Implemented Interfaces:
Cache

public class RandomCache
extends java.lang.Object
implements Cache

Cache with random replacement strategy. Which cached item is replaced depends highly on the hashcode of the cached item. The better the hashfunction, the better this cache.

Version:
$Id: $
Author:
Hendrik Schreiber

Constructor Summary
RandomCache(int initialCapacity)
          Creates a cache with an initial capacity that will be increased to the next power of 2
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Retrieves an object from this cache using the given key.
 int getCapacity()
          Returns the capacity of this cache.
 float getHitRatio()
          Returns a number between 0.0 and 1.0. 1.0 is a 100% hit rate.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Registers an object under a key in this cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomCache

public RandomCache(int initialCapacity)
Creates a cache with an initial capacity that will be increased to the next power of 2

Method Detail

getCapacity

public int getCapacity()
Description copied from interface: Cache
Returns the capacity of this cache. The exact meaning of this value is implementation dependent.

Specified by:
getCapacity in interface Cache

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: Cache
Retrieves an object from this cache using the given key.

Specified by:
get in interface Cache
Returns:
null if the object is not in this cache (anymore)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: Cache
Registers an object under a key in this cache.

Specified by:
put in interface Cache

getHitRatio

public float getHitRatio()
Returns a number between 0.0 and 1.0. 1.0 is a 100% hit rate.

Specified by:
getHitRatio in interface Cache


Copyright © 2002 Hendrik Schreiber
http://www.tagtraum.com/performance/
This software can be distributed under LGPL