org.jscience.linguistics.search
Class CharIntMap

java.lang.Object
  extended by org.jscience.linguistics.search.CharIntMap
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable

public class CharIntMap
extends java.lang.Object
implements java.io.Externalizable, java.lang.Cloneable

The CharIntMap is a collection to save char to int mappings in. The CharIntMap is destined to provide fast access to skip tables while being both Unicode-safe and more RAM-effective than a naive int array.

The CharIntMap is initialized by specifying the extent between the lowest and the highest occuring character and the lowest occuring character. Only an array of size highest - lowest + 1 is constructed.

There's usually no need to construct a CharIntMap yourself, it is done automatically for you in the pre-processing methods.

See Also:
Serialized Form

Constructor Summary
CharIntMap()
          Constructor for CharIntMap.
CharIntMap(int extent, char lowest)
          Constructor for CharIntMap.
CharIntMap(int extent, char lowest, int defaultValue)
          Constructor for CharIntMap.
 
Method Summary
 java.lang.Object clone()
          Returns a deep clone of this CharIntMap.
 boolean equals(java.lang.Object obj)
          Returns if this Object is equal to another Object.
 int get(char c)
          Returns the stored value for the given char.
 int getExtent()
          Returns the extent of the actual char array.
 char getHighest()
          Returns the highest char that mappings can be saved for.
 char getLowest()
          Returns the lowest char that mappings can be saved for.
 int hashCode()
          Returns the hashCode of this Object.
 void readExternal(java.io.ObjectInput in)
           
 void set(char c, int val)
          Sets the stored value for the given char.
 java.lang.String toString()
          Returns a String representation of this Object.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharIntMap

public CharIntMap()
Constructor for CharIntMap. Required for Serialization.


CharIntMap

public CharIntMap(int extent,
                  char lowest)
Constructor for CharIntMap.

Parameters:
extent - the extent of the text
lowest - the lowest occuring character

CharIntMap

public CharIntMap(int extent,
                  char lowest,
                  int defaultValue)
Constructor for CharIntMap.

Parameters:
extent - the extent of the text
lowest - the lowest occuring character
defaultValue - a default value to initialize the underlying int array with
Method Detail

clone

public java.lang.Object clone()
Returns a deep clone of this CharIntMap.

Overrides:
clone in class java.lang.Object
Returns:
an CharIntMap containing the same mappings

get

public int get(char c)
Returns the stored value for the given char.

Parameters:
c - the char
Returns:
the stored value

set

public void set(char c,
                int val)
Sets the stored value for the given char.

Parameters:
c - the char
val - the new value

getExtent

public int getExtent()
Returns the extent of the actual char array.

Returns:
the extent

getLowest

public char getLowest()
Returns the lowest char that mappings can be saved for.

Returns:
a char

getHighest

public char getHighest()
Returns the highest char that mappings can be saved for.

Returns:
char

equals

public boolean equals(java.lang.Object obj)
Returns if this Object is equal to another Object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the other Object
Returns:
if this Object is equal
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Returns the hashCode of this Object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Returns a String representation of this Object.

Overrides:
toString in class java.lang.Object
Returns:
a String
See Also:
Object.toString()

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException
See Also:
Externalizable.writeExternal(java.io.ObjectOutput)

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Externalizable.readExternal(java.io.ObjectInput)