Expand description
§rust-igraph
Pure-Rust port of the igraph network analysis library. Targets full API parity with igraph C v1.0.x (~850 public functions), validated continuously against the three official implementations (igraph C, python-igraph, R-igraph).
Status: alpha — only the Phase 0 walking-skeleton API is shipped (
Graph,read_edgelist,bfs). The catalog grows algorithm-by-algorithm through Phase 1-10. See the project’s master plan.
§Quick start
use rust_igraph::{Graph, bfs};
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 3).unwrap();
let order = bfs(&g, 0).unwrap();
assert_eq!(order, vec![0, 1, 2, 3]);§License
GPL-2.0-or-later, matching upstream igraph.
Re-exports§
pub use crate::core::error::IgraphError;pub use crate::core::error::IgraphResult;pub use crate::core::graph::Graph;pub use crate::core::graph::VertexId;
Modules§
- algorithms
- Algorithm implementations for rust-igraph.
- core
- Core data structures for rust-igraph.
Structs§
- BfsTree
- Result of a multi-output BFS scan from a single root. Returned by
bfs_tree. - Biconnected
Components - Output of
biconnected_components. - Connected
Components - Result of a weak connected-components scan.
- Dijkstra
AllPaths - Output of
dijkstra_all_shortest_paths. - Dijkstra
Paths - Output of
dijkstra_paths.parents[v]is the predecessor ofvalong the shortest-path tree from the single source (orNonefor the source itself and for unreachable vertices — the caller can disambiguate viadistances[v]).inbound_edges[v]is the edge idvwas reached through;Nonefor the source and unreachable vertices. - Edgelist
Percolation - Outputs of
edgelist_percolation. Same length as the input edge slice.giant_size[i]is the size of the largest component after edgeiis added;vertex_count[i]is the number of distinct vertices touched by edges0..=i. - Eulerian
Classification - Whether an Eulerian path or cycle exists in a graph.
- Site
Percolation - Outputs of
site_percolation. Same length asvertex_order.giant_size[i]is the size of the largest connected component after vertexvertex_order[i]is activated;edge_count[i]is the cumulative number of edges added through stepi(an edge is “added” the moment both its endpoints become active). - Widest
Paths - Sidecar outputs from a single-source widest-paths run. Carries
the widths vector plus the parent-pointer SPT (vertex-side and
edge-side). Counterpart of the
parentsandinbound_edgesoutputs ofigraph_get_widest_paths. Source itself hasparents[source] == Noneandinbound_edges[source] == None; unreachable vertices also have bothNone. To disambiguate the source from unreachable targets, consultwidths: source hasSome(f64::INFINITY), unreachable hasNone.
Enums§
- Coreness
Mode - Direction-handling for
coreness_with_mode. - Dijkstra
Mode - Direction selector for the mode-aware Dijkstra entry points
(SP-001c). Counterpart of
igraph_neimode_trestricted to the three valuesigraph_distances_dijkstraaccepts. For undirected graphs every variant collapses toDijkstraMode::All(every edge is bidirectional). - EccMode
- Mode for direction-aware eccentricity / radius / diameter on directed
graphs. For undirected graphs every mode reduces to
EccMode::All. - Neighborhood
Mode - Direction mode for
neighborhood_size_with_modeon directed graphs. Ignored on undirected graphs — every mode reduces toNeighborhoodMode::All. - Reciprocity
Mode - Reciprocity formula choice. Counterpart of upstream’s
igraph_reciprocity_t(IGRAPH_RECIPROCITY_DEFAULT/IGRAPH_RECIPROCITY_RATIO). - Simple
Mode - Direction-handling for
is_simple_with_mode. Counterpart of upstream’sdirectedboolean parameter.
Functions§
- a_
star_ path - Single-source single-target shortest path using A*.
- articulation_
points - Articulation points of
graph(returns vertices in upstream’s DFS-discovery order). - assortativity_
degree - Degree assortativity coefficient of
graph(undirected, unweighted). ReturnsNonefor graphs with no edges or for regular graphs (all vertices same degree — the variance denominator vanishes, matching upstream’sIGRAPH_NAN). - assortativity_
degree_ directed - Directed degree assortativity coefficient (ALGO-PR-006c).
- assortativity_
degree_ directed_ weighted - Directed weighted degree assortativity (PR-006d).
- assortativity_
degree_ weighted - Weighted degree assortativity coefficient.
- average_
local_ efficiency - Average of
local_efficiencyover allNvertices. By upstream convention, returns0.0whenvcount < 3(no vertex can have two distinct neighbours, so every per-vertex value is trivially 0). - avg_
nearest_ neighbor_ degree - Average nearest-neighbour degree, per vertex.
- avg_
nearest_ neighbor_ degree_ weighted - Weighted average nearest-neighbour degree (Barrat formula).
- bellman_
ford_ distances - Single-source Bellman-Ford shortest distances on
graphfromsource, following out-edges on directed graphs. - bellman_
ford_ distances_ with_ mode - Single-source Bellman-Ford with directed-mode selection.
- betweenness
- Per-vertex (unweighted) betweenness centrality.
- betweenness_
weighted - Per-vertex weighted betweenness centrality.
- bfs
- Visit order of vertices reachable from
root, in BFS order. - bfs_
tree - Multi-output BFS from
root. Returns visit order, per-vertex distances, and per-vertex BFS-tree parent in a single pass. - biconnected_
components - Compute the biconnected components of
graph. - bond_
percolation - Bond percolation: the size of the largest component as edges of
graphare added in the order specified byedge_order. - bridges
- Bridges of
graph— edges whose removal would increase the number of (weakly) connected components. - closeness
- Per-vertex closeness centrality (
Vec<Option<f64>>). - closeness_
weighted - Per-vertex weighted closeness centrality.
- complementer
- Returns the complementer of
graph. - connected_
components - Compute the weak connected components of
graph. - convergence_
degree - Per-edge convergence degree.
- convergence_
degree_ full - Convergence degree along with the per-edge
In(e)/Out(e)counts. - coreness
- Per-vertex coreness number.
- coreness_
with_ mode - Coreness with explicit
CorenessMode(ALGO-PR-015b). - count_
adjacent_ triangles - Per-vertex adjacent-triangle count. Entry
iis the number of triangles vertexiparticipates in. Parallel edges and self-loops are ignored — the simple graph induced by the OUT-neighbour view is used (consistent withcount_triangles). For directed graphs that is not yet the underlying-undirected projection that upstream uses; see ALGO-PR-002 for the deferred fix. - count_
loops - Counts self-loop edges in
graph. - count_
multiple - Per-edge multiplicity: how many edges share each edge’s endpoint pair.
- count_
reachable - Per-vertex count of reachable vertices (including the vertex itself).
- count_
triangles - Count the number of triangles in
graph. Edge directions, parallel edges, and self-loops are ignored. - decompose
- Decompose
graphinto its weakly connected components. - density
- Edge density of
graph. Counterpart ofigraph_density(_, NULL_weights, _, /*loops=*/false). - dfs
- Pre-order visit of vertices reachable from
root, in DFS order. - diameter
- Diameter of
graph— the maximum vertex eccentricity.Nonefor a graph with no vertices. - diameter_
weighted - OUT-mode default for
diameter_weighted_with_mode. - diameter_
weighted_ with_ mode - Mode-aware weighted diameter.
Noneforvcount == 0. - diameter_
with_ mode - Diameter of
graphunder the givenmode.Noneforvcount == 0. - difference
- Returns
orig \ sub: the multiset difference of the edges. - dijkstra_
all_ shortest_ paths - All shortest weighted paths from
sourceto every vertex, preserving every tie. Counterpart ofigraph_get_all_shortest_paths_dijkstra(_, _, _, _, source, vss_all(), weights, mode). - dijkstra_
distances - Single-source Dijkstra distances.
- dijkstra_
distances_ cutoff - Single-source Dijkstra distances with an optional
cutoff. Whencutoff = Some(c), vertices whose shortest-path distance exceedscare returned asNone(unreachable-within-cutoff); the search stops relaxing edges out of any vertex whosemindist > c. - dijkstra_
distances_ cutoff_ with_ mode - Mode-aware
dijkstra_distances_cutoff. Counterpart ofigraph_distances_dijkstra_cutoff(_, _, source, vss_all(), weights, mode, cutoff). - dijkstra_
distances_ multi - Multi-source Dijkstra distances.
result[i][v]is the shortest distance fromsources[i]tov(orNoneif unreachable / past the cutoff). - dijkstra_
distances_ multi_ with_ mode - Mode-aware
dijkstra_distances_multi. - dijkstra_
distances_ with_ mode - Mode-aware Dijkstra distances. Counterpart of
igraph_distances_dijkstra(_, _, source, vss_all(), weights, mode). - dijkstra_
path_ to - Reconstruct a single source-to-target path returning vertex and
edge sequences.
Ok(None)iftargetis unreachable; the source vertex appears as the first element when reachable. - dijkstra_
path_ to_ with_ mode - Mode-aware
dijkstra_path_to. Counterpart ofigraph_get_shortest_path_dijkstra(_, _, _, source, target, weights, mode). - dijkstra_
paths - Single-source Dijkstra returning distances + parents + inbound edges over every vertex.
- dijkstra_
paths_ with_ mode - Mode-aware
dijkstra_paths. Counterpart ofigraph_get_shortest_paths_dijkstra(_, _, _, source, vss_all(), weights, mode, parents, inbound_edges). - disjoint_
union - Returns the disjoint union of
leftandright. - disjoint_
union_ many - Disjoint union of any number of graphs (ALGO-OP-002b).
- distances
- Unweighted shortest-path lengths from
sourceto every vertex. - eccentricity
- Eccentricity of every vertex (length
vcount). Resultr[v]is the maximum shortest-path distance fromvto any reachable vertex. Isolated vertices have eccentricity0. - eccentricity_
weighted - OUT-mode default for
eccentricity_weighted_with_mode. Counterpart ofigraph_eccentricity(_, weights, _, igraph_vss_all(), IGRAPH_OUT). - eccentricity_
weighted_ with_ mode - Mode-aware weighted eccentricity. For each vertex
v, returnsmax_{u reachable from v} dist(v, u), where distances are weighted shortest-path lengths (Dijkstra). Unreachable vertex pairs are ignored (matches upstream’sunconn=true); isolated vertices have eccentricity0.0. - eccentricity_
with_ mode - Eccentricity of every vertex following
mode-direction edges. - edge_
betweenness - Per-edge unweighted betweenness centrality.
- edge_
betweenness_ weighted - Per-edge weighted betweenness centrality (
Vec<f64>). - edgelist_
percolation - Percolation curve as a sequence of vertex-pair edges is added.
- eigenvector_
centrality - Eigenvector centrality scores normalized so
max == 1. - eulerian_
path - Build an Eulerian path or cycle for
graphif one exists. ReturnsSome(edge_ids)(the walk visits each edge exactly once) orNoneif no Eulerian walk exists. - floyd_
warshall_ distances - All-pairs shortest distances via Floyd-Warshall.
- girth
- Shortest cycle length in
graph. ReturnsNonefor acyclic graphs. - global_
efficiency - Global efficiency of
graph— average inverse pairwise shortest distance over allN*(N-1)ordered vertex pairs. Pairs that are unreachable contribute 0. - harmonic_
centrality - Per-vertex harmonic centrality.
- harmonic_
centrality_ weighted - Per-vertex weighted harmonic centrality.
- has_
loop - Returns
trueiffgraphhas at least one self-loop edge. - has_
multiple - Returns
trueiffgraphhas at least one parallel edge. - intersection
- Returns the intersection of
leftandright. - is_
acyclic - Returns
trueiffgraphcontains no cycle. - is_
biconnected - Check whether
graphis biconnected. - is_
complete - Returns
trueiff every pair of distinct vertices is adjacent. - is_dag
- Returns
trueiffgraphis a directed acyclic graph. - is_
eulerian - Decide whether
graphhas an Eulerian path and/or cycle. - is_
forest - Returns
Some(roots)iffgraphis a forest undermode, otherwiseNone. The null graph is a forest with empty roots. - is_loop
- Returns a per-edge boolean vector marking self-loops.
- is_
multiple - Returns a per-edge boolean vector marking multiple (parallel) edges.
- is_
same_ graph - Returns
trueiffg1andg2are identical as labelled graphs: same vertex count, same directedness, same edge multiset. Edges differing only in storage order (or, for undirected, in endpoint orientation) are treated as identical. - is_
simple - Returns
trueifgraphhas neither self-loops nor parallel edges. - is_
simple_ with_ mode is_simplewith explicitSimpleMode(ALGO-PR-013b).- is_tree
- Returns
Some(root)iffgraphis a tree undermode, otherwiseNone. The null graph (vcount == 0) is not a tree by convention. - johnson_
distances - All-pairs shortest-path distances via Johnson’s algorithm.
- knnk
- Per-degree average nearest-neighbour degree,
k_nn(k). - knnk_
weighted - Per-degree weighted average nearest-neighbour degree.
- local_
efficiency - Per-vertex local efficiency. For each vertex
v, computes the average inverse distance between every ordered pair of distinct vertices inN(v)(the unique non-self neighbours ofv), measured in the subgraph obtained by removingv— paths must not pass throughv. Pairs unreachable inG \ {v}contribute 0. - mean_
distance - Mean unweighted shortest-path length over all reachable ordered pairs.
Counterpart of
igraph_average_path_length(_, NULL_weights, _, _, /*directed=*/true, /*unconn=*/true). - modularity
- Modularity of
graphwith respect to community assignmentmembership. - modularity_
directed - Directed modularity (Leicht-Newman, ALGO-CO-001b).
- modularity_
weighted - Weighted modularity (ALGO-CO-001c).
- neighborhood
- k-hop neighbourhood vertex list for every vertex (
mode = All,mindist = 0). - neighborhood_
size - k-hop neighbourhood size for every vertex (
mode = All,mindist = 0). - neighborhood_
size_ with_ mode - Full mode-aware k-hop neighbourhood size with
mindistfilter. - neighborhood_
with_ mode - Full mode-aware k-hop neighbourhood vertex list with
mindistfilter. - pagerank
PageRankscores via power iteration with damping0.85.- pagerank_
weighted - Weighted
PageRankscores via power iteration with damping0.85. - radius
- Radius of
graph— the minimum vertex eccentricity.Nonefor a graph with no vertices (matches upstream’sIGRAPH_NANfor the null graph). - radius_
weighted - OUT-mode default for
radius_weighted_with_mode. - radius_
weighted_ with_ mode - Mode-aware weighted radius.
Noneforvcount == 0. - radius_
with_ mode - Radius of
graphunder the givenmode.Noneforvcount == 0. - random_
walk - Random walk on
graphstarting atstart, taking up tostepstransitions. - reachability_
matrix - Dense reachability matrix of
graph.result[i][j]istrueiff vertexjis reachable fromiin zero or more steps. - read_
edgelist - Read an edge list from any
Readinto a freshGraph. - reciprocity
- Reciprocity of
graph. ReturnsNonefor graphs with no edges (matches upstream’sIGRAPH_NAN). - reciprocity_
with_ mode - Reciprocity with explicit mode +
ignore_loops(ALGO-PR-004b). - simplify
- Return a copy of
graphwith self-loops and/or parallel edges removed. - site_
percolation - Site percolation: the size of the largest component as vertices
(sites) of
graphare activated in the order specified byvertex_order. - strongly_
connected_ components - Compute the strongly connected components of
graph. - topological_
sorting - Returns a topological ordering of
graph’s vertices. - transitive_
closure - Transitive closure of
graph. The returned graph shares the same vertex count and direction as the input. - transitivity_
barrat - Barrat’s weighted local transitivity, per vertex.
- transitivity_
local_ undirected - Local transitivity (clustering coefficient) per vertex.
- transitivity_
undirected - Global transitivity (clustering coefficient) of
graph—3 * triangles / connected_triples. ReturnsNonewhen there are no connected triples (matches upstream’sIGRAPH_TRANSITIVITY_NANmode); use.unwrap_or(0.0)for theIGRAPH_TRANSITIVITY_ZERObehaviour. - union
- Returns the union of
leftandright. - widest_
path - Widest path from
fromtoto: returns the vertex sequence and the edge sequence along the widest (maximum-bottleneck) path. - widest_
path_ widths - Single-source widest-path widths on
graphfromsource, following out-edges on directed graphs. - widest_
path_ widths_ floyd_ warshall - All-pairs widest-path widths via the Floyd-Warshall recurrence.
- widest_
path_ widths_ floyd_ warshall_ with_ mode - Mode-aware variant of
widest_path_widths_floyd_warshall. Mode selects how directed edges contribute to the adjacency matrix: - widest_
path_ widths_ with_ mode - Widest-path widths with directed-mode selection. Mirrors
widest_path_widthsbut lets you choose OUT/IN/ALL traversal for directed graphs (ignored on undirected). - widest_
path_ with_ mode - Widest path with mode selection. Mirrors
widest_pathbut lets you pick OUT/IN/ALL traversal on directed graphs. - widest_
paths - Single-source widest-paths sidecar: widths plus the parent-pointer SPT. Convenient when you want all of widths, parent vertices, and inbound edge ids in one call without re-running the SPT.
- widest_
paths_ to - Widest paths from a single source to multiple targets. Returns
one
WidestPathResultper element oftargets, in the same order;Nonemeans the target is unreachable fromfrom. - widest_
paths_ to_ with_ mode - Mode-aware variant of
widest_paths_to. - widest_
paths_ with_ mode - Mode-aware variant of
widest_paths.
Type Aliases§
- Widest
Path Result - One entry of
widest_paths_to’s output:Some((vertices, edges))for a reachable target,Nonefor unreachable. Each vertex chain begins with the source and ends with the target; each edge chain has length one less.