"""In-process latest-state changefeed, backed by the native SinceKit index.""" from collections import namedtuple import _sincekit BatchPlan = namedtuple("BatchPlan", ["revision", "rows", "prefix_lengths"]) class Index: """A fixed-capacity index of dense integer slots.""" __slots__ = ("_index",) def __init__(self, capacity): self._index = _sincekit.create(capacity) @property def capacity(self): return _sincekit.capacity(self._index) @property def revision(self): return _sincekit.revision(self._index) def write_many(self, changes): """Publish (slot_id, deleted_bool) pairs in order and return the revision.""" return _sincekit.write_many(self._index, tuple(changes)) def since_many(self, cursors): """Return an immutable plan with shared rows and a prefix length per cursor.""" return BatchPlan(*_sincekit.since_many(self._index, tuple(cursors)))