/// <summary> /// instanciate a new bloom filter with a the specified bit count /// the maximum allowed bits for this implementation is 2^32. /// a chunk of memory the size of bitCount is allocated imidiatly after calling this constructor. /// </summary> /// <param name="bitCount">the amount of bits used by this bloom filter. all memory is allocated imidiatly</param> /// <param name="hashFunction">The hash function used by this bloom filter</param> /// <param name="totalHashes">the number of hashes for each opertation in this filter. this value /// must be lower than or equal to hashFunction.HashCount</param> public ConcurrentBloomFilter(ulong bitCount, IKHashFunction <uint> hashFunction, int totalHashes) { if (hashFunction == null) { hashFunction = new RehashKHashFunction <uint>(new FNV1A32HashFunction()); // the default hash function is FNV1A } if (totalHashes > hashFunction.HashCount) { throw new IndexOutOfRangeException("totalHashes is to large for the provided hashFunction"); } mHashes = totalHashes; mHashFunction = hashFunction; if (bitCount > uint.MaxValue) { throw new OutOfMemoryException("This implementation of bloom's filter is limited to a max of 2^32 bits"); } mBitCount = (uint)bitCount; uint dataSize = (mBitCount / BitsPerArrayItem) + 1; mData = new int[dataSize]; }
/// <summary> /// instanciate a new bloom filter with an intented capacity and with specified number of bits per element /// the maximum allowed bits for this implementation is 2^32. so capacity*bitsPerElement must be under 2^32. /// a chunk of memory the size of capacity*bitsPerElement is allocated imidiatly after calling this constructor. /// </summary> /// <param name="capacity">the intended amount of elements for this bloom filter. all memory is allocated imidiatly</param> /// <param name="bitsPerElement">the number of bits for each element of this bloom filter</param> /// <param name="hashFunction">The hash function used by this bloom filter</param> /// <param name="totalHashes">the number of hashes for each opertation in this filter. this value /// must be lower than or equal to hashFunction.HashCount</param> public ConcurrentBloomFilter(int capacity, int bitsPerElement, IKHashFunction <uint> hashFunction, int totalHashes) : this(((ulong)capacity) * ((ulong)bitsPerElement), hashFunction, totalHashes) { }