Exemple #1
0
def setup(size, density):
    ''' Populated the table.

    :param int size: total entries
    :param float density: (0,1] value for how many entries to add.
    '''
    assert size > 0, size
    assert density > 0 and density <= 1, density
    global g_list
    global g_size
    global g_count
    g_list = [[None] * size for _ in range(size)]
    count = size * size * 1.0 * density // 1
    g_size = size
    g_count = count
    i = 0
    while i < count:
        idx = random.randint(0, size * size - 1)
        x, y = (idx // size, idx % size)
        if g_list[x][y] is None:
            g_list[x][y] = random_tuple()
            i += 1
    global g_get_keys
    for i in range(1000000):
        idx = random.randint(0, size * size - 1)
        g_get_keys.append((idx // size, idx % size))
    global g_set_keys
    g_set_keys = g_get_keys
Exemple #2
0
def setup(size, density):
    ''' Populated the table.

    :param int size: total entries
    :param float density: (0,1] value for how many entries to add.
    '''
    assert size > 0, size
    assert density > 0 and density <= 1, density
    global g_table
    global g_size
    global g_count
    count = size * size * 1.0 * density // 1
    g_size = size
    g_count = count
    i = 0
    while i < count:
        _idx = random.randint(0, size*size-1)
        _key = _idx // g_size, _idx % g_size
        if _key in g_table:
            continue
        g_table[_key] = random_tuple()
        i += 1
    # TODO (x): need fix the percentage of present keys.
    global g_get_keys
    for i in range(1000000):
        _idx = random.randint(0, size*size-1)
        _key = _idx // g_size, _idx % g_size
        g_get_keys.append(_key)
    global g_set_keys
    g_set_keys = g_get_keys
Exemple #3
0
def setup(size, density):
    ''' Populated the table.

    :param int size: total entries
    :param float density: (0,1] value for how many entries to add.
    '''
    global g_zero_tuple
    for _ in range(5):
        g_zero_tuple.int.append(0)

    assert size > 0, size
    assert density > 0 and density <= 1, density
    global g_list
    global g_size
    global g_count
    for _ in range(size):
        t = g_list.list.add()
        t.CopyFrom(g_zero_tuple)
    count = size * 1.0 * density // 1
    g_size = size
    g_count = count
    i = 0
    while i < count:
        _key = random.randint(0, size - 1)
        if is_zero(_key):
            g_list.list[_key].CopyFrom(list_to_pb_tuple(random_tuple()))
            i += 1
    global g_get_keys
    for i in range(1000000):
        g_get_keys.append(random.randint(0, size - 1))
    global g_set_keys
    g_set_keys = g_get_keys