예제 #1
0
 /// <summary>
 /// <c>true</c> when the filters are compatible, else <c>false</c>
 /// </summary>
 /// <typeparam name="TId">The type of entity identifier</typeparam>
 /// <typeparam name="TCount">The type of the occurence counter for the invertible Bloom filter.</typeparam>
 /// <typeparam name="TEntity">Type of the entity</typeparam>
 /// <param name="filter">Bloom filter data</param>
 /// <param name="otherFilter">The Bloom filter data to compare against</param>
 /// <param name="configuration">THe Bloom filter configuration</param>
 /// <returns></returns>
 public static bool IsCompatibleWith <TEntity, TId, THash, TCount>(
     this IInvertibleBloomFilterData <TId, THash, TCount> filter,
     IInvertibleBloomFilterData <TId, THash, TCount> otherFilter,
     IInvertibleBloomFilterConfiguration <TEntity, TId, THash, TCount> configuration)
     where TId : struct
     where TCount : struct
     where THash : struct
 {
     if (filter == null || otherFilter == null)
     {
         return(true);
     }
     if (!filter.IsValid() || !otherFilter.IsValid())
     {
         return(false);
     }
     if (filter.IsReverse != otherFilter.IsReverse ||
         filter.HashFunctionCount != otherFilter.HashFunctionCount ||
         (filter.SubFilter != otherFilter.SubFilter &&
          !filter.SubFilter.IsCompatibleWith(otherFilter.SubFilter, configuration.SubFilterConfiguration)))
     {
         return(false);
     }
     if (filter.BlockSize != otherFilter.BlockSize)
     {
         var foldFactors = configuration.FoldingStrategy?.GetFoldFactors(filter.BlockSize, otherFilter.BlockSize);
         if (foldFactors?.Item1 > 1 || foldFactors?.Item2 > 1)
         {
             return(true);
         }
     }
     return(filter.BlockSize == otherFilter.BlockSize &&
            filter.IsReverse == otherFilter.IsReverse &&
            filter.Counts?.LongLength == otherFilter.Counts?.LongLength);
 }
예제 #2
0
 /// <summary>
 /// Set the data for this Bloom filter.
 /// </summary>
 /// <param name="data">The data to restore</param>
 public virtual void Rehydrate(IInvertibleBloomFilterData <TId, int, TCount> data)
 {
     if (data == null)
     {
         return;
     }
     if (!data.IsValid())
     {
         throw new ArgumentException(
                   "Invertible Bloom filter data is invalid.",
                   nameof(data));
     }
     Data = data.ConvertToBloomFilterData(Configuration);
     ValidateData();
 }