示例#1
0
def test_fetch_next_hash():
    jc = JitCounter(size=2048)
    # check the distribution of "fetch_next_hash() & ~7".
    blocks = [[jc.fetch_next_hash() & ~7 for i in range(65536)] for j in range(2)]
    for block in blocks:
        assert 0 <= jc._get_index(block[0]) < 2048
        assert 0 <= jc._get_index(block[-1]) < 2048
        assert 0 <= jc._get_index(block[2531]) < 2048
        assert 0 <= jc._get_index(block[45981]) < 2048
        # should be correctly distributed: ideally 2047 or 2048 different
        # values
        assert len(set([jc._get_index(x) for x in block])) >= 2040
    # check that the subkeys are distinct for same-block entries
    subkeys = {}
    for block in blocks:
        for x in block:
            idx = jc._get_index(x)
            subkeys.setdefault(idx, []).append(jc._get_subhash(x))
    collisions = 0
    for idx, sks in subkeys.items():
        collisions += len(sks) - len(set(sks))
    assert collisions < 5
示例#2
0
def test_fetch_next_hash():
    jc = JitCounter(size=2048)
    # check the distribution of "fetch_next_hash() & ~7".
    blocks = [[jc.fetch_next_hash() & ~7 for i in range(65536)]
              for j in range(2)]
    for block in blocks:
        assert 0 <= jc._get_index(block[0]) < 2048
        assert 0 <= jc._get_index(block[-1]) < 2048
        assert 0 <= jc._get_index(block[2531]) < 2048
        assert 0 <= jc._get_index(block[45981]) < 2048
        # should be correctly distributed: ideally 2047 or 2048 different
        # values
        assert len(set([jc._get_index(x) for x in block])) >= 2040
    # check that the subkeys are distinct for same-block entries
    subkeys = {}
    for block in blocks:
        for x in block:
            idx = jc._get_index(x)
            subkeys.setdefault(idx, []).append(jc._get_subhash(x))
    collisions = 0
    for idx, sks in subkeys.items():
        collisions += len(sks) - len(set(sks))
    assert collisions < 5
示例#3
0
def test_get_subhash():
    assert JitCounter._get_subhash(0x518ebd) == 0x8ebd
示例#4
0
def test_get_subhash():
    assert JitCounter._get_subhash(0x518ebd) == 0x8ebd