Beispiel #1
0
        public void Add(long item)
        {
            var bytes = ToBytes(item);
            var hash1 = (int)Hasher1.Hash(bytes);
            var hash2 = (int)Hasher2.Hash(bytes);

            var hash = hash1;

            for (var i = 0; i < _numHashFunctions; i++)
            {
                hash += hash2;
                hash &= int.MaxValue; //make positive
                var idx = (hash % _numBits);
                _bits[idx / LongSize] |= (1UL << (idx % LongSize));
            }
        }
Beispiel #2
0
        public bool MayExist(long item)
        {
            var bytes = ToBytes(item);
            var hash1 = (int)Hasher1.Hash(bytes);
            var hash2 = (int)Hasher2.Hash(bytes);

            var hash = hash1;

            for (var i = 0; i < _numHashFunctions; i++)
            {
                hash += hash2;
                hash &= int.MaxValue; //make positive
                var idx = (hash % _numBits);
                if ((_bits[idx / LongSize] & (1UL << (idx % LongSize))) == 0)
                {
                    return(false);
                }
            }

            return(true);
        }