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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! What:
//! Byte searches over a slice that the index readers share: where a byte first appears, how long a run of one byte is,
//! and whether any byte is not zero.
//! Why:
//! The index formats are NUL-terminated names, `/`-separated paths and zero-filled hashes. A closure per search was
//! reported by `rust/avoidable-closure`; one named loop per question reads the same everywhere and breaks the same way.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! const nul = bytes.indexOf(0); // firstIndexOfByte(bytes, 0)
//! const hasData = bytes.some((b) => b !== 0); // hasNonzeroByte(bytes)
//! ```
/// Whether `byte` is the path separator `/`; the shape `split` and `all` want.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const isSlash = (byte: number): boolean => byte === 0x2f;
/// ```
/// The position of the first byte of `bytes` equal to `wanted`, or `None` when no byte is.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function firstIndexOfByte(bytes: Uint8Array, wanted: number): number | undefined; // bytes.indexOf(wanted)
/// ```
/// How many bytes at the start of `bytes` equal `wanted` in a row.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function leadingRunLength(bytes: Uint8Array, wanted: number): number;
/// ```
/// How many bytes at the start of `bytes` are ASCII digits.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function leadingDigitCount(bytes: Uint8Array): number;
/// ```
/// Whether any byte of `bytes` is not zero; an empty slice has none.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function hasNonzeroByte(bytes: Uint8Array): boolean; // bytes.some((b) => b !== 0)
/// ```
/// How many bytes `left` and `right` share at their start.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function commonPrefixLength(left: Uint8Array, right: Uint8Array): number;
/// ```