/// <summary> /// Add a Bloom filter (union) /// </summary> /// <param name="bloomFilterData"></param> /// <remarks>Results in all keys from the filters.</remarks> public virtual void Add(IBloomFilterData bloomFilterData) { if (bloomFilterData == null) { return; } var foldedSize = _configuration.FoldingStrategy?.GetFoldFactors(_blockSize, bloomFilterData.BlockSize); if (bloomFilterData.BlockSize != BlockSize & foldedSize == null) { throw new ArgumentException("Bloom filters of different sizes cannot be added.", nameof(bloomFilterData)); } var otherBitArray = new FastBitArray(bloomFilterData.Bits ?? EmptyByteArray) { Length = (int)bloomFilterData.BlockSize }; if (foldedSize != null && (foldedSize.Item2 != 1 || foldedSize.Item1 != 1)) { if (foldedSize.Item1 != 1) { Fold((uint)foldedSize.Item1, true); } if (foldedSize.Item2 != 1) { for (var i = 0; i < _data.Length; i++) { _data.Set(i, _data.Get(i) | GetFolded(otherBitArray, i, (uint)foldedSize.Item2)); } ItemCount = ItemCount + bloomFilterData.ItemCount; return; } } _data = _data.Or(otherBitArray); ItemCount = ItemCount + bloomFilterData.ItemCount; }