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

Function node_id

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

Source from the content-addressed store, hash-verified

43}
44
45pub fn node_id(file_path: &str, kind: &str, name: &str, line: u32) -> String {
46 let mut hasher = Sha256::new();
47 hasher.update(file_path.as_bytes());
48 hasher.update(b":");
49 hasher.update(kind.as_bytes());
50 hasher.update(b":");
51 hasher.update(name.as_bytes());
52 hasher.update(b":");
53 hasher.update(line.to_string().as_bytes());
54 let digest = hasher.finalize();
55 // 32 hex chars = first 16 bytes.
56 let mut hex = String::with_capacity(kind.len() + 1 + 32);
57 hex.push_str(kind);
58 hex.push(':');
59 for b in &digest[..16] {
60 hex.push_str(&format!("{b:02x}"));
61 }
62 hex
63}
64
65pub fn file_node_id(file_path: &str) -> String {
66 format!("file:{file_path}")

Callers 1

generateMethod · 0.85

Calls 3

updateMethod · 0.80
lenMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected