/** * A constructor to support rebuilding the BloomFilter from a serialized representation. * @param bits BloomK sketch data in form of array of longs. * @param numFuncs Number of functions called as K. */ public BloomKFilter(long[] bits, int numFuncs) { super(); bitSet = new BitSet(bits); this.m = bits.length * Long.SIZE; this.k = numFuncs; checkArgument((bitSet.data.length % DEFAULT_BLOCK_SIZE) == 0, "bitSet has to be block aligned"); this.totalBlockCount = bitSet.data.length / DEFAULT_BLOCK_SIZE; } static int optimalNumOfHashFunctions(long n, long m) {
public BloomKFilter(long maxNumEntries) { checkArgument(maxNumEntries > 0, "expectedEntries should be > 0"); long numBits = optimalNumOfBits(maxNumEntries, DEFAULT_FPP); this.k = optimalNumOfHashFunctions(maxNumEntries, numBits); long nLongs = (long) Math.ceil((double) numBits / (double) Long.SIZE); // additional bits to pad long array to block size long padLongs = DEFAULT_BLOCK_SIZE - nLongs % DEFAULT_BLOCK_SIZE; this.m = (nLongs + padLongs) * Long.SIZE; this.bitSet = new BitSet(m); checkArgument((bitSet.data.length % DEFAULT_BLOCK_SIZE) == 0, "bitSet has to be block aligned"); this.totalBlockCount = bitSet.data.length / DEFAULT_BLOCK_SIZE; }
/** * A constructor to support rebuilding the BloomFilter from a serialized representation. * @param bits * @param numFuncs */ public BloomKFilter(long[] bits, int numFuncs) { super(); bitSet = new BitSet(bits); this.m = bits.length * Long.SIZE; this.k = numFuncs; checkArgument((bitSet.data.length % DEFAULT_BLOCK_SIZE) == 0, "bitSet has to be block aligned"); this.totalBlockCount = bitSet.data.length / DEFAULT_BLOCK_SIZE; } static int optimalNumOfHashFunctions(long n, long m) {
public BloomKFilter(long maxNumEntries) { checkArgument(maxNumEntries > 0, "expectedEntries should be > 0"); long numBits = optimalNumOfBits(maxNumEntries, DEFAULT_FPP); this.k = optimalNumOfHashFunctions(maxNumEntries, numBits); int nLongs = (int) Math.ceil((double) numBits / (double) Long.SIZE); // additional bits to pad long array to block size int padLongs = DEFAULT_BLOCK_SIZE - nLongs % DEFAULT_BLOCK_SIZE; this.m = (nLongs + padLongs) * Long.SIZE; this.bitSet = new BitSet(m); checkArgument((bitSet.data.length % DEFAULT_BLOCK_SIZE) == 0, "bitSet has to be block aligned"); this.totalBlockCount = bitSet.data.length / DEFAULT_BLOCK_SIZE; }