cc.mallet.grmm.types
Class BidirectionalIntObjectMap

java.lang.Object
  extended by cc.mallet.grmm.types.BidirectionalIntObjectMap
All Implemented Interfaces:
java.io.Serializable

public class BidirectionalIntObjectMap
extends java.lang.Object
implements java.io.Serializable

A mapping between integers and objects where the mapping in each direction is efficient. Integers are assigned consecutively, starting at zero, as objects are added to map. Objects can not be deleted from the map and thus the integers are never reused.

This class is exactly like Alphabet in MALLET, except that it does not do the Serialization magic to ensure that two alphabets that are desrialized from the same file are ==. This avoids memory leaks, because MALLET Alphabets are retained in memory forever.

See Also:
Serialized Form

Constructor Summary
BidirectionalIntObjectMap()
           
BidirectionalIntObjectMap(BidirectionalIntObjectMap other)
           
BidirectionalIntObjectMap(int capacity)
           
 
Method Summary
 boolean contains(java.lang.Object entry)
           
 void dump()
           
 void dump(java.io.PrintStream out)
           
 void dump(java.io.PrintWriter out)
           
 boolean growthStopped()
           
 java.util.Iterator iterator()
           
 int lookupIndex(java.lang.Object entry)
           
 int lookupIndex(java.lang.Object entry, boolean addIfNotPresent)
          Return -1 if entry isn't present.
 int[] lookupIndices(java.lang.Object[] objects, boolean addIfNotPresent)
           
 java.lang.Object lookupObject(int index)
           
 java.lang.Object[] lookupObjects(int[] indices)
           
 java.lang.Object[] lookupObjects(int[] indices, java.lang.Object[] buf)
          Returns an array of the objects corresponding to
 int size()
           
 void startGrowth()
           
 void stopGrowth()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] in)
          Returns an array containing all the entries in the Alphabet.
 java.lang.String toString()
          Return String representation of all Alphabet entries, each separated by a newline.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BidirectionalIntObjectMap

public BidirectionalIntObjectMap(int capacity)

BidirectionalIntObjectMap

public BidirectionalIntObjectMap()

BidirectionalIntObjectMap

public BidirectionalIntObjectMap(BidirectionalIntObjectMap other)
Method Detail

lookupIndex

public int lookupIndex(java.lang.Object entry,
                       boolean addIfNotPresent)
Return -1 if entry isn't present.


lookupIndex

public int lookupIndex(java.lang.Object entry)

lookupObject

public java.lang.Object lookupObject(int index)

toArray

public java.lang.Object[] toArray()

toArray

public java.lang.Object[] toArray(java.lang.Object[] in)
Returns an array containing all the entries in the Alphabet. The runtime type of the returned array is the runtime type of in. If in is large enough to hold everything in the alphabet, then it it used. The returned array is such that for all entries obj, ret[lookupIndex(obj)] = obj .


iterator

public java.util.Iterator iterator()

lookupObjects

public java.lang.Object[] lookupObjects(int[] indices)

lookupObjects

public java.lang.Object[] lookupObjects(int[] indices,
                                        java.lang.Object[] buf)
Returns an array of the objects corresponding to

Parameters:
indices - An array of indices to look up
buf - An array to store the returned objects in.
Returns:
An array of values from this Alphabet. The runtime type of the array is the same as buf

lookupIndices

public int[] lookupIndices(java.lang.Object[] objects,
                           boolean addIfNotPresent)

contains

public boolean contains(java.lang.Object entry)

size

public int size()

stopGrowth

public void stopGrowth()

startGrowth

public void startGrowth()

growthStopped

public boolean growthStopped()

toString

public java.lang.String toString()
Return String representation of all Alphabet entries, each separated by a newline.

Overrides:
toString in class java.lang.Object

dump

public void dump()

dump

public void dump(java.io.PrintStream out)

dump

public void dump(java.io.PrintWriter out)