Package org.jibx.util
Class StringIntSizedMap
- java.lang.Object
-
- org.jibx.util.StringIntSizedMap
-
public class StringIntSizedMap extends Object
Fixed size hash map usingStringvalues as keys mapped to primitiveintvalues.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_FILL_FRACTIONDefault fill fraction for sizing of tables.static intDEFAULT_NOT_FOUNDDefault value returned when key not found in table.protected intm_arraySizeSize of array used for keys.protected intm_hitOffsetOffset added (modulo table size) to slot number on collision.protected String[]m_keyTableArray of key table slots.protected intm_notFoundValueValue returned when key not found in table.protected int[]m_valueTableArray of value table slots.
-
Constructor Summary
Constructors Constructor Description StringIntSizedMap(int count)Constructor with only value count specified.StringIntSizedMap(int count, double fill, int miss)Constructor with full specification.StringIntSizedMap(int count, int miss)Constructor with value count and miss value specified.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(String key, int value)Add an entry to the table.voidclear()Set the table to the empty state.booleancontainsKey(String key)Check if an entry is present in the table.intget(String key)Find an entry in the table.
-
-
-
Field Detail
-
DEFAULT_FILL_FRACTION
public static final double DEFAULT_FILL_FRACTION
Default fill fraction for sizing of tables.- See Also:
- Constant Field Values
-
DEFAULT_NOT_FOUND
public static final int DEFAULT_NOT_FOUND
Default value returned when key not found in table.- See Also:
- Constant Field Values
-
m_arraySize
protected final int m_arraySize
Size of array used for keys.
-
m_keyTable
protected final String[] m_keyTable
Array of key table slots.
-
m_valueTable
protected final int[] m_valueTable
Array of value table slots.
-
m_notFoundValue
protected final int m_notFoundValue
Value returned when key not found in table.
-
m_hitOffset
protected final int m_hitOffset
Offset added (modulo table size) to slot number on collision.
-
-
Constructor Detail
-
StringIntSizedMap
public StringIntSizedMap(int count, double fill, int miss)Constructor with full specification.- Parameters:
count- number of values to assume in sizing of tablefill- fraction fill for table (maximum of0.7, to prevent excessive collisions)miss- value returned when key not found in table
-
StringIntSizedMap
public StringIntSizedMap(int count, int miss)Constructor with value count and miss value specified. Uses default fill fraction.- Parameters:
count- number of values to assume in initial sizing of tablemiss- value returned when key not found in table
-
StringIntSizedMap
public StringIntSizedMap(int count)
Constructor with only value count specified. Uses default fill fraction and miss value.- Parameters:
count- number of values to assume in initial sizing of table
-
-
Method Detail
-
add
public int add(String key, int value)
Add an entry to the table. If the key is already present in the table, this replaces the existing value associated with the key.- Parameters:
key- key to be added to table (non-null)value- associated value for key- Returns:
- value previously associated with key, or reserved not found value if key not previously present in table
-
containsKey
public final boolean containsKey(String key)
Check if an entry is present in the table. This method is supplied to support the use of values matching the reserved not found value.- Parameters:
key- key for entry to be found- Returns:
trueif key found in table,falseif not
-
get
public final int get(String key)
Find an entry in the table.- Parameters:
key- key for entry to be returned- Returns:
- value for key, or reserved not found value if key not found
-
clear
public void clear()
Set the table to the empty state.
-
-