MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / predict

Function predict

atomic-core/examples/semantic_codec_lab/lengths.rs:23–43  ·  view source on GitHub ↗
(bytes: &[u8])

Source from the content-addressed store, hash-verified

21 *h.finalize().as_bytes()
22}
23fn predict(bytes: &[u8]) -> usize {
24 let cap = bytes.len().min(4096);
25 let mut width = cap.min(16);
26 loop {
27 let window = &bytes[..width];
28 let ascii = window
29 .iter()
30 .position(|b| !b.is_ascii())
31 .unwrap_or(window.len());
32 if ascii == 0 {
33 return usize::from(!bytes.is_empty());
34 }
35 let length = Tokenizer::new(&window[..ascii])
36 .next()
37 .map_or(0, |token| token.len());
38 if length < ascii || ascii < width || width == cap {
39 return length;
40 }
41 width = (width * 2).min(cap);
42 }
43}
44fn offset(tag: u64, refs: &mut &[u8], previous: &mut u64, cursor: usize) -> Result<usize> {
45 if tag == 0 {
46 return Ok(cursor);

Callers 2

splitFunction · 0.70
valueMethod · 0.70

Calls 5

lenMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected