MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / hash_call_sequence

Function hash_call_sequence

src/redundancy.rs:249–280  ·  view source on GitHub ↗

Pre-order walk, collecting the leftmost identifier of every call/invocation/macro node, in source order, then hashing them.

(root: Node<'_>, source: &[u8])

Source from the content-addressed store, hash-verified

247/// Pre-order walk, collecting the leftmost identifier of every
248/// call/invocation/macro node, in source order, then hashing them.
249fn hash_call_sequence(root: Node<'_>, source: &[u8]) -> String {
250 let mut calls: Vec<String> = Vec::new();
251 let mut stack: Vec<Node<'_>> = vec![root];
252 while let Some(node) = stack.pop() {
253 let kind = node.kind();
254 if is_call_kind(kind) {
255 if let Some(name) = leftmost_callable_name(node, source) {
256 calls.push(name);
257 }
258 }
259 let mut cursor = node.walk();
260 if cursor.goto_first_child() {
261 let mut children: Vec<Node<'_>> = Vec::new();
262 loop {
263 children.push(cursor.node());
264 if !cursor.goto_next_sibling() {
265 break;
266 }
267 }
268 for child in children.into_iter().rev() {
269 stack.push(child);
270 }
271 }
272 }
273
274 let mut hasher = Sha256::new();
275 for name in &calls {
276 hasher.update(name.as_bytes());
277 hasher.update([0x1f]);
278 }
279 short_hex(hasher.finalize().as_slice())
280}
281
282fn is_call_kind(kind: &str) -> bool {
283 const MARKERS: [&str; 4] = ["call", "invocation", "macro", "apply"];

Callers 1

compute_fingerprintFunction · 0.85

Calls 5

is_call_kindFunction · 0.85
leftmost_callable_nameFunction · 0.85
short_hexFunction · 0.85
kindMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected