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

Function projection_id

atomic-core/src/pristine/span_patch_storage.rs:675–715  ·  view source on GitHub ↗
(
    file: &ExternalFile,
    domain: &[u8],
    spans: &[VisibleSpan],
)

Source from the content-addressed store, hash-verified

673}
674
675fn projection_id(
676 file: &ExternalFile,
677 domain: &[u8],
678 spans: &[VisibleSpan],
679) -> Result<SpanProjectionId> {
680 let mut normalized: Vec<(&ExternalSpan, u64, u64)> = Vec::new();
681 for span in spans {
682 let length = u64::try_from(span.output.len())?;
683 ensure!(length != 0, "empty projected authored fragment");
684 let end = span
685 .target_start
686 .checked_add(length)
687 .context("projected fragment overflow")?;
688 if let Some((target, _, previous_end)) = normalized.last_mut() {
689 if *target == &span.target && *previous_end == span.target_start {
690 *previous_end = end;
691 continue;
692 }
693 }
694 normalized.push((&span.target, span.target_start, end));
695 }
696 ensure!(
697 !normalized.is_empty(),
698 "projected semantic identity has no authored bytes"
699 );
700 let mut bytes = Vec::new();
701 bytes.extend_from_slice(b"atomic.span.semantic.projection.v1\0");
702 bytes.extend_from_slice(domain);
703 bytes.push(0);
704 bytes.extend_from_slice(file.owner.as_bytes());
705 bytes.extend_from_slice(&file.ordinal.to_be_bytes());
706 bytes.extend_from_slice(&u64::try_from(normalized.len())?.to_be_bytes());
707 for (target, start, end) in normalized {
708 bytes.extend_from_slice(target.owner.as_bytes());
709 bytes.extend_from_slice(&target.start.to_be_bytes());
710 bytes.extend_from_slice(&target.end.to_be_bytes());
711 bytes.extend_from_slice(&start.to_be_bytes());
712 bytes.extend_from_slice(&end.to_be_bytes());
713 }
714 Ok(SpanProjectionId(Hash::of(&bytes)))
715}
716
717/// One token interpreted from a span-backed file, with its exact authored
718/// byte fragments. A token may cross changes and therefore has no fabricated

Callers 2

semantic_baseline_idMethod · 0.85
semantic_linesMethod · 0.85

Calls 5

SpanProjectionIdClass · 0.85
lenMethod · 0.45
contextMethod · 0.45
pushMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected