net.sf.mmm.util.text.api
Interface StringHasher

All Known Implementing Classes:
AbstractStringHasher, FastStringHasher, SimpleStringHasher

public interface StringHasher

This is the interface for a hashing algorithm for strings (in form of char[] or CharSequence.
ATTENTION:
The implementation may NOT be compatible to String.hashCode(). It only needs to guarantee, that all method defined in this interface are compatible to each other. The purpose of this interface is to abstract from the hash-algorithm that can be optimized for performance or to generate strong hashes (or maybe both). In this context performance or fast is especially focused on methods such as getHashCodes(char[], int, int, int) rather than getHashCode(CharSequence) which will NOT be faster than String.hashCode() itself.

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Method Summary
 int getHashCode(char[] string, int start, int end)
          This method gets the hash-code for the specified subsequence of the given string.
 int getHashCode(CharSequence string)
          This method gets the hash-code for the given string.
 int getHashCode(CharSequence string, int start, int end)
          This method gets the hash-code for the specified subsequence of the given string.
 int[] getHashCodes(char[] string, int length)
          This method gets the hash-codes for all subsequence of string that have the given length.
 int[] getHashCodes(char[] string, int length, int stringStart, int stringEnd)
          This method gets the hash-codes for all subsequence of string from stringStart (inclusive) until stringEnd (exclusive) that have the given length.
 int[] getHashCodes(CharSequence string, int length)
          This method gets the hash-codes for all subsequence of string that have the given length.
 int[] getHashCodes(CharSequence string, int length, int stringStart, int stringEnd)
          This method gets the hash-codes for all subsequence of string from stringStart (inclusive) until stringEnd (exclusive) that have the given length.
 

Method Detail

getHashCode

int getHashCode(CharSequence string)
This method gets the hash-code for the given string.

Parameters:
string - is the CharSequence to hash.
Returns:
the according hash-code.
See Also:
getHashCode(CharSequence, int, int)

getHashCode

int getHashCode(CharSequence string,
                int start,
                int end)
This method gets the hash-code for the specified subsequence of the given string.

Parameters:
string - is the CharSequence containing the subsequence to hash.
start - is the index of the first character to include into the hash.
end - is the index one before the last character to include into the hash.
Returns:
the according hash-code.
See Also:
Object.hashCode()

getHashCode

int getHashCode(char[] string,
                int start,
                int end)
This method gets the hash-code for the specified subsequence of the given string.

Parameters:
string - is the char-array containing the substring to hash.
start - is the index of the first character to include into the hash.
end - is the index one before the last character to include into the hash.
Returns:
the according hash-code.
See Also:
Object.hashCode()

getHashCodes

int[] getHashCodes(char[] string,
                   int length)
This method gets the hash-codes for all subsequence of string that have the given length.

Parameters:
string - is the string as char-array.
length - is the length of the sub-sequences of string to hash.
Returns:
the requested hash-codes. An empty array if the length of string is less than the given length.
See Also:
getHashCodes(char[], int, int, int)

getHashCodes

int[] getHashCodes(char[] string,
                   int length,
                   int stringStart,
                   int stringEnd)
This method gets the hash-codes for all subsequence of string from stringStart (inclusive) until stringEnd (exclusive) that have the given length.
The implementation of this method needs to behave functionally equivalent to this code (but should be more efficient):
 int size = stringEnd - stringStart - length + 1;
 if (size <= 0) {
   return new int[0];
 }
 int[] result = new int[size];
 for (int i = 0; i < size; i++) {
   result[i] = getHashCode(string, i, i + length);
 }
 return result;
 

Parameters:
string - is the string as char-array.
length - is the length of the sub-sequences of string to hash.
stringStart - is the index where to start in string.
stringEnd - is the index where to stop in string.
Returns:
the requested hash-codes. An empty array if the length of string is less than the given length.

getHashCodes

int[] getHashCodes(CharSequence string,
                   int length)
This method gets the hash-codes for all subsequence of string that have the given length.

Parameters:
string - is the string as char-array.
length - is the length of the sub-sequences of string to hash.
Returns:
the requested hash-codes. An empty array if the length of string is less than the given length.
See Also:
getHashCodes(char[], int)

getHashCodes

int[] getHashCodes(CharSequence string,
                   int length,
                   int stringStart,
                   int stringEnd)
This method gets the hash-codes for all subsequence of string from stringStart (inclusive) until stringEnd (exclusive) that have the given length.

Parameters:
string - is the string as char-array.
length - is the length of the sub-sequences of string to hash.
stringStart - is the index where to start in string.
stringEnd - is the index where to stop in string.
Returns:
the requested hash-codes. An empty array if the length of string is less than the given length.
See Also:
getHashCodes(char[], int)


Copyright © 2001-2010 mmm-Team. All Rights Reserved.