Class Hashing

java.lang.Object
  |
  +--Hashing

public class Hashing
extends java.lang.Object

Class Hashing contains three different string-valued hash functions, as discussed in Lecture Notes Week 5.


Constructor Summary
Hashing()
           
 
Method Summary
static int hash1(java.lang.String key, int tableSize)
          Compute a hash index for the given string by summing the string characters and taking the modulus of the given table size.
static int hash2(java.lang.String key, int tableSize)
          Compute a hash index for the given string by summing the first three string characters with the formula: char[0] + (27 * char[1]) + (729 * char[2]) where 27 is the number of letter in the alphabet + 1 for a blank, and 729 is 272.
static int hash3(java.lang.String key, int tableSize)
          Compute a hash index for the given string by summing all of the string characters with the formula: (37 * char[0]) + (37^2 * char[1]) + ...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hashing

public Hashing()
Method Detail

hash1

public static int hash1(java.lang.String key,
                        int tableSize)
Compute a hash index for the given string by summing the string characters and taking the modulus of the given table size.

hash2

public static int hash2(java.lang.String key,
                        int tableSize)
Compute a hash index for the given string by summing the first three string characters with the formula: char[0] + (27 * char[1]) + (729 * char[2]) where 27 is the number of letter in the alphabet + 1 for a blank, and 729 is 272. Return the sum mod the given table size.

hash3

public static int hash3(java.lang.String key,
                        int tableSize)
Compute a hash index for the given string by summing all of the string characters with the formula: (37 * char[0]) + (37^2 * char[1]) + ... + (37^(l-1) * char[l]) where 37 is an empirically chosen value to provide good distribution and l = key.length(). Return the sum mod the given table size.