Package org.glassfish.rmic.iiop
Class StaticStringsHash
- java.lang.Object
-
- org.glassfish.rmic.iiop.StaticStringsHash
-
public class StaticStringsHash extends java.lang.Object
StaticStringsHash takes an array of constant strings and uses several different hash methods to try to find the 'best' one for that set. The set of methods is currently fixed, but with a little work could be made extensible thru subclassing.The current set of methods is:
- length() - works well when all strings are different length.
- charAt(n) - works well when one offset into all strings is different.
- hashCode() - works well with larger arrays.
getKey(String)
method can be used to use the selected hash method to produce a key. Themethod
string will contain "length()", "charAt(n)", or "hashCode()", and is intended for use by code generators.The
keys
array will contain the full set of unique keys.The
buckets
array will contain a set of arrays, one for each key in thekeys
, wherebuckets[x][y]
is an index into thestrings
array.
-
-
Field Summary
Fields Modifier and Type Field Description private int
bucketCount
int[][]
buckets
Buckets for each key, where buckets[x][y] is an index into the strings[] array.private int[]
bucketSizes
private static int
CHAR_AT
private static int
CHAR_AT_MAX_CHARS
private static int
CHAR_AT_MAX_LINES
private int
charAt
private static int
HASH_CODE
private int
keyKind
int[]
keys
Unique hash keysprivate int
length
private static int
LENGTH
private int
maxDepth
java.lang.String
method
The method to invoke on String to produce the hash keyprivate int
minStringLength
java.lang.String[]
strings
The set of strings upon which the hash info is createdprivate int[]
tempKeys
-
Constructor Summary
Constructors Constructor Description StaticStringsHash(java.lang.String[] strings)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addKey(int key)
private int
findUnusedKey()
int
getKey(java.lang.String str)
Get a key for the given string using the selected hash method.private int
getKeys(int methodKind)
static void
main(java.lang.String[] args)
Print an optimized 'contains' method for the argument stringsprivate void
resetKeys(int keyKind)
private void
setMinStringLength()
-
-
-
Field Detail
-
strings
public java.lang.String[] strings
The set of strings upon which the hash info is created
-
keys
public int[] keys
Unique hash keys
-
buckets
public int[][] buckets
Buckets for each key, where buckets[x][y] is an index into the strings[] array.
-
method
public java.lang.String method
The method to invoke on String to produce the hash key
-
length
private int length
-
tempKeys
private int[] tempKeys
-
bucketSizes
private int[] bucketSizes
-
bucketCount
private int bucketCount
-
maxDepth
private int maxDepth
-
minStringLength
private int minStringLength
-
keyKind
private int keyKind
-
charAt
private int charAt
-
LENGTH
private static final int LENGTH
- See Also:
- Constant Field Values
-
CHAR_AT
private static final int CHAR_AT
- See Also:
- Constant Field Values
-
HASH_CODE
private static final int HASH_CODE
- See Also:
- Constant Field Values
-
CHAR_AT_MAX_LINES
private static final int CHAR_AT_MAX_LINES
- See Also:
- Constant Field Values
-
CHAR_AT_MAX_CHARS
private static final int CHAR_AT_MAX_CHARS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getKey
public int getKey(java.lang.String str)
Get a key for the given string using the selected hash method.- Parameters:
str
- the string to return a key for.- Returns:
- the key.
-
main
public static void main(java.lang.String[] args)
Print an optimized 'contains' method for the argument strings
-
resetKeys
private void resetKeys(int keyKind)
-
setMinStringLength
private void setMinStringLength()
-
findUnusedKey
private int findUnusedKey()
-
getKeys
private int getKeys(int methodKind)
-
addKey
private void addKey(int key)
-
-