/[Apache-SVN]/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/JenkinsHash.java
ViewVC logotype

Diff of /hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/JenkinsHash.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 693597, Tue Sep 9 20:36:49 2008 UTC revision 698265, Tue Sep 23 18:10:06 2008 UTC
# Line 38  import java.io.IOException; Line 38  import java.io.IOException;
38   * @see <a href="http://burtleburtle.net/bob/hash/doobs.html">Has update on the   * @see <a href="http://burtleburtle.net/bob/hash/doobs.html">Has update on the
39   * Dr. Dobbs Article</a>   * Dr. Dobbs Article</a>
40   */   */
41  public class JenkinsHash {  public class JenkinsHash extends Hash {
42    private static long INT_MASK  = 0x00000000ffffffffL;    private static long INT_MASK  = 0x00000000ffffffffL;
43    private static long BYTE_MASK = 0x00000000000000ffL;    private static long BYTE_MASK = 0x00000000000000ffL;
44    
45    private static long rot(long val, int pos) {    private static JenkinsHash _instance = new JenkinsHash();
     return ((Integer.rotateLeft(  
         (int)(val & INT_MASK), pos)) & INT_MASK);  
   }  
46    
47    /**    public static Hash getInstance() {
48     * Alternate form for hashing an entire byte array      return _instance;
    *  
    * @param bytes  
    * @return hash value  
    */  
   public static int hash(byte[] bytes) {  
     return hash(bytes, bytes.length, -1);  
49    }    }
50    
51    /**    private static long rot(long val, int pos) {
52     * Alternate form for hashing an entire byte array      return ((Integer.rotateLeft(
53     *          (int)(val & INT_MASK), pos)) & INT_MASK);
    * @param bytes  
    * @param initval  
    * @return hash value  
    */  
   public static int hash(byte[] bytes, int initval) {  
     return hash(bytes, bytes.length, initval);  
54    }    }
55    
56    /**    /**
# Line 94  public class JenkinsHash { Line 79  public class JenkinsHash {
79     * acceptable.  Do NOT use for cryptographic purposes.     * acceptable.  Do NOT use for cryptographic purposes.
80    */    */
81    @SuppressWarnings("fallthrough")    @SuppressWarnings("fallthrough")
82    public static int hash(byte[] key, int nbytes, int initval) {    public int hash(byte[] key, int nbytes, int initval) {
83      int length = nbytes;      int length = nbytes;
84      long a, b, c;       // We use longs because we don't have unsigned ints      long a, b, c;       // We use longs because we don't have unsigned ints
85      a = b = c = (0x00000000deadbeefL + length + initval) & INT_MASK;      a = b = c = (0x00000000deadbeefL + length + initval) & INT_MASK;
# Line 266  public class JenkinsHash { Line 251  public class JenkinsHash {
251      FileInputStream in = new FileInputStream(args[0]);      FileInputStream in = new FileInputStream(args[0]);
252      byte[] bytes = new byte[512];      byte[] bytes = new byte[512];
253      int value = 0;      int value = 0;
254        JenkinsHash hash = new JenkinsHash();
255      for (int length = in.read(bytes); length > 0 ; length = in.read(bytes)) {      for (int length = in.read(bytes); length > 0 ; length = in.read(bytes)) {
256        value = hash(bytes, length, value);        value = hash.hash(bytes, length, value);
257      }      }
258      System.out.println(Math.abs(value));      System.out.println(Math.abs(value));
259    }    }

Legend:
Removed from v.693597  
changed lines
  Added in v.698265

apache@apache.org
ViewVC Help
Powered by ViewVC 1.1.2