File size: 955 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
30
31
32
33
"""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)))