spectre/
lib.rs

1//! Spectre is a small toolkit for analysing p2p network graphs, though it can also apply more generally
2//! to undirected graphs.
3//!
4//! # Basic usage
5//!
6//! The library is centered around the [`Graph`](graph::Graph) structure which can be constructed
7//! from one or more [`Edge`](edge::Edge) instances. Once constructed, various measurements and
8//! matrix representations of the graph can be computed.
9//!
10//! ```rust
11//! use std::net::SocketAddr;
12//!
13//! use spectre::edge::Edge;
14//! use spectre::graph::Graph;
15//!
16//! // Construct the graph instance.
17//! let mut graph = Graph::new();
18//!
19//! // Create some addresses to be part of a network topology.
20//! let addrs: Vec<SocketAddr> = (0..3)
21//!     .map(|i| format!("127.0.0.1:{i}").parse().unwrap())
22//!     .collect();
23//! let (a, b, c) = (addrs[0], addrs[1], addrs[2]);
24//!
25//! // Insert some edges, note the IDs can be any type that is `Copy + Eq + Hash + Ord`.
26//! graph.insert(Edge::new(a, b));
27//! graph.insert(Edge::new(a, c));
28//!
29//! // Compute some metrics on that state of the graph.
30//! let density = graph.density();
31//! let degree_centrality_delta = graph.degree_centrality_delta();
32//!
33//! // Matrices can be pretty printed...
34//! println!("{}", graph.laplacian_matrix());
35//! // ...outputs:
36//! //  ┌          ┐
37//! //  │  2 -1 -1 │
38//! //  │ -1  1  0 │
39//! //  │ -1  0  1 │
40//! //  └          ┘
41//! ```
42
43mod betweenness;
44mod closeness;
45pub mod edge;
46pub mod graph;