edu.berkeley.nlp.lm.collections
Class Indexer<E extends Comparable<E>>

java.lang.Object
  extended by edu.berkeley.nlp.lm.collections.Indexer<E>
All Implemented Interfaces:
Serializable

public class Indexer<E extends Comparable<E>>
extends Object
implements Serializable

Maintains a two-way map between a set of objects and contiguous integers from 0 to the number of objects.

Author:
Dan Klein, Adam Pauls
See Also:
Serialized Form

Field Summary
protected  TIntMap<E> indexes
           
protected  boolean locked
           
protected  ArrayList<E> objects
           
 
Constructor Summary
Indexer()
           
Indexer(boolean sync)
           
Indexer(Collection<? extends E> c)
           
 
Method Summary
 boolean add(E elem)
           
 int getIndex(E e)
          Return the index of the element If doesn't exist, add it.
 E getObject(int index)
           
 Iterable<E> getObjects()
           
 int indexOf(E o)
          Returns the index of the given object, or -1 if the object is not present in the indexer.
 void lock()
           
 int size()
          Returns the number of objects indexed.
 void trim()
          Save some space my compacting underlying maps and lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objects

protected ArrayList<E extends Comparable<E>> objects

indexes

protected TIntMap<E extends Comparable<E>> indexes

locked

protected boolean locked
Constructor Detail

Indexer

public Indexer(boolean sync)

Indexer

public Indexer()

Indexer

public Indexer(Collection<? extends E> c)
Method Detail

lock

public void lock()

getObject

public E getObject(int index)

add

public boolean add(E elem)

size

public int size()
Returns the number of objects indexed.


indexOf

public int indexOf(E o)
Returns the index of the given object, or -1 if the object is not present in the indexer.

Parameters:
o -
Returns:

getIndex

public int getIndex(E e)
Return the index of the element If doesn't exist, add it.


trim

public void trim()
Save some space my compacting underlying maps and lists.


getObjects

public Iterable<E> getObjects()