Skip to main content

graphrust_ffi/
cxx_bindings.rs

1//! CXX-based C++ FFI bindings
2//!
3//! This module provides C++ bindings using the CXX crate for type-safe interop.
4//! The C++ side includes automatic handling of Rust types like Vec and String.
5
6// This would be included in build.rs to generate the CXX bindings
7// For now, we'll use a simplified version that demonstrates the pattern
8
9use crate::FFIGraph;
10
11/// Safe wrapper for algorithms exposed to C++
12pub struct AlgorithmWrapper;
13
14impl AlgorithmWrapper {
15    /// BFS traversal accessible from C++
16    pub fn bfs_traverse_cpp(graph: &FFIGraph, start: u32) -> Vec<u32> {
17        graph.bfs_traverse_ffi(start)
18    }
19
20    /// Dijkstra accessible from C++
21    pub fn dijkstra_cpp(graph: &FFIGraph, start: u32) -> Vec<f64> {
22        graph.dijkstra_ffi(start)
23    }
24
25    /// PageRank accessible from C++
26    pub fn pagerank_cpp(graph: &FFIGraph, iterations: u32, damping_factor: f64) -> Vec<f64> {
27        graph.pagerank_ffi(iterations, damping_factor)
28    }
29
30    /// Triangle counting accessible from C++
31    pub fn triangle_count_cpp(graph: &FFIGraph) -> u64 {
32        graph.triangle_count_ffi()
33    }
34
35    /// Component count accessible from C++
36    pub fn component_count_cpp(graph: &FFIGraph) -> u32 {
37        graph.component_count_ffi()
38    }
39
40    /// Clustering coefficient accessible from C++
41    pub fn clustering_coefficient_cpp(graph: &FFIGraph) -> f64 {
42        graph.clustering_coefficient_ffi()
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_algorithm_wrapper() {
52        let _graph = FFIGraph::new(5, true);
53        // This is just a compilation test to ensure the wrapper works
54    }
55}