src/coordinator/CursorCountPolicy.bend
mylsm-lsm-store@0.6.0.0 · 29 lines · 0 definitions
1import Base
2import mylsm-lsm-store@0.6.0.0/src/coordinator/Protocol.bend as Protocol
3
4# Reports one representable count update or exhaustion of the backup format.
5type Decision is Data:
6 CountContinue{next_count: U32}
7 CountLimit{}
8
9# Increments a cursor count without wrapping its fixed-width representation.
10def next.checked(count: U32, maximum: Bool) -> Decision:
11 match maximum:
12 case True{}: CountLimit{}
13 case False{}: CountContinue{U32.from_nat(Nat.add(U32.to_nat(count), 1n))}
14
15def next.copies(copies: U32 & U32 & U32) -> Decision:
16 match copies:
17 case (retained, (checked, _)):
18 next.checked(retained, U32.is_eq(checked, 4294967295))
19
20# Advances a cursor count without wrapping past its representable limit.
21def next(count: U32) -> Decision:
22 next.copies(Protocol.u32.duplicate.triple(count))
23
24def u32.pair.copied(copies: U32 & U32 & U32) -> U32 & U32:
25 match copies:
26 case (first, (second, _)): (first, second)
27
28def u32.pair(value: U32) -> U32 & U32:
29 u32.pair.copied(Protocol.u32.duplicate.triple(value))