com.mongodb.util
Class Hash

java.lang.Object
  extended by com.mongodb.util.Hash

public final class Hash
extends java.lang.Object


Constructor Summary
Hash()
           
 
Method Summary
static int hashBackward(java.lang.String s)
          Creates a hash for a string.
static long hashBackwardLong(java.lang.String s)
          Creates a long hash for a string.
static int hashCode(java.lang.CharSequence s, int start, int end)
          Creates a hash code of a string from [start-end)
static int hashCode(java.lang.String... strings)
          Calculate the hashcode for a series of strings combined as one.
static long longHash(java.lang.String s)
          64-bit hash, using longs, in stead of ints, for less collisions, for when it matters.
static long longHash(java.lang.String s, int start, int end)
          64-bit hash using longs, starting on index 'start' and including everything before 'end'.
static long longHashAppend(long hash, char c)
          Adds a character to an existing hash code.
static long longLowerHash(java.lang.String s)
          Same as longHash(String), using only lower-case values of letters.
static long longLowerHash(java.lang.String s, int start, int end)
          Long (64-bit) hash, lower-cased, from [start-end)
static long longLowerHash(java.lang.String s, int start, int end, long hash)
          Long (64-bit) hash, lower-cased, from [start-end)
static long longLowerHashAppend(long hash, char c)
          Adds the lower-case equivalent of a character to an existing hash code.
static int lowerCaseHash(java.lang.String s)
          This is an exact copy of the String hashCode() function, aside from the lowercasing.
static int lowerCaseHash(java.lang.String s, int start, int end)
          Creates a hash code of a lowercase string from [start-end)
static int lowerCaseSpaceTrimHash(java.lang.String s)
          This is an exact copy of the String hashCode() function, aside from the lowercasing.
static int lowerCaseSpaceTrimHash(java.lang.String s, int start, int end)
          Creates a hash code of a lowercase string from [start-end) ignoring whitespace
static int nospaceLowerHash(java.lang.String s, int start, int end)
          Creates a hash code of a lowercase string with whitespace removed from [start-end)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hash

public Hash()
Method Detail

hashBackward

public static final int hashBackward(java.lang.String s)
Creates a hash for a string.

Parameters:
s - String to hash
Returns:
the hash code

hashBackwardLong

public static final long hashBackwardLong(java.lang.String s)
Creates a long hash for a string.

Parameters:
s - the string to hash
Returns:
the hash code

longHash

public static final long longHash(java.lang.String s)
64-bit hash, using longs, in stead of ints, for less collisions, for when it matters. Calls longHash( s , 0 , s.length() )

Parameters:
s - The String to hash.
Returns:
the hash code

longHash

public static final long longHash(java.lang.String s,
                                  int start,
                                  int end)
64-bit hash using longs, starting on index 'start' and including everything before 'end'.

Parameters:
s - The string to hash.
start - Where to start the hash.
end - Where to end the hash.
Returns:
the hash code

longLowerHash

public static final long longLowerHash(java.lang.String s)
Same as longHash(String), using only lower-case values of letters. Calls longhash( s , 0 , s.length() ).

Parameters:
s - The string to Hash.
Returns:
the hash code

longLowerHash

public static final long longLowerHash(java.lang.String s,
                                       int start,
                                       int end)
Long (64-bit) hash, lower-cased, from [start-end)

Parameters:
s - The string to hash.
start - where to start hashing.
end - Where to stop hashing.
Returns:
the hash code

longLowerHash

public static final long longLowerHash(java.lang.String s,
                                       int start,
                                       int end,
                                       long hash)
Long (64-bit) hash, lower-cased, from [start-end)

Parameters:
s - The string to hash.
start - where to start hashing.
end - Where to stop hashing.
Returns:
the hash code

longLowerHashAppend

public static final long longLowerHashAppend(long hash,
                                             char c)
Adds the lower-case equivalent of a character to an existing hash code.

Parameters:
hash - the existing hash code
c - the character to add
Returns:
the hash code

longHashAppend

public static final long longHashAppend(long hash,
                                        char c)
Adds a character to an existing hash code.

Parameters:
hash - the existing hash code
c - the character to add
Returns:
the hash code

lowerCaseHash

public static final int lowerCaseHash(java.lang.String s)
This is an exact copy of the String hashCode() function, aside from the lowercasing.

Parameters:
s - string to be hashed
Returns:
the hash code

lowerCaseHash

public static final int lowerCaseHash(java.lang.String s,
                                      int start,
                                      int end)
Creates a hash code of a lowercase string from [start-end)

Parameters:
s - string to be hashed
start - the starting index
end - the ending index
Returns:
the hash code

hashCode

public static final int hashCode(java.lang.CharSequence s,
                                 int start,
                                 int end)
Creates a hash code of a string from [start-end)

Parameters:
s - string to be hashed
start - the starting index
end - the ending index
Returns:
the hash code

nospaceLowerHash

public static final int nospaceLowerHash(java.lang.String s,
                                         int start,
                                         int end)
Creates a hash code of a lowercase string with whitespace removed from [start-end)

Parameters:
s - string to be hashed
start - the starting index
end - the ending index
Returns:
the hash code

lowerCaseSpaceTrimHash

public static final int lowerCaseSpaceTrimHash(java.lang.String s)
This is an exact copy of the String hashCode() function, aside from the lowercasing. No, it's not. It also ignores consecutive whitespace.

Parameters:
s - string to be hashed
Returns:
the hash code

lowerCaseSpaceTrimHash

public static final int lowerCaseSpaceTrimHash(java.lang.String s,
                                               int start,
                                               int end)
Creates a hash code of a lowercase string from [start-end) ignoring whitespace

Parameters:
s - string to be hashed
start - the starting index
end - the ending index
Returns:
the hash code

hashCode

public static final int hashCode(java.lang.String... strings)
Calculate the hashcode for a series of strings combined as one.

Parameters:
strings - Varargs array of Strings.
Returns:
A hashcode.