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

Function predict

atomic-core/examples/semantic_codec_lab/context.rs:99–125  ·  view source on GitHub ↗

Frozen experimental predictor: boundaries and IDs are never inferred. Every classification that differs from the author's value is stored explicitly.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

97// Frozen experimental predictor: boundaries and IDs are never inferred. Every
98// classification that differs from the author's value is stored explicitly.
99fn predict(bytes: &[u8]) -> u64 {
100 if matches!(bytes, b"\n" | b"\r\n" | b"\r") {
101 7
102 } else if !bytes.is_empty() && bytes.iter().all(u8::is_ascii_whitespace) {
103 1
104 } else if bytes.starts_with(b"//") {
105 6
106 } else if bytes.len() >= 2 && matches!(bytes[0], b'\'' | b'"') && bytes.last() == bytes.first()
107 {
108 4
109 } else if bytes.first().is_some_and(u8::is_ascii_digit) {
110 5
111 } else if bytes.len() == 1 && b"(){}[];,.".contains(&bytes[0]) {
112 3
113 } else if !bytes.is_empty() && bytes.iter().all(|b| b"+-*/%=!<>|&^~?:@".contains(b)) {
114 2
115 } else if std::str::from_utf8(bytes).is_ok_and(|s| {
116 s.chars()
117 .next()
118 .is_some_and(|c| c.is_alphabetic() || c == '_')
119 && s.chars().all(|c| c.is_alphanumeric() || c == '_')
120 }) {
121 0
122 } else {
123 8
124 }
125}
126
127pub fn predict_kinds(view: &View<'_>, content: &[u8]) -> Result<Vec<u8>> {
128 let mut actual = view.kinds;

Callers 2

predict_kindsFunction · 0.70
restore_kindsFunction · 0.70

Calls 7

lastMethod · 0.80
is_emptyMethod · 0.45
allMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
containsMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected