コード例 #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
ファイル: test_counter.py プロジェクト: sota/pypy-old
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
ファイル: test_counter.py プロジェクト: Darriall/pypy
def test_get_index():
    jc = JitCounter(size=128)    # 7 bits
    for i in range(10):
        hash = 400000001 * i
        index = jc._get_index(hash)
        assert index == (hash >> (32 - 7))
コード例 #4
0
ファイル: test_counter.py プロジェクト: sota/pypy-old
def test_get_index():
    jc = JitCounter(size=128)  # 7 bits
    for i in range(10):
        hash = 400000001 * i
        index = jc._get_index(hash)
        assert index == (hash >> (32 - 7))