BloomFilter
public struct BloomFilter<T: BloomFilterType>
A Bloom filter is a probabilistic set designed to check rapidly and memory-efficiently, whether an element is definitely not in the set or may be in the set. The false positive probability is provided at construction time.
Inserted elements must conform to the BloomFilterType
protocol. Types already conforming to the
protocol include, but are not limited to: Int
, Double
and String
.
-
Creates a Bloom filter with the expected number of elements and a default false positive probability of 3%. Inserting significantly more elements than specified will result a deterioration of the false positive probability.
Declaration
Swift
public init(expectedCount: Int)
-
Creates a Bloom filter with the expected number of elements and expected false positive probability. Inserting significantly more elements than specified will result in a deterioration of the false positive probability.
Declaration
Swift
public init(expectedCount: Int, FPP: Double)
-
The expected false positive probability. In other words, the probability that
contains()
will erroneously return true.Declaration
Swift
public let FPP: Double
-
Returns the approximated number of elements in the bloom filter.
Declaration
Swift
public var roughCount: Int
-
Returns
true
if no element has been inserted into the Bloom filter.Declaration
Swift
public var isEmpty: Bool
-
Returns
true
if the given element might be in the Bloom filter or false if it’s definitely not.Declaration
Swift
public func contains(_ element: T) -> Bool
-
Inserts an element into the Bloom filter. All subsequent calls to
contains()
with the same element will return true.Declaration
Swift
public mutating func insert(_ element: T)
-
Removes all the elements from the Bloom filter.
Declaration
Swift
public mutating func removeAll()