Class BloomFilter

java.lang.Object
model.logic.server.dictionary.BloomFilter

public class BloomFilter extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    BloomFilter(int size, String... hashingAlgorithms)
    The BloomFilter function is used to add elements to the filter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String word)
    The add function takes a string and hashes it using the message digesters.
    boolean
    The contains function takes a string and checks if it is in the Bloom Filter.
    The toString function returns a string representation of the bitset.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BloomFilter

      public BloomFilter(int size, String... hashingAlgorithms)
      The BloomFilter function is used to add elements to the filter.
      Parameters:
      size - size Set the size of the bitset
      hashingAlgorithms - hashingAlgorithms Pass in a variable number of arguments
  • Method Details

    • add

      public void add(String word)
      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

      public boolean contains(String word)
      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

      public String toString()
      The toString function returns a string representation of the bitset.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the bitset