Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the bloom filter with a manual number of hashes.
        /// </summary>
        /// <param name="bitSize">Size of the bloom filter in bits (m)</param>
        /// <param name="setSize">Size of the set (n)</param>
        /// <param name="numberOfHashes">Number of hashing functions (k)</param>
        /// <param name="hashFuncFactory">Hashing function factory</param>
        public BloomFilter(int bitSize, int setSize, int numberOfHashes, HashFunctionFactory <T> hashFuncFactory)
        {
            BitSize        = bitSize;
            SetSize        = setSize;
            NumberOfHashes = numberOfHashes;

            this.bitArray        = new BitArray(bitSize);
            this.hashFuncFactory = hashFuncFactory;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Import from an existing bloom filter
        /// </summary>
        /// <param name="filter">Bytes from the existing bloom filter</param>
        /// <param name="setSize">Size of the set (n)</param>
        /// <param name="numberOfHashes">Number of hashing functions (k)</param>
        /// <param name="hashFuncFactory">Hashing function factory</param>
        public BloomFilter(byte[] filter, int setSize, int numberOfHashes, HashFunctionFactory <T> hashFuncFactory)
        {
            BitSize        = filter.Length * BitsInByte;
            SetSize        = setSize;
            NumberOfHashes = numberOfHashes;

            this.bitArray        = new BitArray(BitSize);
            this.hashFuncFactory = hashFuncFactory;

            for (int ind = 0; ind < filter.Length; ind++)
            {
                for (int bit = 0; bit < BitsInByte; bit++)
                {
                    this.bitArray[ind * BitsInByte + bit] = (filter[ind] & (1 << (BitsInByte - 1 - bit))) != 0;
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes the bloom filter and sets the optimal number of hashes.
 /// </summary>
 /// <param name="bitSize">Size of the bloom filter in bits (m)</param>
 /// <param name="setSize">Size of the set (n)</param>
 /// <param name="hashFuncFactory">Hashing function factory</param>
 public BloomFilter(int bitSize, int setSize, HashFunctionFactory <T> hashFuncFactory) : this(bitSize, setSize, OptimalNumberOfHashes(bitSize, setSize), hashFuncFactory)
 {
 }