public static int hash(byte[] data) { return hash(data, data.length, -1); }
/** * 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 int hash(Object o) { if (o == null) { return 0; } if (o instanceof Long) { return hashLong((Long) o); } if (o instanceof Integer) { return hashLong((Integer) o); } if (o instanceof Double) { return hashLong(Double.doubleToRawLongBits((Double) o)); } if (o instanceof Float) { return hashLong(Float.floatToRawIntBits((Float) o)); } if (o instanceof String) { return hash(((String) o).getBytes()); } if (o instanceof byte[]) { return hash((byte[]) o); } return hash(o.toString()); }
public static int hash(byte[] data, int seed) { return hash(data, data.length, seed); }
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()); }
public static int hash(Object o) { if (o == null) { return 0; } if (o instanceof Long) { return hashLong((Long) o); } if (o instanceof Integer) { return hashLong((Integer) o); } if (o instanceof Double) { return hashLong(Double.doubleToRawLongBits((Double) o)); } if (o instanceof Float) { return hashLong(Float.floatToRawIntBits((Float) o)); } if (o instanceof String) { return hash(((String) o).getBytes()); } if (o instanceof byte[]) { return hash((byte[]) o); } return hash(o.toString()); }
@Override public boolean offer(Object o) { boolean modified = false; long hash = (long) MurmurHash.hash(o); int bit = (int) ((hash & 0xFFFFFFFFL) % (long) length); int i = bit / 8; byte b = map[i]; byte mask = (byte) (1 << (bit % 8)); if ((mask & b) == 0) { map[i] = (byte) (b | mask); count--; modified = true; } return modified; }
@Override public boolean offer(Object o) { long x = MurmurHash.hash64(o); return offerHashed(x); }
static int[] getHashBuckets(byte[] b, int hashCount, int max) { int[] result = new int[hashCount]; int hash1 = MurmurHash.hash(b, b.length, 0); int hash2 = MurmurHash.hash(b, b.length, hash1); for (int i = 0; i < hashCount; i++) { result[i] = Math.abs((hash1 + i * hash2) % max); } return result; } }
@Override public boolean offer(Object o) { final long x = MurmurHash.hash64(o); return offerHashed(x); }
@Override public boolean offer(Object o) { int x = MurmurHash.hash(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)); }
@Override public boolean offer(Object o) { final int x = MurmurHash.hash(o); return offerHashed(x); }
@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); }
@Test public void testHashByteArrayOverload() { String input = "hashthis"; byte[] inputBytes = input.getBytes(); int hashOfString = MurmurHash.hash(input); assertEquals("MurmurHash.hash(byte[]) did not match MurmurHash.hash(String)", hashOfString, MurmurHash.hash(inputBytes)); Object bytesAsObject = inputBytes; assertEquals("MurmurHash.hash(Object) given a byte[] did not match MurmurHash.hash(String)", hashOfString, MurmurHash.hash(bytesAsObject)); }
/** * 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); }
@Test public void testHash() throws Exception { final long actualHash = MurmurHash.hash("hashthis"); final long expectedHash = -1974946086L; assertEquals("MurmurHash.hash(String) returns wrong hash value", expectedHash, actualHash); } }
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()); }
public static int hash(byte[] data) { return hash(data, data.length, -1); }
@Override public boolean offer(Object o) { long x = MurmurHash.hash64(o); return offerHashed(x); }