Esempio n. 1
0
        /// <summary>
        /// Get the folded value at the given position
        /// </summary>
        /// <typeparam name="TCount">Type of the item</typeparam>
        /// <param name="values">The values</param>
        /// <param name="position">The position</param>
        /// <param name="blockSize">The block size of the unfolded Bloom filter</param>
        /// <param name="foldFactor">Factor to fold by</param>
        /// <param name="foldOperator">The operator to apply during folding</param>
        /// <returns></returns>
        internal static TCount GetFolded <TCount>(
            this ICompressedArray <TCount> values,
            long position,
            long blockSize,
            long foldFactor,
            Func <TCount, TCount, TCount> foldOperator)
            where TCount : struct
        {
            if (foldFactor <= 1L)
            {
                return(values[position]);
            }
            var foldedSize = blockSize / foldFactor;

            position = position % foldedSize;
            return(LongEnumerable.Range(1L, foldFactor)
                   .Aggregate(values[position],
                              (foldedValue, factor) => foldOperator(foldedValue, values[position + factor * foldedSize])));
        }
Esempio n. 2
0
 /// <summary>
 /// Set the counter provider.
 /// </summary>
 /// <param name="configuration"></param>
 public void SyncCompressionProviders(
     ICountingBloomFilterConfiguration <TId, THash, TCount> configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentException("Configuration is null", nameof(configuration));
     }
     if (_hasDirtyProvider)
     {
         _hasDirtyProvider = false;
         _membershipTest   = position => IsMember(configuration.CountConfiguration, this, position);
         _hashSumProvider  = configuration.CompressedArrayFactory.Create <THash>();
         _hashSumProvider.Load(_hashSums, BlockSize, _membershipTest);
         _hashSums      = null;
         _idSumProvider = configuration.CompressedArrayFactory.Create <TId>();
         _idSumProvider.Load(_idSums, BlockSize, _membershipTest);
         _idSums = null;
     }
 }