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

Function columns

atomic-core/src/change/format_v3/semantic/encode.rs:230–268  ·  view source on GitHub ↗
(ops: &[FileOps], content: &[u8], split_ids: bool)

Source from the content-addressed store, hash-verified

228}
229
230pub(super) fn columns(ops: &[FileOps], content: &[u8], split_ids: bool) -> FormatResult<Columns> {
231 if content.len() > MAX_PAYLOAD {
232 return Err(super::super::FormatError::SemanticLimitExceeded);
233 }
234 let mut lines = HashMap::new();
235 let mut offset = 0;
236 for line in content.split_inclusive(|b| *b == b'\n') {
237 lines.entry(line).or_insert(offset);
238 lines
239 .entry(line.strip_suffix(b"\n").unwrap_or(line))
240 .or_insert(offset);
241 offset += line.len();
242 }
243 let mut e = Encoder {
244 c: Columns {
245 split_ids,
246 content_hash: *blake3::hash(content).as_bytes(),
247 ..Columns::default()
248 },
249 s: State::default(),
250 content,
251 lines,
252 literals: HashMap::new(),
253 remaining: MAX_EXPANDED,
254 };
255 charge(&mut e.remaining, ops.len(), FileOps::COST)?;
256 put(&mut e.c.control, ops.len() as u64);
257 for file in ops {
258 let metadata = postcard::to_allocvec(&(file.trunk_id(), file.path(), file.trunk_op()))?;
259 charge(&mut e.remaining, metadata.len(), 1)?;
260 e.c.metadata.extend(metadata);
261 charge(&mut e.remaining, file.line_count(), LineOps::COST)?;
262 put(&mut e.c.control, file.line_count() as u64);
263 for line in file.line_ops() {
264 e.line(line)?;
265 }
266 }
267 Ok(e.c)
268}

Callers 2

encode_layoutFunction · 0.85
encodeFunction · 0.85

Calls 12

extendMethod · 0.80
chargeFunction · 0.70
putFunction · 0.70
hashFunction · 0.50
lenMethod · 0.45
as_bytesMethod · 0.45
trunk_idMethod · 0.45
pathMethod · 0.45
trunk_opMethod · 0.45
line_countMethod · 0.45
line_opsMethod · 0.45
lineMethod · 0.45

Tested by

no test coverage detected