/** * Constructor. * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash functions to consider. * @param hashType type of the hashing function (see {@link Hash}). */ protected Filter(int vectorSize, int nbHash, int hashType) { this.vectorSize = vectorSize; this.nbHash = nbHash; this.hashType = hashType; this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); }
int[] h = hash.hash(k);
int[] h = hash.hash(k);
@Override public void readFields(DataInput in) throws IOException { int ver = in.readInt(); if (ver > 0) { // old unversioned format this.nbHash = ver; this.hashType = Hash.JENKINS_HASH; } else if (ver == VERSION) { this.nbHash = in.readInt(); this.hashType = in.readByte(); } else { throw new IOException("Unsupported version: " + ver); } this.vectorSize = in.readInt(); this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); } }//end class
int[] h = hash.hash(k);
/** * Constructor. * * @param vectorSize * The vector size of <i>this</i> filter. * @param nbHash * The number of hash functions to consider. * @param hashType * type of the hashing function (see {@link Hash}). */ protected Filter(final int vectorSize, final int nbHash, final int hashType) { this.vectorSize = vectorSize; this.nbHash = nbHash; this.hashType = hashType; this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); }
int[] h = hash.hash(k);
@Override public boolean membershipTest(Key key) { if(key == null) { throw new NullPointerException("Key may not be null"); } int[] h = hash.hash(key); hash.clear(); for(int i = 0; i < nbHash; i++) { // find the bucket int wordNum = h[i] >> 4; // div 16 int bucketShift = (h[i] & 0x0f) << 2; // (mod 16) * 4 long bucketMask = 15L << bucketShift; if((buckets[wordNum] & bucketMask) == 0) { return false; } } return true; }
@Override public void readFields(final DataInput in) throws IOException { final int ver = in.readInt(); rVersion = ver; if (ver > 0) { // old unversioned format this.nbHash = ver; this.hashType = Hash.JENKINS_HASH; } else if (ver == VERSION | ver == VERSION + 1) { // Support for directly serializing the bitset this.nbHash = in.readInt(); this.hashType = in.readByte(); } else { throw new IOException("Unsupported version: " + ver); } this.vectorSize = in.readInt(); this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); } }// end class
int[] h = hash.hash(k);
@Override public void add(Key key) { if(key == null) { throw new NullPointerException("key can not be null"); } int[] h = hash.hash(key); hash.clear(); for(int i = 0; i < nbHash; i++) { // find the bucket int wordNum = h[i] >> 4; // div 16 int bucketShift = (h[i] & 0x0f) << 2; // (mod 16) * 4 long bucketMask = 15L << bucketShift; long bucketValue = (buckets[wordNum] & bucketMask) >>> bucketShift; // only increment if the count in the bucket is less than BUCKET_MAX_VALUE if(bucketValue < BUCKET_MAX_VALUE) { // increment by 1 buckets[wordNum] = (buckets[wordNum] & ~bucketMask) | ((bucketValue + 1) << bucketShift); } } }
/** * Constructor. * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash functions to consider. * @param hashType type of the hashing function (see {@link Hash}). */ protected Filter(int vectorSize, int nbHash, int hashType) { this.vectorSize = vectorSize; this.nbHash = nbHash; this.hashType = hashType; this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); }
int[] h = hash.hash(k);
/** * Constructor. * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash functions to consider. * @param hashType type of the hashing function (see {@link Hash}). */ protected Filter(int vectorSize, int nbHash, int hashType) { this.vectorSize = vectorSize; this.nbHash = nbHash; this.hashType = hashType; this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); }
/** * Adds a false positive information to <i>this</i> retouched Bloom filter. * <p> * <b>Invariant</b>: if the false positive is <code>null</code>, nothing happens. * @param key The false positive key to add. */ public void addFalsePositive(Key key) { if (key == null) { throw new NullPointerException("key can not be null"); } int[] h = hash.hash(key); hash.clear(); for (int i = 0; i < nbHash; i++) { fpVector[h[i]].add(key); } }
/** * Constructor. * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash functions to consider. * @param hashType type of the hashing function (see {@link Hash}). */ protected Filter(int vectorSize, int nbHash, int hashType) { this.vectorSize = vectorSize; this.nbHash = nbHash; this.hashType = hashType; this.hash = new HashFunction(this.vectorSize, this.nbHash, this.hashType); }