public static int hashUnsafeBytes(Object base, long offset, int lengthInBytes, int seed) { assert (lengthInBytes >= 0): "lengthInBytes cannot be negative"; int lengthAligned = lengthInBytes - lengthInBytes % 4; int h1 = hashBytesByInt(base, offset, lengthAligned, seed); for (int i = lengthAligned; i < lengthInBytes; i++) { int halfWord = Platform.getByte(base, offset + i); int k1 = mixK1(halfWord); h1 = mixH1(h1, k1); } return fmix(h1, lengthInBytes); }
private boolean containsHashBuffer(BitArray[] bloomFilters, int[] hashBuffer) { final int hashBufferLength = hashBuffer.length; for (int index = 0; index < hashBufferLength; index++) { final int combinedHash = hashBuffer[index]; final BitArray bloomFilter = bloomFilters[index]; if (!bloomFilter.get(combinedHash % bloomFilter.bitSize())) { return false; } } return true; }
private double calculateAverageLoad(BitArray[] bloomFilters) { double totalLoad = 0D; final int bloomFiltersLength = bloomFilters.length; for (BitArray currentBloomFilter : bloomFilters) { totalLoad += currentBloomFilter.bitCount() / currentBloomFilter.bitSize(); } return totalLoad / bloomFiltersLength; }
public static int hashUnsafeWords(Object base, long offset, int lengthInBytes, int seed) { // This is based on Guava's `Murmur32_Hasher.processRemaining(ByteBuffer)` method. assert (lengthInBytes % 8 == 0): "lengthInBytes must be a multiple of 8 (word-aligned)"; int h1 = hashBytesByInt(base, offset, lengthInBytes, seed); return fmix(h1, lengthInBytes); }
public int hashLong(long input) { return hashLong(input, seed); }
public int hashUnsafeWords(Object base, long offset, int lengthInBytes) { return hashUnsafeWords(base, offset, lengthInBytes, seed); }
public int hashInt(int input) { return hashInt(input, seed); }
public static BitArray readFrom(DataInputStream in) throws IOException { final int numWords = in.readInt(); long[] data = new long[numWords]; for (int i = 0; i < numWords; i++) { data[i] = in.readLong(); } return new BitArray(data); } // @formatter:on
private void fillHashBuffer(byte[] element, int[] hashBuffer) { /* * Adam Kirsch and Michael Mitzenmacher. 2008. Less hashing, same performance: Building a better Bloom filter. * Random Struct. Algorithms 33, 2 (September 2008), 187-218. DOI=http://dx.doi.org/10.1002/rsa.v33:2 */ final int hashBufferLength = hashBuffer.length; final int hash1 = Murmur3_x86_32.hashUnsafeBytes(element, Platform.BYTE_ARRAY_OFFSET, element.length, 0); final int hash2 = Murmur3_x86_32.hashUnsafeBytes(element, Platform.BYTE_ARRAY_OFFSET, element.length, hash1); for (int index = 0; index < hashBufferLength; index++) { int combinedHash = hash1 + ((index + 1) * hash2); if (combinedHash < 0) { combinedHash = ~combinedHash; } hashBuffer[index] = combinedHash; } }
public BitArray(long numBits) { this(new long[numWords(numBits)]); }
private boolean containsHashBuffer(BitArray[] bloomFilters, int[] hashBuffer) { final int hashBufferLength = hashBuffer.length; for (int index = 0; index < hashBufferLength; index++) { final int combinedHash = hashBuffer[index]; final BitArray bloomFilter = bloomFilters[index]; if (!bloomFilter.get(combinedHash % bloomFilter.bitSize())) { return false; } } return true; }
private void fillHashBuffer(byte[] element, int[] hashBuffer) { /* * Adam Kirsch and Michael Mitzenmacher. 2008. Less hashing, same performance: Building a better Bloom filter. * Random Struct. Algorithms 33, 2 (September 2008), 187-218. DOI=http://dx.doi.org/10.1002/rsa.v33:2 */ final int hashBufferLength = hashBuffer.length; final int hash1 = Murmur3_x86_32.hashUnsafeBytes(element, Platform.BYTE_ARRAY_OFFSET, element.length, 0); final int hash2 = Murmur3_x86_32.hashUnsafeBytes(element, Platform.BYTE_ARRAY_OFFSET, element.length, hash1); for (int index = 0; index < hashBufferLength; index++) { int combinedHash = hash1 + ((index + 1) * hash2); if (combinedHash < 0) { combinedHash = ~combinedHash; } hashBuffer[index] = combinedHash; } }
private boolean containsHashBuffer(BitArray[] bloomFilters, int[] hashBuffer) { final int hashBufferLength = hashBuffer.length; for (int index = 0; index < hashBufferLength; index++) { final int combinedHash = hashBuffer[index]; final BitArray bloomFilter = bloomFilters[index]; if (!bloomFilter.get(combinedHash % bloomFilter.bitSize())) { return false; } } return true; }
private void fillHashBuffer(byte[] element, int[] hashBuffer) { /* * Adam Kirsch and Michael Mitzenmacher. 2008. Less hashing, same performance: Building a better Bloom filter. * Random Struct. Algorithms 33, 2 (September 2008), 187-218. DOI=http://dx.doi.org/10.1002/rsa.v33:2 */ final int hashBufferLength = hashBuffer.length; final int hash1 = Murmur3_x86_32.hashUnsafeBytes(element, Platform.BYTE_ARRAY_OFFSET, element.length, 0); final int hash2 = Murmur3_x86_32.hashUnsafeBytes(element, Platform.BYTE_ARRAY_OFFSET, element.length, hash1); for (int index = 0; index < hashBufferLength; index++) { int combinedHash = hash1 + ((index + 1) * hash2); if (combinedHash < 0) { combinedHash = ~combinedHash; } hashBuffer[index] = combinedHash; } }