MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / run

Function run

nodedb/src/engine/graph/algo/diameter.rs:26–47  ·  view source on GitHub ↗

Run Diameter/Eccentricity computation on the CSR index. `params.mode`: "EXACT" or "APPROXIMATE" (default). Returns `(diameter, radius)` as a single row.

(csr: &CsrIndex, params: &AlgoParams)

Source from the content-addressed store, hash-verified

24/// `params.mode`: "EXACT" or "APPROXIMATE" (default).
25/// Returns `(diameter, radius)` as a single row.
26pub fn run(csr: &CsrIndex, params: &AlgoParams) -> AlgoResultBatch {
27 let n = csr.node_count();
28 if n == 0 {
29 return AlgoResultBatch::new(GraphAlgorithm::Diameter);
30 }
31
32 let mode = params
33 .mode
34 .as_deref()
35 .unwrap_or("APPROXIMATE")
36 .to_uppercase();
37
38 let (diameter, radius) = if mode == "EXACT" {
39 compute_exact(csr, n)
40 } else {
41 compute_approximate(csr, n)
42 };
43
44 let mut batch = AlgoResultBatch::new(GraphAlgorithm::Diameter);
45 batch.push_diameter(diameter, radius);
46 batch
47}
48
49/// Exact computation: BFS from every node, compute all eccentricities.
50fn compute_exact(csr: &CsrIndex, n: usize) -> (i64, i64) {

Callers 4

diameter_pathFunction · 0.70
diameter_triangleFunction · 0.70
diameter_approximateFunction · 0.70
diameter_single_nodeFunction · 0.70

Calls 4

compute_exactFunction · 0.85
compute_approximateFunction · 0.85
push_diameterMethod · 0.80
node_countMethod · 0.45

Tested by 4

diameter_pathFunction · 0.56
diameter_triangleFunction · 0.56
diameter_approximateFunction · 0.56
diameter_single_nodeFunction · 0.56