コード例 #1
0
def test_delete():
    bf = CountingBloomFilter(8000, 3)

    assert bf.remove("test") is False

    bf.add("test")
    assert bf.remove("test") is True, "Can't remove element"
    assert bf.remove("test") is False, "Element wasn't in fact removed"
コード例 #2
0
    " ut nunc porttitor pharetra in non lorem. In purus metus,"
    " sollicitudin tristique sapien.")

if __name__ == '__main__':
    bf = CountingBloomFilter(80000, 4)

    print(bf)
    print("Bloom filter uses {} bytes in the memory".format(bf.sizeof()))

    print("Filter contains approx. {} unique elements".format(bf.count()))

    print("'Lorem' {} in the filter".format(
        "is" if bf.test("Lorem") else "is not"))

    words = set(LOREM_IPSUM.split())
    for word in words:
        bf.add(word.strip(" .,"))

    print("Added {} words, in the filter approx. {} unique elements".format(
        len(words), bf.count()))

    print("'Lorem' {} in the filter".format(
        "is" if bf.test("Lorem") else "is not"))

    print("Delete 'Lorem' from the filter")
    bf.remove("Lorem")

    print("In the filter approximately {} elements".format(bf.count()))
    print("'Lorem' {} in the filter".format(
        "is" if bf.test("Lorem") else "is not"))