edu.stanford.nlp.util
Class OAIndex<K>

java.lang.Object
  extended by edu.stanford.nlp.util.OAIndex<K>
All Implemented Interfaces:
IndexInterface<K>, Serializable

public class OAIndex<K>
extends Object
implements IndexInterface<K>

Open addressing backed index for arbitrary object types. Includes support for both traditional matching of keys values based on the equals() method as well as 'identity' matching where by keys are only compared with '=='. WARNING: This is currently experimental code. It exists since in theory open addressing hashing should be more efficient for hashing int values than bucket-chain hashing, which is used to back java.util.HashMap. To do list: - in fear of user stupidity, i think HashMap re-hashes the hash values returned by objects, should we? - finalize interface - rigorous benchmarks - unit tests

Author:
Daniel Cer
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface edu.stanford.nlp.util.IndexInterface
INVALID_ENTRY
 
Constructor Summary
OAIndex()
           
OAIndex(boolean identityHash)
           
 
Method Summary
 int boundOnMaxIndex()
           
 boolean contains(Object key)
           
 K get(int idx)
          Gets the object whose index is the integer argument.
 int indexOf(K key)
          Returns the integer index of the Object in the Index or -1 if the Object is not already in the Index.
 int indexOf(K key, boolean add)
          Takes an Object and returns the integer index of the Object, perhaps adding it to the index first.
 Set<K> keySet()
           
static void main(String[] args)
           
 int maxIndex()
           
 int size()
          Returns the number of indexed objects.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OAIndex

public OAIndex()

OAIndex

public OAIndex(boolean identityHash)
Method Detail

keySet

public Set<K> keySet()

maxIndex

public int maxIndex()

boundOnMaxIndex

public int boundOnMaxIndex()

get

public K get(int idx)
Description copied from interface: IndexInterface
Gets the object whose index is the integer argument.

Specified by:
get in interface IndexInterface<K>
Parameters:
idx - the integer index to be queried for the corresponding argument
Returns:
the object whose index is the integer argument.

toString

public String toString()
Overrides:
toString in class Object

indexOf

public int indexOf(K key)
Description copied from interface: IndexInterface
Returns the integer index of the Object in the Index or -1 if the Object is not already in the Index.

Specified by:
indexOf in interface IndexInterface<K>
Parameters:
key - the Object whose index is desired.
Returns:
the index of the Object argument. Returns -1 if the object is not in the index.

contains

public boolean contains(Object key)
Specified by:
contains in interface IndexInterface<K>

indexOf

public int indexOf(K key,
                   boolean add)
Description copied from interface: IndexInterface
Takes an Object and returns the integer index of the Object, perhaps adding it to the index first. Returns -1 if the Object is not in the Index. (Note: indexOf(x, true) is the direct replacement for the number(x) method in the old Numberer class.)

Specified by:
indexOf in interface IndexInterface<K>
Parameters:
key - the Object whose index is desired.
add - Whether it is okay to add new items to the index
Returns:
the index of the Object argument. Returns -1 if the object is not in the index.

main

public static void main(String[] args)
                 throws IOException
Throws:
IOException

size

public int size()
Description copied from interface: IndexInterface
Returns the number of indexed objects.

Specified by:
size in interface IndexInterface<K>
Returns:
the number of indexed objects.


Stanford NLP Group