d6f69eff0534c66a3ce04193d9cee27a08975ed7 — Amirouche 11 months ago 51a155c dev
2 files changed, 16 insertions(+), 1 deletions(-)

M found/nstore.py
M found/vnstore.py
M found/nstore.py => found/nstore.py +10 -1
@@ 42,7 42,10 @@ def combinations(tab):

def ok(solutions, tab):
    """Check that SOLUTIONS of TAB is a correct solution"""
    """Check that SOLUTIONS is a possible set of permutations of columns
    of TAB that allow to query any pattern of TAB in hop.

    cx = combinations(tab)

    for combination in cx:

@@ 60,6 63,11 @@ def ok(solutions, tab):

def _compute_indices(n):
    # I do not understand the algorithm, it gives a good result
    # according to the above function called `ok`.
    # ref: https://stackoverflow.com/a/55148433/140837

    tab = list(range(n))
    cx = list(itertools.combinations(tab, n // 2))
    for c in cx:

@@ 117,6 125,7 @@ def make(name, prefix, n):
    return _NStore(name, tuple(prefix), n, list(_compute_indices(n)))

# TODO: rename `add` to `set`
def add(tx, nstore, *items, value=b''):
    assert len(items) == nstore.n, "invalid item count"
    for subspace, index in enumerate(nstore.indices):

M found/vnstore.py => found/vnstore.py +6 -0
@@ 56,6 56,7 @@ def make(self, subspace, n):
        nstore.open('tuples', subspace + ['tuples'], n + 1),

def change_create(tx, vnstore):
    changeid = uuid4()
    # When significance is `None` the change is skipped by

@@ 64,6 65,7 @@ def change_create(tx, vnstore):
    nstore.add(tx, vnstore.history, changeid, 'message', None)
    return changeid

def change_message(tx, vnstore, changeid, message):
    # If there is an existing message, remove it.
    bindings = nstore.query(tx, vnstore.history, changeid, 'message', nstore.var('message'))

@@ 74,11 76,13 @@ def change_message(tx, vnstore, changeid, message):
    # Add message
    nstore.add(tx, vnstore.history, changeid, 'message', message)

def change_apply(tx, vnstore, changeid):
    # apply change by settings a verionstamp
    nstore.remove(tx, vnstore.history, changeid, 'significance', None)
    nstore.add(tx, vnstore.history, changeid, 'significance', found.Versionstamp())

def ask(tx, vnstore, *items):
    assert len(items) == vnstore.n, "Incorrect count of ITEMS"
    # Complexity is at least O(n), where n is the number of times the

@@ 115,6 119,7 @@ def add(vnstore, tx, change_id, *items):
    self._tuples.add(tr, *items, value=value)
    return True

def delete(tx, vnstore, change_id, *items):
    assert len(items) == vnstore.n
    if not ask(tx, vnstore, *items):

@@ 126,6 131,7 @@ def delete(tx, vnstore, change_id, *items):
    self._tuples.add(tr, *items, value=value)
    return True

def _from(self, tr, *pattern, seed=Map()):  # seed is immutable
    """Yields bindings that match PATTERN"""
    assert len(pattern) == len(self._items), "invalid item count"