/[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

--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/JenkinsHash.java	2008/09/09 20:36:49	693597
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/JenkinsHash.java	2008/09/23 18:10:06	698265
@@ -38,9 +38,15 @@
  * @see <a href="http://burtleburtle.net/bob/hash/doobs.html">Has update on the
  * Dr. Dobbs Article</a>
  */
-public class JenkinsHash {
+public class JenkinsHash extends Hash {
   private static long INT_MASK  = 0x00000000ffffffffL;
   private static long BYTE_MASK = 0x00000000000000ffL;
+  
+  private static JenkinsHash _instance = new JenkinsHash();
+  
+  public static Hash getInstance() {
+    return _instance;
+  }
 
   private static long rot(long val, int pos) {
     return ((Integer.rotateLeft(
@@ -48,27 +54,6 @@
   }
 
   /**
-   * Alternate form for hashing an entire byte array
-   * 
-   * @param bytes
-   * @return hash value
-   */
-  public static int hash(byte[] bytes) {
-    return hash(bytes, bytes.length, -1);
-  }
-  
-  /**
-   * Alternate form for hashing an entire byte array
-   * 
-   * @param bytes 
-   * @param initval
-   * @return hash value
-   */
-  public static int hash(byte[] bytes, int initval) {
-    return hash(bytes, bytes.length, initval);
-  }
-  
-  /**
    * taken from  hashlittle() -- hash a variable-length key into a 32-bit value
    * 
    * @param key the key (the unaligned variable-length array of bytes)
@@ -94,7 +79,7 @@
    * acceptable.  Do NOT use for cryptographic purposes.
   */
   @SuppressWarnings("fallthrough")
-  public static int hash(byte[] key, int nbytes, int initval) {
+  public int hash(byte[] key, int nbytes, int initval) {
     int length = nbytes;
     long a, b, c;       // We use longs because we don't have unsigned ints
     a = b = c = (0x00000000deadbeefL + length + initval) & INT_MASK;
@@ -266,8 +251,9 @@
     FileInputStream in = new FileInputStream(args[0]);
     byte[] bytes = new byte[512];
     int value = 0;
+    JenkinsHash hash = new JenkinsHash();
     for (int length = in.read(bytes); length > 0 ; length = in.read(bytes)) {
-      value = hash(bytes, length, value);
+      value = hash.hash(bytes, length, value);
     }
     System.out.println(Math.abs(value));
   }

 

apache@apache.org
ViewVC Help
Powered by ViewVC 1.1.2