/** * Hash a long and long seed. * * @param datum the input long * @param seed A long valued seed. * @return The 128-bit hash as a long[2]. */ public static long[] hashToLongs(final long datum, final long seed) { final long[] data = { datum }; return hash(data, seed); }
/** * Hash a double and long seed. * * @param datum the input double. * @param seed A long valued seed. * @return The 128-bit hash as a long[2]. */ public static long[] hashToLongs(final double datum, final long seed) { final double d = (datum == 0.0) ? 0.0 : datum; //canonicalize -0.0, 0.0 final long[] data = { Double.doubleToLongBits(d) };//canonicalize all NaN forms return hash(data, seed); }
/** * Create this sketch with a long. * * @param datum The given long datum. * @return a SingleItemSketch */ public static SingleItemSketch create(final long datum) { final long[] data = { datum }; return new SingleItemSketch(hash(data, DEFAULT_UPDATE_SEED)[0] >>> 1); }
/** * Create this sketch with the given byte array. * If the byte array is null or empty no create attempt is made and the method returns null. * * @param data The given byte array. * @return a SingleItemSketch or null */ public static SingleItemSketch create(final byte[] data) { if ((data == null) || (data.length == 0)) { return null; } return new SingleItemSketch(hash(data, DEFAULT_UPDATE_SEED)[0] >>> 1); }
/** * Create this sketch with the given integer array. * If the integer array is null or empty no create attempt is made and the method returns null. * * @param data The given int array. * @return a SingleItemSketch or null */ public static SingleItemSketch create(final int[] data) { if ((data == null) || (data.length == 0)) { return null; } return new SingleItemSketch(hash(data, DEFAULT_UPDATE_SEED)[0] >>> 1); }
private static long murmur(long key) { long[] keyArr = { key }; return MurmurHash3.hash(keyArr, 0)[0]; } }
/** * Updates this sketch with a long[] key and double values. * The values will be stored or added to the ones associated with the key * * @param key The given long[] key * @param values The given values */ public void update(final long[] key, final double[] values) { if (key == null || key.length == 0) { return; } insertOrIgnore(MurmurHash3.hash(key, seed_)[0] >>> 1, values); }
/** * Updates this sketch with a byte[] key and U value. * The value is passed to update() method of the Summary object associated with the key * * @param key The given byte[] key * @param value The given U value */ public void update(final byte[] key, final U value) { if ((key == null) || (key.length == 0)) { return; } insertOrIgnore(MurmurHash3.hash(key, DEFAULT_UPDATE_SEED)[0] >>> 1, value); }
/** * Present the given long as a potential unique item. * * @param datum The given long datum. */ public void update(final long datum) { final long[] data = { datum }; final long[] arr = hash(data, seed); hashUpdate(arr[0], arr[1]); }
/** * Present the given byte array as a potential unique item. * If the byte array is null or empty no update attempt is made and the method returns. * * @param data The given byte array. */ public void update(final byte[] data) { if ((data == null) || (data.length == 0)) { return; } final long[] arr = hash(data, seed); hashUpdate(arr[0], arr[1]); }
/** * Present this sketch with a long. * * @param datum The given long datum. * @return * <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a> */ public UpdateReturnState update(final long datum) { final long[] data = { datum }; return hashUpdate(hash(data, getSeed())[0] >>> 1); }
/** * Present the given byte array as a potential unique item. * If the byte array is null or empty no update attempt is made and the method returns. * * @param data The given byte array. */ public void update(final byte[] data) { if ((data == null) || (data.length == 0)) { return; } couponUpdate(coupon(hash(data, DEFAULT_UPDATE_SEED))); }
/** * Present the given long array as a potential unique item. * If the long array is null or empty no update attempt is made and the method returns. * * @param data The given long array. */ public void update(final long[] data) { if ((data == null) || (data.length == 0)) { return; } couponUpdate(coupon(hash(data, DEFAULT_UPDATE_SEED))); }
/** * Present the given long as a potential unique item. * * @param datum The given long datum. */ public void update(final long datum) { final long[] data = { datum }; couponUpdate(coupon(hash(data, DEFAULT_UPDATE_SEED))); }
/** * Present the given integer array as a potential unique item. * If the integer array is null or empty no update attempt is made and the method returns. * * @param data The given int array. */ public void update(final int[] data) { if ((data == null) || (data.length == 0)) { return; } couponUpdate(coupon(hash(data, DEFAULT_UPDATE_SEED))); }
@Test public void checkByteArrRemainderGT8() { //byte[], remainder > 8 String keyStr = "The quick brown fox jumps over the lazy dog"; byte[] key = keyStr.getBytes(UTF_8); long[] result = hash(key, 0); //Should be: long h1 = 0xe34bbc7bbc071b6cL; long h2 = 0x7a433ca9c49a9347L; Assert.assertEquals(result[0], h1); Assert.assertEquals(result[1], h2); }
@Test public void checkByteArrRemainderLt8() { //byte[], test a remainder < 8 String keyStr = "The quick brown fox jumps over the lazy dogdogdog"; byte[] key = keyStr.getBytes(UTF_8); long[] result = hash(key, 0); //Should be; long h1 = 0x9c8205300e612fc4L; long h2 = 0xcbc0af6136aa3df9L; Assert.assertEquals(result[0], h1); Assert.assertEquals(result[1], h2); }
@Test public void checkByteArrReaminderEQ8() { //byte[], test a remainder = 8 String keyStr = "The quick brown fox jumps over the lazy1"; byte[] key = keyStr.getBytes(UTF_8); long[] result = hash(key, 0); //Should be: long h1 = 0xe3301a827e5cdfe3L; long h2 = 0xbdbf05f8da0f0392L; Assert.assertEquals(result[0], h1); Assert.assertEquals(result[1], h2); }
/** * Present the given long as a potential unique item. * * @param datum The given long datum. */ public void update(final long datum) { final long[] data = { datum }; final long[] harr = hash(data, seed); hashUpdate(harr[0], harr[1]); }
@Test public void checkHashArrayInsert() { long[] hTable = new long[16]; long[] hashIn = new long[1]; for (int i=0; i<8; i++) { hashIn[0] = i; long h = hash(hashIn, 0)[0] >>> 1; hashInsertOnly(hTable, 4, h); int count = hashArrayInsert(hTable, hTable, 4, Long.MAX_VALUE); assertEquals(count, 0); } }