Skip to content

Commit 671dc62

Browse files
author
Cole Miller
committed
Specify initial ring buffer contents when rolling
This allows us to remove the restriction `S_min >= W`, since the checksum values produced before `W` bytes have been consumed are now precisely determined.
1 parent 921c8de commit 671dc62

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

spec.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ $\operatorname{SPLIT}_C \in V_8 \rightarrow V_v$
8282
- $W \in U_{32}$, the window size
8383
- $T \in U_{32}$, the threshold
8484

85-
The configuration must satisfy $S_{\text{max}} \ge S_{\text{min}} \ge W > 0$.
85+
The configuration must satisfy $S_{\text{max}} \ge S_{\text{min}} > 0$ and $W >
86+
0$.
8687

8788
## Definitions
8889

@@ -230,7 +231,7 @@ package `go4.org/rollsum`.
230231
#### Rolling
231232

232233
`rrs` is a family of _rolling_ hashes. We can compute hashes in a
233-
rolling fashion by taking advantage of the fact that:
234+
rolling fashion by taking advantage of the fact that, for $l \geq k \geq 0$:
234235

235236
$a(k + 1, l + 1) = (a(k, l) - (X_k + c) + (X_{l+1} + c)) \mod M$
236237

@@ -246,6 +247,16 @@ So, a typical implementation will work like this:
246247
$a(k + 1, l + 1)$ and $b(k + 1, l + 1)$. Then use those values to
247248
compute $s(k + 1, l + 1)$ and also store them for future use.
248249

250+
In all cases the ring buffer should initially contain all zero bytes.
251+
252+
In some cases it's helpful to use the function $S(l) = s(l - W + 1, l)$, where
253+
$W$ is the window size (see ["Splitting"](#splitting) above). This function can
254+
be defined for all $l \geq 0$ by applying the previous formulas for $a(k, l)$
255+
and $b(k, l)$ and putting $X_i = 0$ for all $i < 0$. The resulting values for
256+
$S$ will be the same as when $a$ and $b$ are computed using the rolling
257+
implementation just described, provided that the ring buffer is initially zeroed
258+
as specified.
259+
249260
#### Choice of M
250261

251262
Choosing $M = 2^{16}$ has the advantages of simplicity and efficiency,

0 commit comments

Comments
 (0)