Skip to content

Commit

Permalink
Support return value for BloomFilter.add() which indicates whether bi…
Browse files Browse the repository at this point in the history
…ts were changed by the add.
  • Loading branch information
kuujo committed Feb 22, 2015
1 parent dc11989 commit 1d0ce19
Showing 1 changed file with 10 additions and 6 deletions.
Expand Up @@ -79,22 +79,26 @@ private static int[] indexes(byte[] bytes, int numHashes, int bits) {
* Adds a byte array value to the bloom filter.
*
* @param bytes The byte array to add.
* @return The bloom filter.
* @return Indicates whether the filter's bits changed.
*/
public BloomFilter<T> add(byte[] bytes) {
public boolean add(byte[] bytes) {
boolean changed = false;
for (int index : indexes(bytes, numHashes, numBits)) {
bits.set(index, true);
if (bits.get(index)) {
bits.set(index, true);
changed = true;
}
}
return this;
return changed;
}

/**
* Adds a value to the bloom filter.
*
* @param value The value to add.
* @return The bloom filter.
* @return Indicates whether the filter's bits changed.
*/
public BloomFilter<T> add(T value) {
public boolean add(T value) {
return add(value.toString().getBytes());
}

Expand Down

0 comments on commit 1d0ce19

Please sign in to comment.