|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gov.nist.nlpir.irf.util.HashingCache
This cache associates a value to a key, a bit like a hashtable does.
When a couple is stored, the value may then be retrieved using the key.
But this operation may not succeed in case a couple has been stored with
a key having the same hashcode as the first one (collision case). This
cache allows values of two different status
to be stored: those which are considered dirty, and those which
aren't. This way, the client may store a persistent object in the cache,
even if this one needs to be written. If the cache destroys this object
because of a collision, it will return it as the return value of the
destroying method so that the client can then do what's necessary. In
the case an object is destroyed but the key associated to the new value
is the same as the one for the disappearing object (regarding
equals()
, the method returns nothing, as this is considered an
update "in memory" that doesn't need to be reported to the disk. This
feature may be deferred to the client in a later release.
Field Summary | |
private boolean[] |
dirty
For every couple (keys[i], values[i]), must it be returned when it's removed from the cache because of a collision? |
private java.lang.Object[] |
keys
Array keeping track of the stored keys. |
private int |
size
Current size of cache, ie of each of its arrays. |
private java.lang.Object[] |
values
Array containing the values. |
Constructor Summary | |
HashingCache(int maxEntries)
Builds a new cache with the given size. |
Method Summary | |
java.lang.Object[] |
add(java.lang.Object key,
java.lang.Object value)
Adds an object (key-value pair) to the queue. |
java.lang.Object |
find(java.lang.Object key)
Find the most recently added value with the given key |
java.lang.Object[] |
getDirtyValues()
|
private java.lang.Object[] |
internPut(int range,
java.lang.Object key,
java.lang.Object value,
boolean willBeDirty)
Common part to put() and add() , this method
seeks the right place in the two tables. |
void |
present()
Present the contents of the cache, in the form: d key1 <=> value1 for couples that are marked dirty,key2 <=> value2 for the others. |
java.lang.Object[] |
put(java.lang.Object key,
java.lang.Object value)
Same as add with no dirty bit. |
java.lang.Object[] |
setMaxEntries(int newMaxEntries)
This method allows to dynamically change the size of the cache. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private java.lang.Object[] keys
private java.lang.Object[] values
private boolean[] dirty
private int size
Constructor Detail |
public HashingCache(int maxEntries)
Method Detail |
public java.lang.Object[] setMaxEntries(int newMaxEntries)
getDirtyValues()
.getDirtyValues()
public final java.lang.Object[] add(java.lang.Object key, java.lang.Object value)
key
- of object to be addedvalue
- of object to be addedadd()
, and its
key is different from the new one given.public final java.lang.Object[] put(java.lang.Object key, java.lang.Object value)
add()
, and its
key is different from the new one given.private final java.lang.Object[] internPut(int range, java.lang.Object key, java.lang.Object value, boolean willBeDirty)
put()
and add()
, this method
seeks the right place in the two tables. If an object is already
present, AND it is marked dirty (it was introduced here with
add()
and not put()
, AND THE KEY IS
DIFFERENT OF THE NEW ONE, then it is returned by this method: the
client should save the value if he wants to keep track of it.public final java.lang.Object find(java.lang.Object key)
key
- search key of object soughtpublic java.lang.Object[] getDirtyValues()
public void present()
d key1 <=> value1
for couples that are marked dirty,key2 <=> value2
for the others.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |