mightContain method

bool mightContain(
  1. String item
)

Tests whether an item might be in the filter.

  • Returns false → the item is definitely not in the set.
  • Returns true → the item is probably in the set (with ~falsePositiveRate chance of being wrong).

Implementation

bool mightContain(String item) {
  if (isEmpty) return false;
  final hashes = _computeHashes(item);
  for (final h in hashes) {
    final bitIndex = h % _bitCount;
    if ((_bits[bitIndex ~/ 8] & (1 << (bitIndex % 8))) == 0) {
      return false; // Definitely not in set
    }
  }
  return true; // Probably in set
}