pub struct FFIGraph { /* private fields */ }Expand description
FFI-friendly wrapper for Graph that can be passed across language boundaries
Implementations§
Source§impl FFIGraph
impl FFIGraph
Sourcepub fn new(num_nodes: u32, is_directed: bool) -> Self
pub fn new(num_nodes: u32, is_directed: bool) -> Self
Creates a new FFI graph with the given number of nodes
Sourcepub fn num_nodes(&self) -> u32
pub fn num_nodes(&self) -> u32
Gets the number of nodes in the graph
Examples found in repository?
examples/rust_example.rs (line 19)
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}Sourcepub fn num_edges(&self) -> u32
pub fn num_edges(&self) -> u32
Gets the number of edges in the graph
Examples found in repository?
examples/rust_example.rs (line 19)
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}Sourcepub fn bfs_traverse_ffi(&self, start: u32) -> Vec<u32>
pub fn bfs_traverse_ffi(&self, start: u32) -> Vec<u32>
Runs BFS from the given starting node
Examples found in repository?
examples/rust_example.rs (line 22)
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}Sourcepub fn bfs_distances_ffi(&self, start: u32) -> Vec<u32>
pub fn bfs_distances_ffi(&self, start: u32) -> Vec<u32>
Gets distances via BFS from the starting node
Examples found in repository?
examples/rust_example.rs (line 26)
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}Sourcepub fn dijkstra_ffi(&self, start: u32) -> Vec<f64>
pub fn dijkstra_ffi(&self, start: u32) -> Vec<f64>
Runs Dijkstra’s algorithm
Examples found in repository?
examples/rust_example.rs (line 30)
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}Sourcepub fn pagerank_ffi(&self, iterations: u32, damping_factor: f64) -> Vec<f64>
pub fn pagerank_ffi(&self, iterations: u32, damping_factor: f64) -> Vec<f64>
Computes PageRank
Examples found in repository?
examples/rust_example.rs (line 34)
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}Sourcepub fn triangle_count_ffi(&self) -> u64
pub fn triangle_count_ffi(&self) -> u64
Counts triangles in the graph
Examples found in repository?
examples/rust_example.rs (line 38)
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}Sourcepub fn component_count_ffi(&self) -> u32
pub fn component_count_ffi(&self) -> u32
Gets the number of connected components
Examples found in repository?
examples/rust_example.rs (line 42)
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}Sourcepub fn clustering_coefficient_ffi(&self) -> f64
pub fn clustering_coefficient_ffi(&self) -> f64
Gets the clustering coefficient
Examples found in repository?
examples/rust_example.rs (line 46)
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}Trait Implementations§
Auto Trait Implementations§
impl Freeze for FFIGraph
impl RefUnwindSafe for FFIGraph
impl Send for FFIGraph
impl Sync for FFIGraph
impl Unpin for FFIGraph
impl UnwindSafe for FFIGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more