/** * Adds a list of false positive information to <i>this</i> retouched Bloom filter. * @param keys The list of false positive. */ public void addFalsePositive(List<Key> keys) { if (keys == null) { throw new NullPointerException("ArrayList<Key> can not be null"); } for (Key k : keys) { addFalsePositive(k); } }
if (!membershipTest(k)) { throw new IllegalArgumentException("Key is not a member"); index = randomRemove(); break; index = minimumFnRemove(h); break; index = maximumFpRemove(h); break; index = ratioRemove(h); break; clearBit(index);
/** * Chooses the bit position that minimizes the number of false negative generated while maximizing. * the number of false positive removed. * @param h The different bit positions. * @return The position that minimizes the number of false negative generated while maximizing. */ private int ratioRemove(int[] h) { computeRatio(); int minIndex = Integer.MAX_VALUE; double minValue = Double.MAX_VALUE; for (int i = 0; i < nbHash; i++) { if (ratio[h[i]] < minValue) { minValue = ratio[h[i]]; minIndex = h[i]; } } return minIndex; }
private void checkOnAbsentFalsePositive(int hashId, int numInsertions, final RetouchedBloomFilter filter, Digits digits, short removeSchema) { AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000 .get(hashId); if (falsePositives == null) Assert.fail(String.format("false positives for hash %d not founded", hashId)); filter.addFalsePositive(falsePositives); for (int i = digits.getStart(); i < numInsertions; i += 2) { filter.add(new Key(Integer.toString(i).getBytes())); } for (Key key : falsePositives) { filter.selectiveClearing(key, removeSchema); } for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) { assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i, filter.membershipTest(new Key(Integer.toString(i).getBytes()))); } }
/** * Constructor * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash function to consider. * @param hashType type of the hashing function (see * {@link org.apache.hadoop.util.hash.Hash}). */ public RetouchedBloomFilter(int vectorSize, int nbHash, int hashType) { super(vectorSize, nbHash, hashType); this.rand = null; createVector(); }
private void checkOnAbsentFalsePositive(int hashId, int numInsertions, final RetouchedBloomFilter filter, Digits digits, short removeSchema) { AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000 .get(hashId); if (falsePositives == null) Assert.fail(String.format("false positives for hash %d not founded", hashId)); filter.addFalsePositive(falsePositives); for (int i = digits.getStart(); i < numInsertions; i += 2) { filter.add(new Key(Integer.toString(i).getBytes())); } for (Key key : falsePositives) { filter.selectiveClearing(key, removeSchema); } for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) { assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i, filter.membershipTest(new Key(Integer.toString(i).getBytes()))); } }
/** * Chooses the bit position that minimizes the number of false negative generated. * @param h The different bit positions. * @return The position that minimizes the number of false negative generated. */ private int minimumFnRemove(int[] h) { int minIndex = Integer.MAX_VALUE; double minValue = Double.MAX_VALUE; for (int i = 0; i < nbHash; i++) { double keyWeight = getWeight(keyVector[h[i]]); if (keyWeight < minValue) { minIndex = h[i]; minValue = keyWeight; } } return minIndex; }
@Override public void readFields(DataInput in) throws IOException { super.readFields(in); createVector(); for (int i = 0; i < fpVector.length; i++) { List<Key> list = fpVector[i]; int size = in.readInt(); for (int j = 0; j < size; j++) { Key k = new Key(); k.readFields(in); list.add(k); } } for (int i = 0; i < keyVector.length; i++) { List<Key> list = keyVector[i]; int size = in.readInt(); for (int j = 0; j < size; j++) { Key k = new Key(); k.readFields(in); list.add(k); } } for (int i = 0; i < ratio.length; i++) { ratio[i] = in.readDouble(); } } }
if (!membershipTest(k)) { throw new IllegalArgumentException("Key is not a member"); index = randomRemove(); break; index = minimumFnRemove(h); break; index = maximumFpRemove(h); break; index = ratioRemove(h); break; clearBit(index);
/** * Adds an array of false positive information to <i>this</i> retouched Bloom filter. * @param keys The array of false positive. */ public void addFalsePositive(Key[] keys) { if (keys == null) { throw new NullPointerException("Key[] can not be null"); } for (int i = 0; i < keys.length; i++) { addFalsePositive(keys[i]); } }
/** * Chooses the bit position that maximizes the number of false positive removed. * @param h The different bit positions. * @return The position that maximizes the number of false positive removed. */ private int maximumFpRemove(int[] h) { int maxIndex = Integer.MIN_VALUE; double maxValue = Double.MIN_VALUE; for (int i = 0; i < nbHash; i++) { double fpWeight = getWeight(fpVector[h[i]]); if (fpWeight > maxValue) { maxValue = fpWeight; maxIndex = h[i]; } } return maxIndex; }
/** * Constructor * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash function to consider. * @param hashType type of the hashing function (see * {@link org.apache.hadoop.util.hash.Hash}). */ public RetouchedBloomFilter(int vectorSize, int nbHash, int hashType) { super(vectorSize, nbHash, hashType); this.rand = null; createVector(); }
/** * Chooses the bit position that minimizes the number of false negative generated while maximizing. * the number of false positive removed. * @param h The different bit positions. * @return The position that minimizes the number of false negative generated while maximizing. */ private int ratioRemove(int[] h) { computeRatio(); int minIndex = Integer.MAX_VALUE; double minValue = Double.MAX_VALUE; for (int i = 0; i < nbHash; i++) { if (ratio[h[i]] < minValue) { minValue = ratio[h[i]]; minIndex = h[i]; } } return minIndex; }
if (!membershipTest(k)) { throw new IllegalArgumentException("Key is not a member"); index = randomRemove(); break; index = minimumFnRemove(h); break; index = maximumFpRemove(h); break; index = ratioRemove(h); break; clearBit(index);
/** * Adds a collection of false positive information to <i>this</i> retouched Bloom filter. * @param coll The collection of false positive. */ public void addFalsePositive(Collection<Key> coll) { if (coll == null) { throw new NullPointerException("Collection<Key> can not be null"); } for (Key k : coll) { addFalsePositive(k); } }
/** * Constructor * @param vectorSize The vector size of <i>this</i> filter. * @param nbHash The number of hash function to consider. * @param hashType type of the hashing function (see * {@link org.apache.hadoop.util.hash.Hash}). */ public RetouchedBloomFilter(int vectorSize, int nbHash, int hashType) { super(vectorSize, nbHash, hashType); this.rand = null; createVector(); }
/** * Chooses the bit position that minimizes the number of false negative generated while maximizing. * the number of false positive removed. * @param h The different bit positions. * @return The position that minimizes the number of false negative generated while maximizing. */ private int ratioRemove(int[] h) { computeRatio(); int minIndex = Integer.MAX_VALUE; double minValue = Double.MAX_VALUE; for (int i = 0; i < nbHash; i++) { if (ratio[h[i]] < minValue) { minValue = ratio[h[i]]; minIndex = h[i]; } } return minIndex; }
if (!membershipTest(k)) { throw new IllegalArgumentException("Key is not a member"); index = randomRemove(); break; index = minimumFnRemove(h); break; index = maximumFpRemove(h); break; index = ratioRemove(h); break; clearBit(index);