Class StaticStringsHash

java.lang.Object
org.glassfish.rmic.iiop.StaticStringsHash

public class StaticStringsHash extends 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:

  1. length() - works well when all strings are different length.
  2. charAt(n) - works well when one offset into all strings is different.
  3. hashCode() - works well with larger arrays.
After constructing an instance over the set of strings, the getKey(String) method can be used to use the selected hash method to produce a key. The method 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 the keys, where buckets[x][y] is an index into the strings array.

Author:
Bryan Atsatt
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int[][]
    Buckets for each key, where buckets[x][y] is an index into the strings[] array.
    int[]
    Unique hash keys
    The method to invoke on String to produce the hash key
    The set of strings upon which the hash info is created
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get a key for the given string using the selected hash method.
    static void
    main(String[] args)
    Print an optimized 'contains' method for the argument strings

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • strings

      public 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 String method
      The method to invoke on String to produce the hash key
  • Constructor Details

    • StaticStringsHash

      public StaticStringsHash(String[] strings)
      Constructor
      Parameters:
      strings - the set of strings upon which to find an optimal hash method. Must not contain duplicates.
  • Method Details

    • getKey

      public int getKey(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(String[] args)
      Print an optimized 'contains' method for the argument strings