public static int hash(byte[] data) { return hash(data, data.length, -1); }
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 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; }
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 int x = MurmurHash.hash(o); return offerHashed(x); }
@Override public boolean offer(Object o) { int x = MurmurHash.hash(o); return offerHashed(x); }
@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)); }
@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 int hash(byte[] data, int seed) { return hash(data, data.length, seed); }
public static int hash(byte[] data) { return hash(data, data.length, -1); }
@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; }
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 int x = MurmurHash.hash(o); return offerHashed(x); }
@Override public boolean offer(Object o) { final int x = MurmurHash.hash(o); return offerHashed(x); }
@Override public boolean offer(Object o) { int x = MurmurHash.hash(o); return offerHashed(x); }
@Override public int hashCode() { return MurmurHash.hash(this.toString()); }
@Override public void postProcessEvent(Event inputEvent) { // counting aggregations are hashed tostring values of the aggregation value inputEvent.getHeaders().put(Constants.FIELD_AGGREGATION_VALUE , MurmurHash.hash( inputEvent.getHeaders().get(Constants.FIELD_AGGREGATION_VALUE).toString() ) ); }