crates/kleene-graph/src/lib.rs
//! Graph algorithms written once against [`kleene_sparse::SparseBackend`].
//!
//! | Algorithm | Here | On |
//! |---|---|---|
//! | Breadth-first search | [`bfs`], [`bfs_with_generic`] | in-place push and pull steps, visited mask; a level may move to the host and back ([`Place`]) |
//! | Breadth-first search on the CPU | [`beamer_bfs`] (the CPU backend's [`bfs`]), [`beamer_hops`] (its hop counts) | direction-optimizing: push from per-thread lists, pull over owned words of the open set, Beamer's switch |
//! | Many searches on the CPU | [`BfsMany`] (one source each, kept searchers) | the device's threads shared out among searchers with a state each, sources taken from a shared counter; as many as [`MANY_BUDGET`] holds, else one at a time on all threads |
//! | Propagation to a fixpoint | [`propagate`], [`propagate_with`] | `vxm` of what changed, `accumulate` |
//! | Shortest paths, path kept | [`sssp`], [`sssp_of`] | delta-stepping with settled vertices masked out, push or pull, over `(distance << 32) \| parent` words |
//! | Shortest paths on the CPU | [`delta_stepping`] (the CPU backend's [`sssp_of`]) | delta-stepping with bucket fusion: light edges relaxed within the bucket, heavy edges once, per-thread buckets, small refills worked at once; width [`delta_for`] |
//! | Set propagation | [`reach_sets`] | bitset union, 64 sources a word |
//! | Labelled set propagation | [`label_reach`] | each edge passes only its set's sources ([`EdgeSets`]): the edge valued by its set's word, union as add, intersection as multiply; on a CPU device with an engine, its mask walk with edge sets |
//! | PageRank | [`pagerank`], [`pagerank_of`] | GAP's pull rounds, damping 0.85, L1 tolerance 1e-4, on the CPU device's workers; [`pagerank_of`] through the backend (a GPU's rounds on the GPU) |
//! | Betweenness | [`betweenness`] | Brandes from sampled sources, level by level: path counts pulled from parents, dependencies pulled from children |
//! | Triangles | [`triangles`] | on [`undirected`]: lower neighbours (renumbered by falling degree when skewed), sorted intersections |
//! | Harmonic centrality | [`harmonic`] | exact: a breadth-first search from every vertex, 64 at once (a bit a source in each vertex's frontier and seen words), small levels pushed and large ones pulled, each level's first reached counted per source |
//! | Harmonic centrality, estimated | [`harmonic_estimate`] | HyperBall: a HyperLogLog counter per vertex (2^b registers, [`HyperBallOptions`]), each round the register-wise maximum over the out-neighbours' counters that changed, the score adding each round's growth of the ball's estimate over the distance |
//! | k-truss, truss numbers | [`ktruss`], [`truss_numbers`] | on [`undirected`]: every edge's support from the triangles found once each (bit sets per worker), then rounds peeling the edges below `k - 2`, each broken triangle counted down once |
//! | Maximal independent set | [`mis`] | on [`undirected`]: fixed priorities from a seed ([`mis_priority`]), rounds in which every undecided vertex above its undecided neighbours joins and its neighbours leave (the greedy set by falling priority) |
//! | Minimum spanning forest | [`spanning_forest`] | Borůvka's rounds on the CPU device's workers: each component's lightest edge out by atomic minima (weight, then entry place: one forest whatever the workers), pairs broken by the lower root, hooks followed with path halving, edges inside a component dropped; unsigned, signed and float weights ([`ForestWeight`]) |
//! | Maximum flow | [`max_flow`] | push-relabel in rounds on the CPU device's workers (Hong's lock-free pushes to the lowest neighbour, atomic capacities and excesses; exact heights again by a backward search after a pass of work); then Dinic's phases (level searches on the workers, blocking flows on one thread), normally one search that proves the flow maximum; the residual graph built on the workers; the flow per entry and the source's side of a minimum cut |
//! | Split | [`Split`] by a [`SplitKey`] (a node property, id blocks, a hash): per [`Part`] the sub-matrix of its internal edges in local ids and its [`Border`] (edges out with the target's part and id); ids one space, a base and a count per part ([`SplitIds`], or [`SplitIds::of`] from the node count and the key alone); one part alone by [`Split::part_only`] (only the part's rows read) or [`Split::part_of_edges`] (a scan that keeps the part's) |
//! | Computed split | [`computed_split`] ([`SplitCompute`] in, [`ComputedSplit`] out; [`crossing_edges`] and [`parts_of_key`] to compare it with hash and id blocks) | balanced label spreading (Spinner) in integers: a hash start within each part's limit, rounds in which each node wants the part most of its neighbours are in (weighted by the part's room, one pass over the edges on the backend: [`GraphBackend::split_votes`]), parts let in only as many as they have room for by a hash of (node, round), every other node by hash allowed to move; the best round kept; the same list on every device |
//! | Local-first rounds | [`reach_rounds`] (a [`ReachPart`] per part, [`part_search`] its search), [`closure_rounds`] ([`ClosurePart`]), [`components_rounds`] ([`ComponentsPart`]), [`sssp_rounds`] ([`SsspPart`]), [`khop_rounds`] ([`KhopPart`], level by level: one hop a round) | each part runs the engine's kernel on its own part until nothing is new, then hands on only its new border nodes ([`Sends`], one entry per node by [`Sends::combine`], compact between machines by [`Sends::to_compact`]; [`Exchanges`] counts them); one part ([`Split::whole`]) is one call of today's kernel |
//! | Sliced search over machines that hold the same whole graph | [`search_slices`] ([`slice_rounds`] over a [`ReachSlice`] per machine; reach and k-hop counts) | each level cut by edge count into slices weighted by the machines' cores ([`Slices`]), every machine computing its own slice; only the new vertices travel ([`Found`], a [`NodeSet`]: a list or a bit map, whichever is smaller, mzstd); the steps are [`beamer_bfs`]'s; many searches handed out whole by [`Slices::portion`]; one machine ([`Slices::one`]) is one call of today's kernel |
//! | One sweep in part order | [`reach_sweep`] in a [`PartOrder`] (the strong components of the part graph, feeders first, in levels) | a part outside a circle runs once, after its feeders; only a circle's parts loop among themselves; [`reach_rounds`]'s answer |
//! | Closure | [`closure`] | boolean `mxm` masked by the known pairs |
//! | Walks of bounded length | [`walk_ends`], [`walk_pairs`] | frontier push steps with nothing closed (GQL's WALK mode), or unmasked boolean `mxm` for (source, end) pairs; past the fewest edges, stopped when a step adds nothing; with no bound, a search or closure from there |
//! | Shortest paths as vertex lists | [`shortest_paths`] | per source a breadth-first search on the graph core, each vertex's parents (one level before, an edge to it) read off the host adjacency; one path per end through the lowest parents ([`Shortest::Any`]) or every shortest path ([`Shortest::All`], up to a limit) |
//! | Weak components | [`components`], [`components_of`] | FastSV with sampling: grandparents pulled over both edge orders (`mxv`), the giant component's rows skipped |
//! | Weak components on the CPU | [`afforest`] (the CPU backend's [`components_of`]); [`afforest_with`] on kept buffers ([`AfforestState`], counted on the workers) | Afforest: two neighbour rounds of lock-free union-find, the giant found by sampling, then only the edges of vertices outside it |
//! | Strong components | [`scc`], [`scc_of`] | trimming, masked min-label colouring, a colour-bound search back from the roots |
//! | Strong components on the CPU | [`multistep`] (the CPU backend's [`scc_of`]) | Multistep: trimming, one forward-backward search from the vertex of most in- times out-edges, max-label colouring with a colour-bound search back from the roots, Tarjan's search on one thread below [`TARJAN_BELOW`] vertices |
//!
//! Breadth-first search: from a set of sources, level by level, each step either
//! pushing the frontier along its out-edges (`vxm`) or letting every unvisited vertex pull
//! from its in-edges (`mxv` on the transpose), with the visited set as a complemented mask
//! so a vertex is never reached twice. The step direction is chosen per level (Beamer's
//! rule) unless it is fixed. A vertex mask limits the vertices a search may enter.
//!
//! Like kleene-sparse this crate depends on Arrow and kleene-sparse only, and on mzstd
//! (zstd in safe Rust) for the frontiers sent between machines.
mod afforest;
mod backend;
mod beamer;
mod bfs;
mod centrality;
mod closure;
mod components;
mod delta_stepping;
mod flow;
mod graph;
mod graphalytics;
mod harmonic;
mod hyperball;
mod ktruss;
mod labels;
mod many;
mod mis;
mod multistep;
mod order;
mod paths;
mod propagate;
mod rounds;
mod shortest;
mod slices;
mod spanning;
mod split;
mod split_compute;
mod walks;
pub use afforest::{AfforestState, afforest, afforest_with};
pub use backend::GraphBackend;
pub use beamer::{beamer_bfs, beamer_hops};
pub use bfs::{
Bfs, BfsOptions, BfsState, BfsSummary, Direction, LevelInfo, Place, Step, bfs, bfs_with,
bfs_with_generic, bfs_with_placed,
};
pub use centrality::{
PageRank, PageRankOptions, Relabel, Triangles, betweenness, pagerank, pagerank_of, triangles,
undirected,
};
pub use closure::{Closure, Side, closure};
pub use components::{
Components, SAMPLE, components, components_of, components_of_generic, scc, scc_of,
scc_of_generic,
};
pub use delta_stepping::{delta_for, delta_stepping};
pub use flow::{MaxFlow, MaxFlowF64, max_flow, max_flow_f64};
pub use graph::{Graph, GraphError};
pub use graphalytics::{Cdlp, LCC_MAX, cdlp, lcc};
pub use harmonic::harmonic;
pub use hyperball::{HarmonicEstimate, HyperBallOptions, harmonic_estimate};
pub use ktruss::{KTruss, ktruss, truss_numbers};
pub use labels::{EdgeSets, label_reach, label_reach_generic};
pub use many::{BfsMany, MANY_BUDGET, MANY_BYTES_PER_VERTEX};
pub use mis::{Mis, mis, mis_priority};
pub use multistep::{TARJAN_BELOW, multistep, multistep_with};
pub use order::PartOrder;
pub use paths::{
Paths, SourceSets, SsspOptions, reach_sets, reach_sets_generic, sssp, sssp_delta, sssp_of,
sssp_of_generic,
};
pub use propagate::{Propagation, propagate, propagate_with};
pub use rounds::{
ClosurePart, ClosureRounds, ComponentsPart, ComponentsRounds, Exchanges, KhopPart, ReachPart,
ReachRounds, SEND_NODE, SEND_PART, SEND_VALUE, Sends, SsspPart, SsspRounds, closure_rounds,
components_rounds, components_rounds_upto, khop_rounds, part_search, reach_rounds,
reach_rounds_upto, reach_sweep, sssp_rounds,
};
pub use shortest::{Shortest, ShortestPaths, shortest_paths};
pub use slices::{
Found, FoundCoder, LOCAL_BELOW, NodeSet, ReachSlice, SliceRun, Slices, search_slices,
slice_rounds,
};
pub use spanning::{ForestWeight, SpanningForest, spanning_forest};
pub use split::{Border, Part, PartSummary, Split, SplitIds, SplitKey};
pub use split_compute::{
ComputedSplit, MAX_COMPUTED_PARTS, SplitCompute, computed_split, crossing_edges, parts_of_key,
};
pub use walks::{Hops, WalkEnds, walk_counts, walk_ends, walk_pairs};
/// The result of a fallible operation of this crate.
pub type Result<T> = std::result::Result<T, GraphError>;
/// The README's example, run as a doctest.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;