BloomFilter.NetCore icon indicating copy to clipboard operation
BloomFilter.NetCore copied to clipboard

Checking for bits set on Add?

Open ChiefInnovator opened this issue 4 years ago • 1 comments

I noticed that you check whether the bits were set on Add. Wouldn't it be better to just set the bits and not care about the results?

        lock (_sync)
        {
            for (var i = 0; i < hashes.Count; i++)
            {
                if (!_hashBits.Get(hashes[i]))
                {
                    _hashBits.Set(hashes[i], true);
                    processResults[i] = false;
                }
                else
                {
                    processResults[i] = true;
                }
            }
        }

ChiefInnovator avatar Aug 01 '21 13:08 ChiefInnovator

Single or multiple, it needs to be clear that the return value indicates whether it already exists.

secne 1

if(bf.Contains("value")){
  return;
}
 //logic
 bf.Add("value");

secne 2

if(!bf.Add("value")){
  return;
}
//logic

secne 3

if(!bf.Add(new []{"v1","v2"}).All()){
  return;
}
//logic

vla avatar Aug 04 '21 09:08 vla