Package edu.berkeley.nlp.lm.collections
Class Indexer<E extends java.lang.Comparable<E>>
- java.lang.Object
-
- edu.berkeley.nlp.lm.collections.Indexer<E>
-
- All Implemented Interfaces:
java.io.Serializable
public class Indexer<E extends java.lang.Comparable<E>> extends java.lang.Object implements java.io.SerializableMaintains 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E elem)intgetIndex(E e)Return the index of the element If doesn't exist, add it.EgetObject(int index)java.lang.Iterable<E>getObjects()intindexOf(E o)Returns the index of the given object, or -1 if the object is not present in the indexer.voidlock()intsize()Returns the number of objects indexed.voidtrim()Save some space my compacting underlying maps and lists.
-
-
-
Constructor Detail
-
Indexer
public Indexer(boolean sync)
-
Indexer
public Indexer()
-
Indexer
public Indexer(java.util.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 java.lang.Iterable<E> getObjects()
-
-