/** * Generates 64 bit hash from byte array with default seed value. * * @param data byte array to hash * @param length length of the array to hash * @return 64 bit hash of the given string */ public static long hash64(final byte[] data, int length) { return hash64(data, length, 0xe17a1465); }
public static long hash64(Object o) { if (o == null) { return 0l; } else if (o instanceof String) { final byte[] bytes = ((String) o).getBytes(); return hash64(bytes, bytes.length); } else if (o instanceof byte[]) { final byte[] bytes = (byte[]) o; return hash64(bytes, bytes.length); } return hash64(o.toString()); }
@Override public boolean offer(Object o) { long x = MurmurHash.hash64(o); return offerHashed(x); }
@Override public boolean offer(Object o) { final long x = MurmurHash.hash64(o); return offerHashed(x); }
@Test public void testHash64ByteArrayOverload() { String input = "hashthis"; byte[] inputBytes = input.getBytes(); long hashOfString = MurmurHash.hash64(input); assertEquals("MurmurHash.hash64(byte[]) did not match MurmurHash.hash64(String)", hashOfString, MurmurHash.hash64(inputBytes)); Object bytesAsObject = inputBytes; assertEquals("MurmurHash.hash64(Object) given a byte[] did not match MurmurHash.hash64(String)", hashOfString, MurmurHash.hash64(bytesAsObject)); }
@Test public void testHash64() throws Exception { final long actualHash = MurmurHash.hash64("hashthis"); final long expectedHash = -8896273065425798843L; assertEquals("MurmurHash.hash64(String) returns wrong hash value", expectedHash, actualHash); }
/** * Generates 64 bit hash from byte array with default seed value. * * @param data byte array to hash * @param length length of the array to hash * @return 64 bit hash of the given string */ public static long hash64(final byte[] data, int length) { return hash64(data, length, 0xe17a1465); }
public static long hash64(Object o) { if (o == null) { return 0l; } else if (o instanceof String) { final byte[] bytes = ((String) o).getBytes(); return hash64(bytes, bytes.length); } else if (o instanceof byte[]) { final byte[] bytes = (byte[]) o; return hash64(bytes, bytes.length); } return hash64(o.toString()); }
@Override public boolean offer(Object o) { long x = MurmurHash.hash64(o); return offerHashed(x); }
@Override public boolean offer(Object o) { long x = MurmurHash.hash64(o); return offerHashed(x); }