Skip to main content

create_graph_from_edges

Function create_graph_from_edges 

Source
pub fn create_graph_from_edges(
    num_nodes: u32,
    is_directed: bool,
    edges: &[(u32, u32, f64)],
) -> FFIGraph
Expand description

Helper function to create a graph from edge list (for FFI)

Examples found in repository?
examples/rust_example.rs (line 17)
7fn main() {
8    // Create a simple undirected graph for clustering coefficient calculation
9    // Triangle: 0-1-2-0
10    let edges = vec![
11        (0u32, 1u32, 1.0f64),
12        (1u32, 2u32, 1.0f64),
13        (2u32, 0u32, 1.0f64),
14        (1u32, 3u32, 1.0f64),
15    ];
16
17    let graph = create_graph_from_edges(4, false, &edges);
18
19    println!("Graph created with {} nodes and {} edges", graph.num_nodes(), graph.num_edges());
20
21    // BFS traversal
22    let traversal = graph.bfs_traverse_ffi(0);
23    println!("BFS traversal from node 0: {:?}", traversal);
24
25    // BFS distances
26    let distances = graph.bfs_distances_ffi(0);
27    println!("BFS distances from node 0: {:?}", distances);
28
29    // Dijkstra
30    let dijkstra_distances = graph.dijkstra_ffi(0);
31    println!("Dijkstra distances from node 0: {:?}", dijkstra_distances);
32
33    // PageRank
34    let pagerank = graph.pagerank_ffi(10, 0.85);
35    println!("PageRank scores: {:?}", pagerank);
36
37    // Triangle counting
38    let triangles = graph.triangle_count_ffi();
39    println!("Triangle count: {}", triangles);
40
41    // Components
42    let components = graph.component_count_ffi();
43    println!("Number of connected components: {}", components);
44
45    // Clustering coefficient
46    let cc = graph.clustering_coefficient_ffi();
47    println!("Clustering coefficient: {}", cc);
48}