def get(self, id, pk='id', deleted=False):
        try:
            if pk == 'id':
                id = int(id)
            if deleted:
                spec = {pk: id}
            else:
                spec = {pk: id, 'data': {'$exists': 1}}
            fields = {'_id': 0}
            row = self.db.docs.find_one(spec, fields)
        except Exception as e:
            raise DatabaseException(e)
        if row:
            return Document(**row)
        raise NotFoundError('%s %s not found' % (pk, id))
def test():
    start = time.time()
    treap = None
    s = set()
    for i in range(100000):
        key = random.randint(0, 10000)
        if random.randint(0, 1) == 0:
            if key in s:
                treap = remove(treap, key)
                s.remove(key)
        elif key not in s:
            treap = insert(treap, key)
            s.add(key)
        assert len(s) == size(treap)

    for i in range(size(treap)):
        assert kth(treap, i) in s
    print(time.time() - start)