|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gov.nist.nlpir.irf.index.braf.HashBlock
This class is a classic implementation of a hash table, except that it
adds an important feature usual hashtables don't provide: as storing in
the table only uses hashCode()
and equals()
,
and that these methods can be refined in each class to have a specific
behavior, it is actually possible to access an object in the hashtable
with different keys, provided these keys have the same hashCode and
return true
when they are compared with equals()
. This is used in PersistentDualKeyContainer and in IdxIntern.
Thus, there is a need for a method getActualKey that returns the object
actually stored as the key when you access the hashblock with a false
key -a key not actually stored.
It also contains a method that reveals the length of the base table
array.
Field Summary | |
private int |
count
The total number of entries in the hashblock. |
private boolean |
dirty
Dirty bit. |
private float |
loadFactor
The load factor for the hashblock. |
(package private) static java.lang.Class |
proxyFeatureListClass
This class object will be used for materialization of lists stored in the block. |
private int |
rehashThreshold
Rehashes the hashblock when count exceeds this threshold. |
protected HashBlockEntry[] |
table
The hash table data. |
Constructor Summary | |
|
HashBlock()
Constructs a new, empty hashtable with a default capacity and load factor. |
private |
HashBlock(HashBlockEntry[] table,
int count,
int rehashThreshold,
float loadFactor)
private constructor only used by the persistence mechanism, when coming back from disk. |
|
HashBlock(int initialCapacity)
Constructs a new, empty hashtable with the specified initial capacity and default load factor. |
|
HashBlock(int initialCapacity,
float loadFactor)
Constructs a new, empty hashblock with the specified initial capacity and the specified load factor. |
Method Summary | |
void |
clear()
Clears this hashblock so that it contains no keys. |
java.lang.Object |
clone()
Creates a clone of this hashblock. |
boolean |
contains(java.lang.Object value)
Tests if some key maps into the specified value in this HashBlock. |
boolean |
containsKey(java.lang.Object key)
Tests if the specified object is a key in this hashtable. |
java.util.Enumeration |
elements()
Returns an enumeration of the values in this hashtable. |
void |
finalize()
As this HashBlock contains Proxies and has counted the references it has to them, it needs to remove those references before being finalized, and this is done in this method. |
java.lang.Object |
get(java.lang.Object key,
int hash)
Returns the value to which the specified key is mapped in this hashtable. |
java.lang.Object |
getActualKey(java.lang.Object key,
int hash)
Returns the object actually stored as a key for this possible key. |
boolean |
isDirty()
|
boolean |
isEmpty()
Tests if this hashtable maps no keys to values. |
java.util.Enumeration |
keys()
Returns an enumeration of the keys in this hashtable. |
int |
length()
|
java.lang.Object |
put(java.lang.Object key,
int hash,
java.lang.Object value)
Maps the specified key to the specified
value in this hashtable. |
static HashBlock |
readFrom(BufferedRandomAccessFile in)
Reads a HashBlock back from the file it was previously written with writeTo() . |
protected void |
rehash()
Rehashes the contents of the HashBlock into a HashBlock with a larger capacity. |
java.lang.Object |
remove(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable. |
int |
size()
|
java.lang.String |
toString()
Returns a string representation of the hashblock. |
void |
writeTo(BufferedRandomAccessFile out)
Writes this block to the file given in parameter. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected transient HashBlockEntry[] table
private transient int count
private int rehashThreshold
private float loadFactor
static java.lang.Class proxyFeatureListClass
private boolean dirty
Constructor Detail |
public HashBlock(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity of the hashtable.loadFactor
- a number between 0.0 and 1.0.public HashBlock(int initialCapacity)
initialCapacity
- the initial capacity of the hashtable.public HashBlock()
private HashBlock(HashBlockEntry[] table, int count, int rehashThreshold, float loadFactor)
Method Detail |
public final int size()
public final int length()
public final boolean isEmpty()
true
if this hashtable maps no keys to values;
false
otherwise.public final java.util.Enumeration keys()
Enumeration
,
elements()
public final java.util.Enumeration elements()
Enumeration
,
keys()
public boolean contains(java.lang.Object value)
containsKey()
method.value
- a value to search for.true
if some key maps to the
value
argument in this hashtable;
false
otherwise.null
.containsKey(java.lang.Object)
public boolean containsKey(java.lang.Object key)
key
- possible key.true
if the specified object is a key in this
hashtable; false
otherwise.contains(java.lang.Object)
public java.lang.Object get(java.lang.Object key, int hash)
key
- a key in the hashtable.null
if the key is not mapped to any value in
this hashtable.put(java.lang.Object, int,
java.lang.Object)
protected void rehash()
public java.lang.Object put(java.lang.Object key, int hash, java.lang.Object value)
key
to the specified
value
in this hashtable. Neither the key nor the
value can be null
.
The value can be retrieved by calling the get
method
with a key that is equal to the original key. Equal here means that
it has the same hash code and returns true to the method equals().
key
- the hashblock key. Must either be an IoAddrIntern
or a DeIntern.hash
- hashCode of the key. As it has already been computed,
it saves a few CPU cycles.value
- the value. During put, it should be ProxyFeatureList
even if its Oid is actually enough.null
if it did not have one.null
.Object.equals(java.lang.Object)
,
get(java.lang.Object, int)
public java.lang.Object remove(java.lang.Object key)
key
- the key that needs to be removed.null
if the key did not have a mapping.public void clear()
public java.lang.Object clone()
public java.lang.String toString()
public java.lang.Object getActualKey(java.lang.Object key, int hash)
key
- possible key.true
if the specified object is a key in this
hashtable; false
otherwise.contains(java.lang.Object)
public boolean isDirty()
public void writeTo(BufferedRandomAccessFile out) throws java.io.IOException
public static HashBlock readFrom(BufferedRandomAccessFile in) throws java.io.IOException
writeTo()
.public void finalize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |