Ejemplo n.º 1
0
        /// <summary>
        /// Creates an empty filter with the given parameters.
        /// The <see cref="Parameters.NumberOfBits"/> specifies the final size of the filter.
        /// </summary>
        public BloomFilter(Parameters parameters)
        {
            Contract.Requires(parameters != null);

            m_bits       = new ConcurrentBitArray(parameters.NumberOfBits);
            m_parameters = parameters;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Modifies the current bit array to be the bit-wise intersect with the given bit array
        /// </summary>
        /// <param name="other">the bit array to intersect with</param>
        /// <returns>the current modified bit array</returns>
        public ConcurrentBitArray And(ConcurrentBitArray other)
        {
            Contract.Requires(other != null && other.Length == Length);

            var array = m_array;

            for (int i = 0; i < array.Length; i++)
            {
                bool updated    = false;
                int  otherValue = Volatile.Read(ref other.m_array[i]);

                while (!updated)
                {
                    var oldValue = Volatile.Read(ref array[i]);
                    var newValue = oldValue & otherValue;
                    updated = Interlocked.CompareExchange(ref array[i], newValue, oldValue) == oldValue;
                }
            }

            return(this);
        }