Example #1
0
        /// <summary>
        /// Creates a new special case of Stable Bloom Filter which is a traditional
        /// Bloom filter with m bits and an optimal number of hash functions for the
        /// target false-positive rate. Unlike the stable variant, data is not evicted
        /// and a cell contains a maximum of 1 hash value.
        /// </summary>
        /// <param name="m">Number of cells to decrement</param>
        /// <param name="fpRate">Desired false-positive rate</param>
        /// <returns></returns>
        public static StableBloomFilter NewUnstableBloomFilter(uint m, double fpRate)
        {
            var cells = new Buckets(m, 1);
            var k     = Utils.OptimalK(fpRate);

            return(new StableBloomFilter
            {
                Hash = Defaults.GetDefaultHashAlgorithm(),
                M = m,
                k = k,
                p = 0,
                Max = cells.MaxBucketValue(),
                cells = cells,
                IndexBuffer = new uint[k]
            });
        }
Example #2
0
        /// <summary>
        /// Creates a new Stable Bloom Filter with m cells and d bits allocated per cell
        /// optimized for the target false-positive rate. Use NewDefaultStableFilter if
        /// you don't want to calculate d.
        /// </summary>
        /// <param name="m">Number of cells to decrement</param>
        /// <param name="d">Bits per cell</param>
        /// <param name="fpRate">Desired false-positive rate</param>
        public StableBloomFilter(uint m, byte d, double fpRate)
        {
            var k = Utils.OptimalK(fpRate) / 2;

            if (k > m)
            {
                k = m;
            }
            else if (k <= 0)
            {
                k = 1;
            }

            var cells = new Buckets(m, d);

            this.Hash        = Defaults.GetDefaultHashAlgorithm();
            this.M           = m;
            this.k           = k;
            this.p           = OptimalStableP(m, k, d, fpRate);
            this.Max         = cells.MaxBucketValue();
            this.cells       = cells;
            this.IndexBuffer = new uint[k];
        }