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

Function predict_kinds

atomic-core/examples/semantic_codec_lab/context.rs:127–150  ·  view source on GitHub ↗
(view: &View<'_>, content: &[u8])

Source from the content-addressed store, hash-verified

125}
126
127pub fn predict_kinds(view: &View<'_>, content: &[u8]) -> Result<Vec<u8>> {
128 let mut actual = view.kinds;
129 let mut mask: Vec<u8> = vec![];
130 let mut exceptions = vec![];
131 let mut n = 0usize;
132 token_bytes(view, content, |bytes| {
133 let kind = control::get(&mut actual)?;
134 if n.is_multiple_of(8) {
135 mask.push(0);
136 }
137 if kind != predict(bytes) {
138 mask[n / 8] |= 1 << (n % 8);
139 transforms::put(&mut exceptions, kind);
140 }
141 n += 1;
142 Ok(())
143 })?;
144 ensure!(actual.is_empty(), "trailing actual token kinds");
145 Ok(postcard::to_allocvec(&(
146 u32::try_from(n)?,
147 mask,
148 exceptions,
149 ))?)
150}
151
152pub fn restore_kinds(
153 view: &View<'_>,

Calls 5

token_bytesFunction · 0.85
getFunction · 0.70
predictFunction · 0.70
putFunction · 0.70
pushMethod · 0.45