## org.apache.xerces.utils
Class StringHasher

    java.lang.Object
      |
      +--org.apache.xerces.utils.StringHasher

public final class StringHasher
extends java.lang.Object

Algorithm used to hash char arrays (strings). This class was created after it was discovered that parsing some documents was unexpectedly slow due to many different strings hashing to the same 32-bit value using the java.lang.String hash algorithm. The trick seems to be the shift of the top eight bits of the hashcode back down to the bottom to keep them from being rolled out.

Version:

Constructor Summary
`StringHasher()`

Method Summary
`static int` `finishHash(int hashcode)` finish hashing a partically completed character hashcode
`static int` `hashChar(int hashcode, int ch)` generate partially completed character hashcode.
`static int` `hashChars(char[] chars, int offset, int length)` generate a hashcode for a character array
`static int` `hashString(java.lang.String str, int strLength)` generate a hashcode for a String

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StringHasher

    public StringHasher()

Method Detail

### hashString

    public static int hashString(java.lang.String str,
                                 int strLength)

  generate a hashcode for a String
  Parameters:
    `str` - the String to hash
    `strLength` - the length of the String to hash
  Returns:
    hashcode for the String

### hashChars

    public static int hashChars(char[] chars,
                                int offset,
                                int length)

  generate a hashcode for a character array
  Parameters:
    `chars` - the array to hash
    `offset` - the offset to start hashing
    `length` - the length of characters to hash
  Returns:
    hashcode for the character array

### hashChar

    public static int hashChar(int hashcode,
                               int ch)

  generate partially completed character hashcode. this is mean to be iterated over individual characters in order to generate a full hash value
  Parameters:
    `hashcode` - a partially completed character hashcode
    `ch` - the character to hash
  Returns:
    a partially completed character hashcode
  See Also:
    `finishHash(int)`

### finishHash

    public static int finishHash(int hashcode)

  finish hashing a partically completed character hashcode
  Parameters:
    `hashcode` - a partially completed character hashcode
  Returns:
    a character hashcode
  See Also:
    `hashChar(int,int)`

Copyright © 1999-2001 Apache XML Project. All Rights Reserved.