Spaces:
Running
Running
File size: 2,202 Bytes
ef8334d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # SinceKit for Python
Use one native index to plan latest-state delivery to Python simulation workers. The checkout includes the C++17 headers. Building requires standard CPython 3.9+, its development headers, a C++17 compiler and setuptools. Run from the repository root.
```sh
cd python
python3 setup.py build_ext --inplace
python3 -m unittest -v test_binding
```
The resulting module imports from this directory. To install into the active environment from here using an existing pip and setuptools/wheel installation, run `python3 -m pip install --no-index --no-build-isolation --no-deps .`.
```python
from sincekit import Index
world = Index(10_000)
world.write_many([(42, False), (9, False), (42, True)])
plan = world.since_many([0, 2, 3])
assert plan.revision == 3
assert plan.rows == ((42, 3, True), (9, 2, False))
assert plan.prefix_lengths == (2, 1, 0)
```
`write_many` accepts an iterable of two-item tuples or lists. Each pair holds a dense slot ID and a deletion flag. `False` publishes a create or update and `True` publishes a tombstone. Repeated writes each advance the revision. Input parsing, range checks and return-value allocation finish before publication. Invalid input or an iterator error leaves the batch unapplied. Code inside caller-supplied iterators runs before the native call and may perform its own independent operations.
`since_many` takes an iterable of integer cursors from this instance. Zero starts at creation. Results are immutable and own their data. Rows hold `(slot_id, revision, deleted)` in descending revision order. For reader `i`, consume the first `plan.prefix_lengths[i]` rows and save `plan.revision` after successful delivery. Use `itertools.islice(plan.rows, n)` to iterate a prefix without copying the tuple. A call with zero readers returns an empty plan at the current revision.
Native calls hold the CPython GIL. Other Python threads see a complete write batch or an earlier one. A long call occupies the GIL while it validates inputs, performs index work and builds Python objects. Each process owns its own index. Group readers with the same access rights. Synchronize application payload snapshots and checkpoint updates separately.
|