Skip to main content

FFIGraph

Struct FFIGraph 

Source
pub struct FFIGraph { /* private fields */ }
Expand description

FFI-friendly wrapper for Graph that can be passed across language boundaries

Implementations§

Source§

impl FFIGraph

Source

pub fn new(num_nodes: u32, is_directed: bool) -> Self

Creates a new FFI graph with the given number of nodes

Source

pub fn add_edge(&mut self, from: u32, to: u32, weight: f64)

Adds an edge to the graph

Source

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}
Source

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}
Source

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}
Source

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}
Source

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}
Source

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}
Source

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}
Source

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}
Source

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§

Source§

impl Clone for FFIGraph

Source§

fn clone(&self) -> FFIGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.