Пример #1
0
def _sorter(rows, key_calc, reverse, batch_size):
    db = KVFile()
    db.insert(((key_calc(row) + "{:08x}".format(row_num), row)
               for row_num, row in enumerate(rows)),
              batch_size=batch_size)

    for _, value in db.items(reverse=reverse):
        yield value
Пример #2
0
def _sorter(rows, key_calc, reverse, batch_size):
    db = KVFile()

    def process(rows):
        for row_num, row in enumerate(rows):
            key = key_calc(row) + '{:08x}'.format(row_num)
            yield (key, row)

    db.insert(process(rows), batch_size=batch_size)
    for _, value in db.items(reverse=reverse):
        yield value
Пример #3
0
def test_filename():
    from kvfile import KVFile, db_kind
    filename = 'bla.filename.' + db_kind + '.db'
    kv1 = KVFile(filename=filename)
    kv1.insert(((str(i), ':{}'.format(i)) for i in range(50000)))
    del kv1

    kv = KVFile(filename=filename)
    assert len(list(kv.keys())) == 50000
    assert len(list(kv.items())) == 50000
    assert kv.get('49999') == ':49999'
Пример #4
0
def test_insert():
    from kvfile import KVFile
    kv = KVFile()
    kv.insert(((str(i), ':{}'.format(i)) for i in range(50000)))
    assert len(list(kv.keys())) == 50000
    assert len(list(kv.items())) == 50000
    assert kv.get('49999') == ':49999'

    kv.insert(((str(i), ':{}'.format(i)) for i in range(50000, 100000)),
              batch_size=40000)
    assert len(list(kv.items())) == 100000

    kv.insert(((str(i), ':{}'.format(i)) for i in range(100000, 100002)),
              batch_size=1)
    kv.insert(((str(i), ':{}'.format(i)) for i in range(100002, 100005)),
              batch_size=0)
    assert len(list(kv.items())) == 100005