/// <summary> /// Adds the specified item to the filter /// </summary> /// <param name="item">The item.</param> /// <returns>Returns true if this item was already in the set</returns> public bool Add(T item) { Count++; bool b = true; int hash = hashGenerator.Invoke(item); for (int i = 0; i < KeyCount; i++) { unsafe { hash++; int index = BloomFilter <T> .GetIndex(hash, array.Length); if (array[index] == byte.MaxValue) { for (int r = i - 1; r >= 0; r--) { hash--; array[BloomFilter <T> .GetIndex(hash, array.Length)]--; } throw new OverflowException("Bloom filter overflowed"); } if (array[index]++ == 0) { b = false; } } } return(b); }
/// <summary> /// Adds the specified item to the filter /// </summary> /// <param name="item">The item.</param> /// <returns>Returns true if this item was already in the set</returns> public bool Add(T item) { bool b = true; int hash = _hashGenerator.Invoke(item); for (int i = 0; i < _keyCount; i++) { hash++; int index = BloomFilter <T> .GetIndex(hash, Array.Length); if (Array[index] == byte.MaxValue) { //Rollback changes for (int r = i - 1; r >= 0; r--) { hash--; Array[BloomFilter <T> .GetIndex(hash, Array.Length)]--; } throw new OverflowException("Bloom filter overflowed"); } if (Array[index]++ == 0) { b = false; } } Count++; return(b); }