Exemplo n.º 1
0
def test_frequency():
    cms = CountMinSketch(4, 100)

    cms.add("test")
    assert cms.frequency("test") == 1, "Can't find recently added element"
    assert cms.frequency("test_test") == 0, "False positive detected"
Exemplo n.º 2
0
    21,
    9,
    29,
    6,
    5,
    2,
    3,
    1,
    16,
    17,
    15,
    5,
    3,
    6,
    9,
    12,
]

if __name__ == '__main__':
    cms = CountMinSketch(4, 100)

    print(cms)
    print("CMS uses {} bytes in the memory".format(cms.sizeof()))

    for digit in DATASET:
        cms.add(digit)

    for digit in sorted(set(DATASET)):
        print("Element: {}. Freq.: {}, Est. Freq.: {}".format(
            digit, DATASET.count(digit), cms.frequency(digit)))
Exemplo n.º 3
0
def test_add():
    cms = CountMinSketch(4, 100)

    for word in ["test", 1, {"hello": "world"}]:
        cms.add(word)
        assert cms.frequency(word) == 1, "Can't find frequency for element"