function it_denies_existence_of_items_not_in_set(BitField $bitField, MultiHash $multiHash) { $multiHash->hash('my string')->willReturn([1, 4]); $bitField->has(1)->willReturn(false); $bitField->has(4)->willReturn(true); $this->contains('my string')->shouldReturn(false); }
/** * @param $expectedValues * @param float $falsePositiveProbability * @return BloomFilter */ public static function generate($expectedValues, $falsePositiveProbability = 0.1) { $sizeOfBitField = (int) ceil($expectedValues * log($falsePositiveProbability) / log(1 / pow(2, log(2)))); $hashFunctions = (int) ($sizeOfBitField / $expectedValues * log(2)); $multiHash = new MultiHash(new DJBX33X(), new FNVHash()); $multiHash->setUpperBound($sizeOfBitField); $multiHash->setHashCount($hashFunctions); return new BloomFilter(new BitField($sizeOfBitField), $multiHash); }