|
Parsing Engine | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,Object>
danbikel.util.AbstractMapToPrimitive<K>
danbikel.util.HashMapPrimitive<K>
danbikel.util.HashMapDouble<K>
danbikel.parser.ProbabilityCache<K>
public class ProbabilityCache<K>
A cache for storing arbitrary objects with their probabilities. This class uses a hash map, and offers several replacement strategies.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class danbikel.util.HashMapDouble |
|---|
HashMapDouble.Entry<K> |
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
| Field Summary | |
|---|---|
static int |
BUCKET_LRU
Integer to indicate to delete the least-recently used entry in the same bucket as an entry being added after the size limit of this cache has been reached or exceeded. |
static int |
CLEAR_ALL
Integer to indicate to delete all of the elements every time the size limit of this cache has been reached or exceeded. |
static int |
HALF_LIFE
Integer to indicate to delete a random half of the elements every time the size limit of this cache has been reached or exceeded. |
static int |
RANDOM
Integer to indicate to delete a random element every time the size limit of this cache has been exceeded. |
| Fields inherited from class danbikel.util.HashMapPrimitive |
|---|
defaultInitialCapacity, defaultLoadFactor, hashCodeBitmask |
| Constructor Summary | |
|---|---|
ProbabilityCache(int maxCapacity)
Constructs a ProbabilityCache with the specified maximum
capacity and the default replacement strategy. |
|
ProbabilityCache(int maxCapacity,
int initialCapacity)
Constructs a ProbabilityCache with the specified maximum
capacity, the specified initial capacity and the default replacement
strategy. |
|
ProbabilityCache(int maxCapacity,
int initialCapacity,
float loadFactor)
Constructs a ProbabilityCache with the specified maximum
capacity, the specified initial capacity, the specified load factor and
the default replacement strategy. |
|
| Method Summary | |
|---|---|
boolean |
containsKey(Object key)
|
Object |
get(Object key)
Throws an UnsupportedOperationException, as the only
way to get values from this specialized cache is through the
getProb(Object) method. |
MapToPrimitive.Entry |
getProb(K key)
Returns the Double containing the probability of the specified
key, or null if the specified key is not in this
cache. |
double |
put(K key,
double probability)
Adds the specified key with the specified probability to this cache. |
Object |
put(Object key,
Object value)
Throws an UnsupportedOperationException, as the only
way to add keys to this specialized cache is through the
put(Object,double) method. |
double |
putAndRemove(K key,
double probability)
A synonym for putAndRemove(key, key.hashCode(), probability). |
double |
putAndRemove(K key,
int hash,
double probability)
Puts the specified key into the cache with the specified probability, removing the least-recently used key from this key's bucket if the bucket is not currently empty. |
void |
removeRandom()
Removes a random mapping from this map (optional operation). |
void |
setMaxCapacity(int maxCapacity)
Sets the maximum capacity for this cache. |
ProbabilityCache |
setStrategy(int strategy)
Sets the strategy for replacement when the size limit of this cache has been reached. |
| Methods inherited from class danbikel.util.HashMapDouble |
|---|
getNewEntry |
| Methods inherited from class danbikel.util.HashMapPrimitive |
|---|
add, add, add, add, add, add, addEntryMRU, entrySet, get, getCapacity, getEntry, getEntry, getEntryMRU, getEntryMRU, getLoadFactor, getOrCreateEntry, getStats, put, put, put, put, put, put, put, remove, removeLRU, removeLRU, removeRandom |
| Methods inherited from class danbikel.util.AbstractMapToPrimitive |
|---|
add, add, add, add, add, add, put, put, put, put, put, put, toString |
| Methods inherited from class java.util.AbstractMap |
|---|
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, values |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
clear, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, values |
| Field Detail |
|---|
public static final int RANDOM
setStrategy(int),
put(Object,double),
Constant Field Valuespublic static final int BUCKET_LRU
This strategy is the default.
setStrategy(int),
put(Object,double),
Constant Field Valuespublic static final int HALF_LIFE
setStrategy(int),
put(Object,double),
Constant Field Valuespublic static final int CLEAR_ALL
setStrategy(int),
put(Object,double),
Constant Field Values| Constructor Detail |
|---|
public ProbabilityCache(int maxCapacity)
ProbabilityCache with the specified maximum
capacity and the default replacement strategy.
maxCapacity - the maximum number of elements held by this cacheBUCKET_LRU,
setStrategy(int)
public ProbabilityCache(int maxCapacity,
int initialCapacity)
ProbabilityCache with the specified maximum
capacity, the specified initial capacity and the default replacement
strategy.
maxCapacity - the maximum number of elements held by this cacheinitialCapacity - the initial capacity of the underlying
hash mapBUCKET_LRU,
setStrategy(int)
public ProbabilityCache(int maxCapacity,
int initialCapacity,
float loadFactor)
ProbabilityCache with the specified maximum
capacity, the specified initial capacity, the specified load factor and
the default replacement strategy.
maxCapacity - the maximum number of elements held by this cacheinitialCapacity - the initial capacity of the underlying
hash maploadFactor - the load factor of the underlying
hash mapBUCKET_LRU,
setStrategy(int)| Method Detail |
|---|
public ProbabilityCache setStrategy(int strategy)
strategy - the integer id for the caching strategy to set for this
cache
RANDOM,
BUCKET_LRU,
HALF_LIFE,
CLEAR_ALLpublic void setMaxCapacity(int maxCapacity)
maxCapacity - the new maximum capacity of this cache
IllegalArgumentException - if the specified maximum capacity
is zero or negative
public Object put(Object key,
Object value)
UnsupportedOperationException, as the only
way to add keys to this specialized cache is through the
put(Object,double) method.
put in interface Map<K,Object>put in class HashMapPrimitive<K>key - ignoredvalue - ignored
put(Object,double)
public double put(K key,
double probability)
put in interface MapToPrimitive<K>put in class AbstractMapToPrimitive<K>key - the key to add to this cacheprobability - the probability of the specified key to be cached
key, or
null if there was no mapping for this keysetStrategy(int)
public final double putAndRemove(K key,
double probability)
putAndRemove(key, key.hashCode(), probability).
key - the key to be inserted into this cacheprobability - the probability of the key
Double.NaN
if the key did not exist in this map
public final double putAndRemove(K key,
int hash,
double probability)
key - the key to be inserted into this cachehash - the hash value of the specified keyprobability - the probability of the specified key
Double.NaN
if the key did not exist in this mappublic Object get(Object key)
UnsupportedOperationException, as the only
way to get values from this specialized cache is through the
getProb(Object) method.
get in interface Map<K,Object>get in class AbstractMap<K,Object>getProb(Object)public MapToPrimitive.Entry getProb(K key)
Double containing the probability of the specified
key, or null if the specified key is not in this
cache.
key - the key to look up in this cache
null
if it is not in this cachepublic boolean containsKey(Object key)
containsKey in interface Map<K,Object>containsKey in class HashMapPrimitive<K>public void removeRandom()
AbstractMapToPrimitive
removeRandom in interface MapToPrimitive<K>removeRandom in class AbstractMapToPrimitive<K>
|
Parsing Engine | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||