Interface BloomFilter

  • All Known Implementing Classes:
    BlockSplitBloomFilter

    public interface BloomFilter
    A Bloom filter is a compact structure to indicate whether an item is not in a set or probably in a set. The Bloom filter usually consists of a bit set that represents a elements set, a hash strategy and a Bloom filter algorithm.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default boolean canMergeFrom​(BloomFilter otherBloomFilter)
      Determines whether a given Bloom filter can be merged into this Bloom filter.
      boolean equals​(Object object)
      Compare this Bloom filter to the specified object.
      boolean findHash​(long hash)
      Determine whether an element is in set or not.
      BloomFilter.Algorithm getAlgorithm()
      Return the algorithm that the bloom filter apply.
      int getBitsetSize()
      Get the number of bytes for bitset in this Bloom filter.
      BloomFilter.Compression getCompression()
      Return the compress algorithm that the bloom filter apply.
      BloomFilter.HashStrategy getHashStrategy()
      Return the hash strategy that the bloom filter apply.
      long hash​(double value)
      Compute hash for double value by using its plain encoding result.
      long hash​(float value)
      Compute hash for float value by using its plain encoding result.
      long hash​(int value)
      Compute hash for int value by using its plain encoding result.
      long hash​(long value)
      Compute hash for long value by using its plain encoding result.
      long hash​(Object value)
      Compute hash for Object value by using its plain encoding result.
      long hash​(Binary value)
      Compute hash for Binary value by using its plain encoding result.
      void insertHash​(long hash)
      Insert an element to the Bloom filter, the element content is represented by the hash value of its plain encoding result.
      default void merge​(BloomFilter otherBloomFilter)
      Merges this Bloom filter with another Bloom filter by performing a bitwise OR of the underlying bitsets
      void writeTo​(OutputStream out)
      Write the Bloom filter to an output stream.
    • Method Detail

      • writeTo

        void writeTo​(OutputStream out)
              throws IOException
        Write the Bloom filter to an output stream. It writes the Bloom filter header including the bitset's length in bytes, the hash strategy, the algorithm, and the bitset.
        Parameters:
        out - the output stream to write
        Throws:
        IOException
      • insertHash

        void insertHash​(long hash)
        Insert an element to the Bloom filter, the element content is represented by the hash value of its plain encoding result.
        Parameters:
        hash - the hash result of element.
      • findHash

        boolean findHash​(long hash)
        Determine whether an element is in set or not.
        Parameters:
        hash - the hash value of element plain encoding result.
        Returns:
        false if element is must not in set, true if element probably in set.
      • getBitsetSize

        int getBitsetSize()
        Get the number of bytes for bitset in this Bloom filter.
        Returns:
        The number of bytes for bitset in this Bloom filter.
      • equals

        boolean equals​(Object object)
        Compare this Bloom filter to the specified object.
        Overrides:
        equals in class Object
        Parameters:
        object -
        Returns:
        true if the given object represents a Bloom filter equivalent to this Bloom filter, false otherwise.
      • hash

        long hash​(int value)
        Compute hash for int value by using its plain encoding result.
        Parameters:
        value - the value to hash
        Returns:
        hash result
      • hash

        long hash​(long value)
        Compute hash for long value by using its plain encoding result.
        Parameters:
        value - the value to hash
        Returns:
        hash result
      • hash

        long hash​(double value)
        Compute hash for double value by using its plain encoding result.
        Parameters:
        value - the value to hash
        Returns:
        hash result
      • hash

        long hash​(float value)
        Compute hash for float value by using its plain encoding result.
        Parameters:
        value - the value to hash
        Returns:
        hash result
      • hash

        long hash​(Binary value)
        Compute hash for Binary value by using its plain encoding result.
        Parameters:
        value - the value to hash
        Returns:
        hash result
      • hash

        long hash​(Object value)
        Compute hash for Object value by using its plain encoding result.
        Parameters:
        value - the value to hash
        Returns:
        hash result
      • getHashStrategy

        BloomFilter.HashStrategy getHashStrategy()
        Return the hash strategy that the bloom filter apply.
        Returns:
        hash strategy that the bloom filter apply
      • getAlgorithm

        BloomFilter.Algorithm getAlgorithm()
        Return the algorithm that the bloom filter apply.
        Returns:
        algorithm that the bloom filter apply
      • getCompression

        BloomFilter.Compression getCompression()
        Return the compress algorithm that the bloom filter apply.
        Returns:
        compress algorithm that the bloom filter apply
      • canMergeFrom

        default boolean canMergeFrom​(BloomFilter otherBloomFilter)
        Determines whether a given Bloom filter can be merged into this Bloom filter. For two Bloom filters to merge, they must:
        • have the same bit size
        • have the same algorithm
        • have the same hash strategy
        Parameters:
        otherBloomFilter - The Bloom filter to merge this Bloom filter with.
      • merge

        default void merge​(BloomFilter otherBloomFilter)
                    throws IOException
        Merges this Bloom filter with another Bloom filter by performing a bitwise OR of the underlying bitsets
        Parameters:
        otherBloomFilter - The Bloom filter to merge this Bloom filter with.
        Throws:
        IOException