Class ConcurrentRollingBloomFilter<T>

  • All Implemented Interfaces:
    BloomFilter<T>

    @ThreadSafe
    public final class ConcurrentRollingBloomFilter<T>
    extends Object
    implements BloomFilter<T>

    A thread-safe implementation of a Bloom Filter that can expand over time to accommodate arbitrary numbers of elements, while also allowing old elements to be deleted after they have expired. Rolling bloom filters are useful for maintaining on-going blacklists of short-lived elements.

    This implementation is optimised for concurrent read performance. Concurrent writes performance is likely to be considerably slower than reads, so this implementation is only suitable for situations where read performance is critical and writes are relatively rare. Write performance may be improved by batching writes via the addAll(Collection) method, or by using some external synchronisation mechanism to perform pre-emptive locking (at the cost of reducing read performance).

    • Method Detail

      • add

        public void add​(T element)
        Description copied from interface: BloomFilter
        Adds the specified element to this set if it is not already possibly present. After a call to this method, subsequent calls to BloomFilter.mightContain(Object) will return true for the same object.
        Specified by:
        add in interface BloomFilter<T>
        Parameters:
        element - the element to add to this set.
      • addAll

        public void addAll​(Collection<? extends T> elements)
        Description copied from interface: BloomFilter
        Adds all of the specified elements to this set if they are not possibly already present.
        Specified by:
        addAll in interface BloomFilter<T>
        Parameters:
        elements - the elements to add to the set.
      • mightContain

        public boolean mightContain​(T element)
        Description copied from interface: BloomFilter
        Checks if the given element might be a member of this set. If this method returns false, then the given object is definitely not a member of the set. If the result is true then the object may or may not be a member of this set, with a certain probability of false positives.
        Specified by:
        mightContain in interface BloomFilter<T>
        Parameters:
        element - the element to check for membership in this set.
        Returns:
        false if the element is definitely not in the set, or true if it might be.