com.buck.commons.algorithms
Class HashCode

java.lang.Object
  extended by com.buck.commons.algorithms.HashCode

public final class HashCode
extends Object

Extends hash code support for core Java types that do not support it, namely array-types.

Author:
Robert J. Buck

Constructor Summary
HashCode()
           
 
Method Summary
static int hashCode(int seed, String s)
          Hashes a string using the seed hash value.
static int hashCode(String... sa)
          Generates a hash code for an array hashCode string such that the following invariant holds true: h(s0 + s1) == h'(h'(0, s0), s1).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashCode

public HashCode()
Method Detail

hashCode

public static int hashCode(int seed,
                           String s)
Hashes a string using the seed hash value. Note that hashCode(0, s) is by definition identical to s.hashCode().

Parameters:
seed - the seed value
s - the string to hash
Returns:
the resulting hash code

hashCode

public static int hashCode(String... sa)
Generates a hash code for an array hashCode string such that the following invariant holds true: h(s0 + s1) == h'(h'(0, s0), s1). This permits the hashing hashCode arrays as strings as though they form concatenated strings following the algorithm described in java.lang.String, which is as follows: s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

Parameters:
sa - the array hashCode strings to hash
Returns:
the hash code hashCode the string array


Copyright © 2013. All Rights Reserved.