MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / node_id

Function node_id

codegraph-kernel/src/ids.rs:16–34  ·  view source on GitHub ↗
(file_path: &str, kind: &str, name: &str, line: u32)

Source from the content-addressed store, hash-verified

14use sha2::{Digest, Sha256};
15
16pub fn node_id(file_path: &str, kind: &str, name: &str, line: u32) -> String {
17 let mut hasher = Sha256::new();
18 hasher.update(file_path.as_bytes());
19 hasher.update(b":");
20 hasher.update(kind.as_bytes());
21 hasher.update(b":");
22 hasher.update(name.as_bytes());
23 hasher.update(b":");
24 hasher.update(line.to_string().as_bytes());
25 let digest = hasher.finalize();
26 // 32 hex chars = first 16 bytes.
27 let mut hex = String::with_capacity(kind.len() + 1 + 32);
28 hex.push_str(kind);
29 hex.push(':');
30 for b in &digest[..16] {
31 hex.push_str(&format!("{b:02x}"));
32 }
33 hex
34}
35
36pub fn file_node_id(file_path: &str) -> String {
37 format!("file:{file_path}")

Callers 15

create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85
create_nodeMethod · 0.85

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected