flowscope_core/analyzer/helpers/
id.rs

1use std::collections::hash_map::DefaultHasher;
2use std::hash::{Hash, Hasher};
3use std::sync::Arc;
4
5/// Generate a deterministic node ID based on type and name
6pub fn generate_node_id(node_type: &str, name: &str) -> Arc<str> {
7    let mut hasher = DefaultHasher::new();
8    node_type.hash(&mut hasher);
9    name.hash(&mut hasher);
10    let hash = hasher.finish();
11
12    format!("{node_type}_{hash:016x}").into()
13}
14
15/// Generate a deterministic edge ID
16pub fn generate_edge_id(from: &str, to: &str) -> Arc<str> {
17    let mut hasher = DefaultHasher::new();
18    from.hash(&mut hasher);
19    to.hash(&mut hasher);
20    let hash = hasher.finish();
21
22    format!("edge_{hash:016x}").into()
23}
24
25/// Generate a deterministic column node ID
26pub fn generate_column_node_id(parent_id: Option<&str>, column_name: &str) -> Arc<str> {
27    let mut hasher = DefaultHasher::new();
28    "column".hash(&mut hasher);
29    if let Some(parent) = parent_id {
30        parent.hash(&mut hasher);
31    }
32    column_name.hash(&mut hasher);
33    let hash = hasher.finish();
34
35    format!("column_{hash:016x}").into()
36}
37
38/// Generate a deterministic output node ID scoped to a statement.
39pub fn generate_output_node_id(statement_index: usize) -> Arc<str> {
40    generate_node_id("output", &format!("statement_{statement_index}"))
41}