java.lang.Object
model.logic.server.dictionary.BloomFilter
-
Constructor Summary
ConstructorsConstructorDescriptionBloomFilter(int size, String... hashingAlgorithms) The BloomFilter function is used to add elements to the filter. -
Method Summary
Modifier and TypeMethodDescriptionvoidThe add function takes a string and hashes it using the message digesters.booleanThe contains function takes a string and checks if it is in the Bloom Filter.toString()The toString function returns a string representation of the bitset.
-
Constructor Details
-
BloomFilter
The BloomFilter function is used to add elements to the filter.- Parameters:
size- size Set the size of the bitsethashingAlgorithms- hashingAlgorithms Pass in a variable number of arguments
-
-
Method Details
-
add
The add function takes a string and hashes it using the message digesters. It then sets the bits in the bitset to 1 at each of those hash values.- Parameters:
word- word Create a byte array that is then used to create a biginteger
-
contains
The contains function takes a string and checks if it is in the Bloom Filter. It does this by hashing the word with each of the hash functions, then taking that hash value modulo bitset size to get an index. If any of those indices are not set, then we know that word is not in our filter. Otherwise, we return true because there's a chance that it could be in our filter (but also might have been inserted into another Bloom Filter).- Parameters:
word- word Create a byte array, which is then used to generate the biginteger- Returns:
- True if the word is in the bloom filter, false otherwise
-
toString
The toString function returns a string representation of the bitset.
-