Skip to main content

graphops/
lib.rs

1//! `graphops`: graph operators (walk/diffusion + related centralities).
2//!
3//! This crate is the canonical home for operator implementations in this workspace.
4//! Call sites should prefer `graphops::*` (and not refer to historical names).
5//!
6//! Public invariants (must not drift):
7//! - **Node order**: outputs are indexed by node id \(0..n-1\) consistent with the input graph’s
8//!   adapter semantics (e.g. `petgraph::NodeIndex::index()` when using the `petgraph` feature).
9//! - **Determinism**: deterministic operators are deterministic given identical inputs + configs.
10//! - **No silent normalization**: normalization behavior is explicit in the API/docs (e.g.
11//!   personalization vectors in PPR).
12//!
13//! Swappable (allowed to change without breaking the contract):
14//! - iteration strategy (serial vs parallel)
15//! - convergence details (so long as tolerance semantics remain correct)
16//! - internal data structures (so long as invariants hold)
17
18#[cfg(feature = "petgraph")]
19pub mod betweenness;
20pub mod graph;
21pub mod node2vec;
22pub mod pagerank;
23pub mod partition;
24pub mod ppr;
25pub mod random_walk;
26pub mod reachability;
27pub mod topk;
28
29#[cfg(feature = "petgraph")]
30pub use betweenness::betweenness_centrality;
31pub use graph::{AdjacencyMatrix, Graph, GraphRef, WeightedGraph, WeightedGraphRef};
32pub use node2vec::{
33    generate_biased_walks_precomp_ref, generate_biased_walks_precomp_ref_from_nodes,
34    generate_biased_walks_weighted_plus_ref, generate_biased_walks_weighted_ref,
35    PrecomputedBiasedWalks, WeightedNode2VecPlusConfig,
36};
37
38#[cfg(feature = "parallel")]
39pub use node2vec::generate_biased_walks_precomp_ref_parallel_from_nodes;
40#[cfg(feature = "parallel")]
41pub use random_walk::{
42    generate_biased_walks_ref_parallel, generate_biased_walks_ref_parallel_from_nodes,
43    generate_walks_ref_parallel, generate_walks_ref_parallel_from_nodes,
44};
45
46pub use pagerank::{pagerank, pagerank_weighted, PageRankConfig};
47pub use pagerank::{pagerank_checked, pagerank_weighted_checked};
48pub use pagerank::{
49    pagerank_checked_run, pagerank_run, pagerank_weighted_checked_run, pagerank_weighted_run,
50    PageRankRun,
51};
52pub use partition::{connected_components, label_propagation};
53pub use ppr::{personalized_pagerank, personalized_pagerank_checked};
54pub use ppr::{personalized_pagerank_checked_run, personalized_pagerank_run};
55pub use random_walk::{
56    generate_biased_walks, generate_biased_walks_from_nodes, generate_biased_walks_ref,
57    generate_biased_walks_ref_from_nodes, generate_biased_walks_ref_streaming_from_nodes,
58    generate_walks, generate_walks_from_nodes, generate_walks_ref, generate_walks_ref_from_nodes,
59    generate_walks_ref_streaming_from_nodes, sample_start_nodes_reservoir, WalkConfig,
60};
61pub use reachability::reachability_counts_edges;
62pub use topk::{normalize, top_k};
63
64#[derive(Debug, thiserror::Error)]
65pub enum Error {
66    #[error("index out of bounds: {0}")]
67    IndexOutOfBounds(usize),
68    #[error("invalid parameter: {0}")]
69    InvalidParameter(String),
70}
71
72pub type Result<T> = std::result::Result<T, Error>;