Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

58
vendor/petgraph/benches/acyclic.rs vendored Normal file
View File

@@ -0,0 +1,58 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::algo::{toposort, DfsSpace};
use petgraph::prelude::*;
use petgraph::{acyclic::Acyclic, data::Build};
use std::cmp::max;
use test::Bencher;
/// Dynamic toposort using Acyclic<G>
#[bench]
#[allow(clippy::needless_range_loop)]
fn acyclic_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 100;
let mut g = Acyclic::<DiGraph<usize, ()>>::new();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
bench.iter(|| {
let mut g = g.clone();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32) as usize;
let j_to = i;
for j in j_from..j_to {
let n2 = nodes[j];
g.try_add_edge(n1, n2, ()).unwrap();
}
}
});
}
/// As a baseline: build the graph and toposort it every time a new edge is added
#[bench]
#[allow(clippy::needless_range_loop)]
fn toposort_baseline_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 100;
let mut g = DiGraph::<usize, ()>::new();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
bench.iter(|| {
let mut g = g.clone();
let mut space = DfsSpace::new(&g);
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32) as usize;
let j_to = i;
for j in j_from..j_to {
let n2 = nodes[j];
g.add_edge(n1, n2, ());
let _order = toposort(&g, Some(&mut space));
}
}
});
}

62
vendor/petgraph/benches/bellman_ford.rs vendored Normal file
View File

@@ -0,0 +1,62 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use std::cmp::{max, min};
use test::Bencher;
use petgraph::algo::{bellman_ford, find_negative_cycle};
#[bench]
#[allow(clippy::needless_range_loop)]
fn bellman_ford_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 100;
let mut g = Graph::new();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
let j_to = min(NODE_COUNT, j_from + neighbour_count);
for j in j_from..j_to {
let n2 = nodes[j];
let mut distance: f64 = ((i + 3) % 10) as f64;
if n1 != n2 {
distance -= 1.0
}
g.add_edge(n1, n2, distance);
}
}
bench.iter(|| {
let _scores = bellman_ford(&g, nodes[0]);
});
}
#[bench]
#[allow(clippy::needless_range_loop)]
fn find_negative_cycle_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 100;
let mut g = Graph::new();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
let j_to = min(NODE_COUNT, j_from + neighbour_count);
for j in j_from..j_to {
let n2 = nodes[j];
let mut distance: f64 = ((i + 3) % 10) as f64;
if n1 != n2 {
distance -= 1.0
}
g.add_edge(n1, n2, distance);
}
}
bench.iter(|| {
let _scores = find_negative_cycle(&g, nodes[0]);
});
}

31
vendor/petgraph/benches/coloring.rs vendored Normal file
View File

@@ -0,0 +1,31 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use std::cmp::{max, min};
use test::Bencher;
use petgraph::algo::dsatur_coloring;
#[bench]
fn dsatur_coloring_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 10_000;
let mut g = Graph::new_undirected();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).into_iter().map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
let j_to = min(NODE_COUNT, j_from + neighbour_count);
for j in j_from..j_to {
let n2 = nodes[j];
g.add_edge(n1, n2, ());
}
}
bench.iter(|| {
let _scores = dsatur_coloring(&g);
});
}

View File

@@ -0,0 +1,334 @@
use std::marker::PhantomData;
use petgraph::data::Build;
use petgraph::prelude::*;
use petgraph::visit::NodeIndexable;
use petgraph::EdgeType;
/// Petersen A and B are isomorphic
///
/// http://www.dharwadker.org/tevet/isomorphism/
const PETERSEN_A: &str = "
0 1 0 0 1 0 1 0 0 0
1 0 1 0 0 0 0 1 0 0
0 1 0 1 0 0 0 0 1 0
0 0 1 0 1 0 0 0 0 1
1 0 0 1 0 1 0 0 0 0
0 0 0 0 1 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1
0 1 0 0 0 1 0 0 0 1
0 0 1 0 0 1 1 0 0 0
0 0 0 1 0 0 1 1 0 0
";
const PETERSEN_B: &str = "
0 0 0 1 0 1 0 0 0 1
0 0 0 1 1 0 1 0 0 0
0 0 0 0 0 0 1 1 0 1
1 1 0 0 0 0 0 1 0 0
0 1 0 0 0 0 0 0 1 1
1 0 0 0 0 0 1 0 1 0
0 1 1 0 0 1 0 0 0 0
0 0 1 1 0 0 0 0 1 0
0 0 0 0 1 1 0 1 0 0
1 0 1 0 1 0 0 0 0 0
";
/// An almost full set, isomorphic
const FULL_A: &str = "
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 0 1
1 1 1 1 1 1 1 1 1 1
";
const FULL_B: &str = "
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 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0 0 0 1 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1
1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0
";
/// Parse a text adjacency matrix format into a directed graph
fn parse_graph<Ty, G>(s: &str) -> G
where
Ty: EdgeType,
G: Default + Build<NodeWeight = (), EdgeWeight = ()> + NodeIndexable,
{
let mut g: G = Default::default();
let s = s.trim();
let lines = s.lines().filter(|l| !l.is_empty());
for (row, line) in lines.enumerate() {
for (col, word) in line.split(' ').filter(|s| !s.is_empty()).enumerate() {
let has_edge = word.parse::<i32>().unwrap();
assert!(has_edge == 0 || has_edge == 1);
if has_edge == 0 {
continue;
}
while col >= g.node_count() || row >= g.node_count() {
g.add_node(());
}
let a = g.from_index(row);
let b = g.from_index(col);
g.update_edge(a, b, ());
}
}
g
}
pub struct GraphFactory<Ty, G = Graph<(), (), Ty>> {
ty: PhantomData<Ty>,
g: PhantomData<G>,
}
impl<Ty, G> GraphFactory<Ty, G>
where
Ty: EdgeType,
G: Default + Build<NodeWeight = (), EdgeWeight = ()> + NodeIndexable,
{
fn new() -> Self {
GraphFactory {
ty: PhantomData,
g: PhantomData,
}
}
pub fn petersen_a(self) -> G {
parse_graph::<Ty, _>(PETERSEN_A)
}
pub fn petersen_b(self) -> G {
parse_graph::<Ty, _>(PETERSEN_B)
}
pub fn full_a(self) -> G {
parse_graph::<Ty, _>(FULL_A)
}
pub fn full_b(self) -> G {
parse_graph::<Ty, _>(FULL_B)
}
pub fn praust_a(self) -> G {
parse_graph::<Ty, _>(PRAUST_A)
}
pub fn praust_b(self) -> G {
parse_graph::<Ty, _>(PRAUST_B)
}
pub fn bigger(self) -> G {
parse_graph::<Ty, _>(BIGGER)
}
pub fn bipartite(self) -> G {
parse_graph::<Ty, _>(BIPARTITE)
}
}
pub fn graph<Ty: EdgeType>() -> GraphFactory<Ty, Graph<(), (), Ty>> {
GraphFactory::new()
}
pub fn ungraph() -> GraphFactory<Undirected, Graph<(), (), Undirected>> {
graph()
}
pub fn digraph() -> GraphFactory<Directed, Graph<(), (), Directed>> {
graph()
}
pub fn stable_graph<Ty: EdgeType>() -> GraphFactory<Ty, StableGraph<(), (), Ty>> {
GraphFactory::new()
}
pub fn stable_ungraph() -> GraphFactory<Undirected, StableGraph<(), (), Undirected>> {
stable_graph()
}
pub fn stable_digraph() -> GraphFactory<Directed, StableGraph<(), (), Directed>> {
stable_graph()
}
pub fn tournament(node_count: usize) -> DiGraph<(), ()> {
let mut edge_forward = true;
let mut g = DiGraph::new();
for _ in 0..node_count {
g.add_node(());
}
for i in g.node_indices() {
for j in g.node_indices() {
if i >= j {
continue;
}
let (source, target) = if edge_forward { (i, j) } else { (j, i) };
g.add_edge(source, target, ());
edge_forward = !edge_forward;
}
}
g
}
/// An F_(1,n) graph (where **|E| == 2(|N|) - 1**) with pseudo-random edge directions.
pub fn directed_fan(n: usize) -> DiGraph<(), ()> {
let mut g = DiGraph::new();
for _ in 0..(n + 1) {
g.add_node(());
}
let mut indices = g.node_indices();
let ix_0 = indices.next().unwrap();
let mut edge_forward = true;
let mut prev_ix = None;
for ix in indices {
let (source, target) = if edge_forward { (ix_0, ix) } else { (ix, ix_0) };
g.add_edge(source, target, ());
if let Some(prev_ix) = prev_ix {
let (source, target) = if edge_forward {
(prev_ix, ix)
} else {
(ix, prev_ix)
};
g.add_edge(source, target, ());
}
edge_forward = !edge_forward;
prev_ix = Some(ix);
}
g
}

2
vendor/petgraph/benches/common/mod.rs vendored Normal file
View File

@@ -0,0 +1,2 @@
mod factories;
pub use factories::*;

33
vendor/petgraph/benches/dijkstra.rs vendored Normal file
View File

@@ -0,0 +1,33 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use std::cmp::{max, min};
use test::Bencher;
use petgraph::algo::dijkstra;
#[bench]
#[allow(clippy::needless_range_loop)]
fn dijkstra_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 10_000;
let mut g = Graph::new_undirected();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
let j_to = min(NODE_COUNT, j_from + neighbour_count);
for j in j_from..j_to {
let n2 = nodes[j];
let distance = (i + 3) % 10;
g.add_edge(n1, n2, distance);
}
}
bench.iter(|| {
let _scores = dijkstra(&g, nodes[0], None, |e| *e.weight());
});
}

View File

@@ -0,0 +1,55 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
use petgraph::algo::greedy_feedback_arc_set;
#[allow(dead_code)]
mod common;
use common::{directed_fan, tournament};
#[bench]
fn greedy_fas_tournament_10_bench(bench: &mut Bencher) {
let g = tournament(10);
bench.iter(|| greedy_feedback_arc_set(&g).for_each(|_| ()))
}
#[bench]
fn greedy_fas_tournament_50_bench(bench: &mut Bencher) {
let g = tournament(50);
bench.iter(|| greedy_feedback_arc_set(&g).for_each(|_| ()))
}
#[bench]
fn greedy_fas_tournament_200_bench(bench: &mut Bencher) {
let g = tournament(200);
bench.iter(|| greedy_feedback_arc_set(&g).for_each(|_| ()))
}
#[bench]
fn greedy_fas_fan_10_bench(bench: &mut Bencher) {
let g = directed_fan(10);
bench.iter(|| greedy_feedback_arc_set(&g).for_each(|_| ()))
}
#[bench]
fn greedy_fas_fan_200_bench(bench: &mut Bencher) {
let g = directed_fan(200);
bench.iter(|| greedy_feedback_arc_set(&g).for_each(|_| ()))
}
#[bench]
fn greedy_fas_fan_1000_bench(bench: &mut Bencher) {
let g = directed_fan(1000);
bench.iter(|| greedy_feedback_arc_set(&g).for_each(|_| ()))
}

View File

@@ -0,0 +1,33 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use std::cmp::{max, min};
use test::Bencher;
use petgraph::algo::floyd_warshall;
#[bench]
#[allow(clippy::needless_range_loop)]
fn floyd_warshall_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 100;
let mut g = Graph::new_undirected();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
let j_to = min(NODE_COUNT, j_from + neighbour_count);
for j in j_from..j_to {
let n2 = nodes[j];
let distance = (i + 3) % 10;
g.add_edge(n1, n2, distance);
}
}
bench.iter(|| {
let _scores = floyd_warshall(&g, |e| *e.weight());
});
}

View File

@@ -0,0 +1,24 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::algo::ford_fulkerson;
use petgraph::prelude::{Graph, NodeIndex};
use test::Bencher;
#[bench]
fn ford_fulkerson_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 1_000;
let mut g: Graph<usize, usize> = Graph::new();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT - 1 {
g.add_edge(nodes[i], nodes[i + 1], 1);
}
bench.iter(|| {
let _flow = ford_fulkerson(
&g,
NodeIndex::from(0),
NodeIndex::from(g.node_count() as u32 - 1),
);
});
}

View File

@@ -0,0 +1,37 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::graph6::from_graph6_representation;
use test::Bencher;
#[bench]
fn from_graph6_str_complete_7(bench: &mut Bencher) {
from_graph6_bench(bench, r"F~~~w");
}
#[bench]
fn from_graph6_str_petersen(bench: &mut Bencher) {
from_graph6_bench(bench, r"IheA@GUAo");
}
#[bench]
fn from_graph6_str_62(bench: &mut Bencher) {
from_graph6_bench(
bench,
r"}x@?xx|G[RO{QRDDMWAJ@XAT\M@IBsP?P[jJKOECP_QKSsL@_Th?mUp@@WC_woIl_nI?AF_ISAGNGxe?pikrJVOwWEqoMKhWGAjk[XPn?WUGrWC]jUjwPJLF@?OU?IGSoqT_rpEM[KCpTvGYBgRvOyJ`\adaY?qsESfR{IQWs?mT}bB@[|?p}MOCOEUZKMw]xKeV[en_EK{eBN?Add?H_@GeE_Bo@?_?PmabQuWc?FHVWcwCLWUF]l??WdIOtyePOc`Sb{SGCU[[__b[OiWnDeCXB@CwW@q_GAYY^eWD[tmoPDf{W]eKjzWCCKOj_",
);
}
#[bench]
fn from_graph6_str_63(bench: &mut Bencher) {
from_graph6_bench(
bench,
r"~??~`U@aoLr_G\V`YnUdSA[@PG?CjSvrrFONaJODKrXQMOMEcExcwEILVHfUDsB[rGLhVVYJgI?DRSBAgsFwAVzs@gct_AL`NkAoRCaHOaTGWcgPs{@a_s^HLZBaB_[W_o__U|aRGLpdK@{EJ?xQOCcOksK_X@AI`aleB\KDwlOX?_@`_K@SD?QOQ?dAz]?hb{UYvdRRoQPrGKdgfUKIDQM\mZCjJW|?~XcoyIHEr~HycEDToBFD?_DT?bYNaQaQ`BMAYWuyo@Uz{dQwViiepaHfAdaaGO[CHW]ggCka?s@g@b?cbI[a@`BlU^nFxy?YL?R[GKIPm_",
);
}
fn from_graph6_bench(bench: &mut Bencher, graph6_str: &str) {
bench.iter(|| (from_graph6_representation::<u16>(graph6_str.to_string())));
}

View File

@@ -0,0 +1,35 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::graph6::ToGraph6;
use test::Bencher;
#[allow(dead_code)]
mod common;
use common::ungraph;
#[bench]
fn graph6_string_praust_bench(bench: &mut Bencher) {
let a = ungraph().praust_a();
let b = ungraph().praust_b();
bench.iter(|| (a.graph6_string(), b.graph6_string()));
}
#[bench]
fn graph6_string_full_bench(bench: &mut Bencher) {
let a = ungraph().full_a();
let b = ungraph().full_b();
bench.iter(|| (a.graph6_string(), b.graph6_string()));
}
#[bench]
fn graph6_string_petersen_bench(bench: &mut Bencher) {
let a = ungraph().petersen_a();
let b = ungraph().petersen_b();
bench.iter(|| (a.graph6_string(), b.graph6_string()));
}

94
vendor/petgraph/benches/graphmap.rs vendored Normal file
View File

@@ -0,0 +1,94 @@
#![feature(test)]
#![cfg(feature = "rayon")]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use rayon::iter::ParallelIterator;
use std::hash::BuildHasher;
use test::Bencher;
#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct MyStruct {
u: String,
v: String,
w: String,
}
fn test_nodes() -> Vec<MyStruct> {
let mut nodes = vec![];
for i in 0..2500 {
nodes.push(MyStruct {
u: format!("X {}", i),
v: format!("Y {} Y", i),
w: format!("{}Z", i),
});
}
nodes
}
fn test_graph<H: BuildHasher + Default>(
data: &Vec<MyStruct>,
) -> GraphMap<&MyStruct, usize, Directed, H> {
let mut gr = GraphMap::new();
for i in 0..2500 {
gr.add_node(&data[i]);
}
for i in 0..1_000 {
for j in 999..2000 {
gr.add_edge(&data[i], &data[j], i * j);
}
}
gr
}
macro_rules! test_case_with_hasher {
($name:ident, $hasher:path) => {
#[bench]
fn $name(bench: &mut Bencher) {
let data = test_nodes();
let gr = test_graph::<$hasher>(&data);
bench.iter(|| {
let mut sources = vec![];
for n in gr.nodes() {
for (src, _, e) in gr.edges_directed(n, Direction::Outgoing) {
if *e == 500 {
sources.push(src.clone());
}
}
}
});
}
};
}
test_case_with_hasher!(graphmap_serial_bench, std::hash::RandomState);
test_case_with_hasher!(graphmap_serial_bench_fxhash, fxhash::FxBuildHasher);
test_case_with_hasher!(graphmap_serial_bench_ahash, ahash::RandomState);
#[bench]
fn graphmap_parallel_bench(bench: &mut Bencher) {
let data = test_nodes();
let gr = test_graph::<std::hash::RandomState>(&data);
bench.iter(|| {
let sources: Vec<MyStruct> = gr
.par_nodes()
.map(|n| {
let mut sources = vec![];
for (src, _, e) in gr.edges_directed(n, Direction::Outgoing) {
if *e == 500 {
sources.push(src.clone());
}
}
sources
})
.flatten()
.collect();
});
}

57
vendor/petgraph/benches/iso.rs vendored Normal file
View File

@@ -0,0 +1,57 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
#[allow(dead_code)]
mod common;
use common::*;
use petgraph::algo::is_isomorphic;
#[bench]
fn petersen_iso_bench(bench: &mut Bencher) {
let a = digraph().petersen_a();
let b = digraph().petersen_b();
bench.iter(|| is_isomorphic(&a, &b));
assert!(is_isomorphic(&a, &b));
}
#[bench]
fn petersen_undir_iso_bench(bench: &mut Bencher) {
let a = ungraph().petersen_a();
let b = ungraph().petersen_b();
bench.iter(|| is_isomorphic(&a, &b));
assert!(is_isomorphic(&a, &b));
}
#[bench]
fn full_iso_bench(bench: &mut Bencher) {
let a = ungraph().full_a();
let b = ungraph().full_b();
bench.iter(|| is_isomorphic(&a, &b));
assert!(is_isomorphic(&a, &b));
}
#[bench]
fn praust_dir_no_iso_bench(bench: &mut Bencher) {
let a = digraph().praust_a();
let b = digraph().praust_b();
bench.iter(|| is_isomorphic(&a, &b));
assert!(!is_isomorphic(&a, &b));
}
#[bench]
fn praust_undir_no_iso_bench(bench: &mut Bencher) {
let a = ungraph().praust_a();
let b = ungraph().praust_b();
bench.iter(|| is_isomorphic(&a, &b));
assert!(!is_isomorphic(&a, &b));
}

View File

@@ -0,0 +1,31 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use std::cmp::{max, min};
use test::Bencher;
use petgraph::algo::k_shortest_path;
#[bench]
#[allow(clippy::needless_range_loop)]
fn k_shortest_path_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 10_000;
let mut g = Graph::new_undirected();
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
for i in 0..NODE_COUNT {
let n1 = nodes[i];
let neighbour_count = i % 8 + 3;
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
let j_to = min(NODE_COUNT, j_from + neighbour_count);
for j in j_from..j_to {
let n2 = nodes[j];
let distance = (i + 3) % 10;
g.add_edge(n1, n2, distance);
}
}
bench.iter(|| k_shortest_path(&g, nodes[0], None, 2, |e| *e.weight()));
}

78
vendor/petgraph/benches/matching.rs vendored Normal file
View File

@@ -0,0 +1,78 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
#[allow(dead_code)]
mod common;
use common::*;
use petgraph::algo::{greedy_matching, maximum_matching};
use petgraph::graph::UnGraph;
fn huge() -> UnGraph<(), ()> {
static NODE_COUNT: u32 = 1_000;
let mut edges = Vec::new();
for i in 0..NODE_COUNT {
for j in i..NODE_COUNT {
if i % 3 == 0 && j % 2 == 0 {
edges.push((i, j));
}
}
}
// 999 nodes, 83500 edges
UnGraph::from_edges(&edges)
}
#[bench]
fn greedy_matching_bipartite(bench: &mut Bencher) {
let g = ungraph().bipartite();
bench.iter(|| greedy_matching(&g));
}
#[bench]
fn greedy_matching_full(bench: &mut Bencher) {
let g = ungraph().full_a();
bench.iter(|| greedy_matching(&g));
}
#[bench]
fn greedy_matching_bigger(bench: &mut Bencher) {
let g = ungraph().bigger();
bench.iter(|| greedy_matching(&g));
}
#[bench]
fn greedy_matching_huge(bench: &mut Bencher) {
let g = huge();
bench.iter(|| greedy_matching(&g));
}
#[bench]
fn maximum_matching_bipartite(bench: &mut Bencher) {
let g = ungraph().bipartite();
bench.iter(|| maximum_matching(&g));
}
#[bench]
fn maximum_matching_full(bench: &mut Bencher) {
let g = ungraph().full_a();
bench.iter(|| maximum_matching(&g));
}
#[bench]
fn maximum_matching_bigger(bench: &mut Bencher) {
let g = ungraph().bigger();
bench.iter(|| maximum_matching(&g));
}
#[bench]
fn maximum_matching_huge(bench: &mut Bencher) {
let g = huge();
bench.iter(|| maximum_matching(&g));
}

246
vendor/petgraph/benches/matrix_graph.rs vendored Normal file
View File

@@ -0,0 +1,246 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
use petgraph::algo;
use petgraph::matrix_graph::{node_index, MatrixGraph};
use petgraph::{Directed, EdgeType, Incoming, Outgoing};
#[bench]
fn add_100_nodes(b: &mut test::Bencher) {
b.iter(|| {
let mut g = MatrixGraph::<(), ()>::with_capacity(100);
for _ in 0..100 {
let _ = g.add_node(());
}
});
}
#[bench]
fn add_100_edges_to_self(b: &mut test::Bencher) {
let mut g = MatrixGraph::<(), ()>::with_capacity(100);
let nodes: Vec<_> = (0..100).map(|_| g.add_node(())).collect();
let g = g;
b.iter(|| {
let mut g = g.clone();
for &node in nodes.iter() {
g.add_edge(node, node, ());
}
});
}
#[bench]
fn add_5_edges_for_each_of_100_nodes(b: &mut test::Bencher) {
let mut g = MatrixGraph::<(), ()>::with_capacity(100);
let nodes: Vec<_> = (0..100).map(|_| g.add_node(())).collect();
let g = g;
let edges_to_add: Vec<_> = nodes
.iter()
.enumerate()
.flat_map(|(i, &node)| {
let edges: Vec<_> = (0..5)
.map(|j| (i + j + 1) % nodes.len())
.map(|j| (node, nodes[j]))
.collect();
edges
})
.collect();
b.iter(|| {
let mut g = g.clone();
for &(source, target) in edges_to_add.iter() {
g.add_edge(source, target, ());
}
});
}
#[bench]
fn add_edges_from_root(bench: &mut test::Bencher) {
bench.iter(|| {
let mut gr = MatrixGraph::new();
let a = gr.add_node(());
for _ in 0..100 {
let b = gr.add_node(());
gr.add_edge(a, b, ());
}
});
}
#[bench]
fn add_adjacent_edges(bench: &mut test::Bencher) {
bench.iter(|| {
let mut gr = MatrixGraph::new();
let mut prev = None;
for _ in 0..100 {
let b = gr.add_node(());
if let Some(a) = prev {
gr.add_edge(a, b, ());
}
prev = Some(b);
}
});
}
/// An almost full set
const FULL: &str = "
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 0 1
1 1 1 1 1 1 1 1 1 1
";
const BIGGER: &str = "
0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 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0 0 1 1 1 0 0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 0
0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1
0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 1 0
0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1
0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 1
0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1
0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 1 0
";
/// Parse a text adjacency matrix format into a directed graph
fn parse_matrix<Ty: EdgeType>(s: &str) -> MatrixGraph<(), (), Ty> {
let mut gr = MatrixGraph::default();
let s = s.trim();
let lines = s.lines().filter(|l| !l.is_empty());
for (row, line) in lines.enumerate() {
for (col, word) in line.split(' ').filter(|s| !s.is_empty()).enumerate() {
let has_edge = word.parse::<i32>().unwrap();
assert!(has_edge == 0 || has_edge == 1);
if has_edge == 0 {
continue;
}
while col >= gr.node_count() || row >= gr.node_count() {
gr.add_node(());
}
gr.add_edge(node_index(row), node_index(col), ());
}
}
gr
}
#[bench]
fn full_edges_out(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(FULL);
bench.iter(|| a.edges_directed(node_index(1), Outgoing).count())
}
#[bench]
fn full_edges_in(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(FULL);
bench.iter(|| a.edges_directed(node_index(1), Incoming).count())
}
#[bench]
fn full_neighbors_out(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(FULL);
bench.iter(|| a.neighbors_directed(node_index(1), Outgoing).count())
}
#[bench]
fn full_neighbors_in(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(FULL);
bench.iter(|| a.neighbors_directed(node_index(1), Incoming).count())
}
#[bench]
fn full_kosaraju_sccs(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(FULL);
bench.iter(|| algo::kosaraju_scc(&a));
}
#[bench]
fn full_tarjan_sccs(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(FULL);
bench.iter(|| algo::tarjan_scc(&a));
}
#[bench]
fn bigger_edges_out(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(BIGGER);
bench.iter(|| a.edges_directed(node_index(1), Outgoing).count())
}
#[bench]
fn bigger_edges_in(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(BIGGER);
bench.iter(|| a.edges_directed(node_index(1), Incoming).count())
}
#[bench]
fn bigger_neighbors_out(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(BIGGER);
bench.iter(|| a.neighbors_directed(node_index(1), Outgoing).count())
}
#[bench]
fn bigger_neighbors_in(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(BIGGER);
bench.iter(|| a.neighbors_directed(node_index(1), Incoming).count())
}
#[bench]
fn bigger_kosaraju_sccs(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(BIGGER);
bench.iter(|| algo::kosaraju_scc(&a));
}
#[bench]
fn bigger_tarjan_sccs(bench: &mut Bencher) {
let a = parse_matrix::<Directed>(BIGGER);
bench.iter(|| algo::tarjan_scc(&a));
}

View File

@@ -0,0 +1,60 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
#[allow(dead_code)]
mod common;
use common::{digraph, ungraph};
use petgraph::algo::min_spanning_tree;
#[bench]
fn min_spanning_tree_praust_undir_bench(bench: &mut Bencher) {
let a = ungraph().praust_a();
let b = ungraph().praust_b();
bench.iter(|| (min_spanning_tree(&a), min_spanning_tree(&b)));
}
#[bench]
fn min_spanning_tree_praust_dir_bench(bench: &mut Bencher) {
let a = digraph().praust_a();
let b = digraph().praust_b();
bench.iter(|| (min_spanning_tree(&a), min_spanning_tree(&b)));
}
#[bench]
fn min_spanning_tree_full_undir_bench(bench: &mut Bencher) {
let a = ungraph().full_a();
let b = ungraph().full_b();
bench.iter(|| (min_spanning_tree(&a), min_spanning_tree(&b)));
}
#[bench]
fn min_spanning_tree_full_dir_bench(bench: &mut Bencher) {
let a = digraph().full_a();
let b = digraph().full_b();
bench.iter(|| (min_spanning_tree(&a), min_spanning_tree(&b)));
}
#[bench]
fn min_spanning_tree_petersen_undir_bench(bench: &mut Bencher) {
let a = ungraph().petersen_a();
let b = ungraph().petersen_b();
bench.iter(|| (min_spanning_tree(&a), min_spanning_tree(&b)));
}
#[bench]
fn min_spanning_tree_petersen_dir_bench(bench: &mut Bencher) {
let a = digraph().petersen_a();
let b = digraph().petersen_b();
bench.iter(|| (min_spanning_tree(&a), min_spanning_tree(&b)));
}

52
vendor/petgraph/benches/ograph.rs vendored Normal file
View File

@@ -0,0 +1,52 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::graph::Graph;
#[bench]
fn bench_inser(b: &mut test::Bencher) {
let mut og = Graph::new();
let fst = og.add_node(0i32);
for x in 1..125 {
let n = og.add_node(x);
og.add_edge(fst, n, ());
}
b.iter(|| og.add_node(1))
}
#[bench]
fn bench_add_edge(b: &mut test::Bencher) {
let mut og = Graph::new();
for _ in 0..100 {
og.add_node(());
}
b.iter(|| {
for (a, b) in og.node_indices().zip(og.node_indices().skip(1)) {
og.add_edge(a, b, ());
}
og.clear_edges();
})
}
#[bench]
fn bench_remove(b: &mut test::Bencher) {
// removal is very slow in a big graph.
// and this one doesn't even have many nodes.
let mut og = Graph::new();
let fst = og.add_node(0i32);
let mut prev = fst;
for x in 1..1250 {
let n = og.add_node(x);
og.add_edge(prev, n, ());
prev = n;
}
//println!("{}", og);
b.iter(|| {
for _ in 0..100 {
og.remove_node(fst);
}
})
}

36
vendor/petgraph/benches/page_rank.rs vendored Normal file
View File

@@ -0,0 +1,36 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
use petgraph::algo::page_rank;
#[allow(dead_code)]
mod common;
use common::directed_fan;
#[cfg(feature = "rayon")]
use petgraph::algo::page_rank::parallel_page_rank;
#[cfg(feature = "rayon")]
use rayon::prelude::*;
#[bench]
fn page_rank_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 500;
let g = directed_fan(NODE_COUNT);
bench.iter(|| {
let _ranks = page_rank(&g, 0.6_f64, 10);
});
}
#[bench]
#[cfg(feature = "rayon")]
fn par_page_rank_bench(bench: &mut Bencher) {
static NODE_COUNT: usize = 2_000;
let g = directed_fan(NODE_COUNT);
bench.iter(|| {
let _ranks = parallel_page_rank(&g, 0.6_f64, 100, None);
});
}

55
vendor/petgraph/benches/serialize.rs vendored Normal file
View File

@@ -0,0 +1,55 @@
#![feature(test)]
#[cfg(feature = "serde-1")]
mod serialize {
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use rand::Rng;
use test::Bencher;
const NUM_NODES: usize = 1_000_000;
const NUM_EDGES: usize = 100_000;
const NUM_HOLES: usize = 1_000_000;
fn make_stable_graph() -> StableGraph<u32, u32> {
let mut g = StableGraph::with_capacity(NUM_NODES + NUM_HOLES, NUM_EDGES);
let indices: Vec<_> = (0..NUM_NODES + NUM_HOLES)
.map(|i| g.add_node(i as u32))
.collect();
let mut rng = rand::thread_rng();
g.extend_with_edges((0..NUM_EDGES).map(|_| {
let first = rng.gen_range(0, NUM_NODES + NUM_HOLES);
let second = rng.gen_range(0, NUM_NODES + NUM_HOLES - 1);
let second = second + (second >= first) as usize;
let weight: u32 = rng.gen();
(indices[first], indices[second], weight)
}));
// Remove nodes to make the structure a bit more interesting
while g.node_count() > NUM_NODES {
let idx = rng.gen_range(0, indices.len());
g.remove_node(indices[idx]);
}
g
}
#[bench]
fn serialize_stable_graph(bench: &mut Bencher) {
let graph = make_stable_graph();
bench.iter(|| bincode::serialize(&graph).unwrap());
}
#[bench]
fn deserialize_stable_graph(bench: &mut Bencher) {
let graph = make_stable_graph();
let data = bincode::serialize(&graph).unwrap();
bench.iter(|| {
let graph2: StableGraph<u32, u32> = bincode::deserialize(&data).unwrap();
graph2
});
}
}

97
vendor/petgraph/benches/stable_graph.rs vendored Normal file
View File

@@ -0,0 +1,97 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use petgraph::prelude::*;
use test::Bencher;
#[allow(dead_code)]
mod common;
use common::*;
use petgraph::stable_graph::node_index;
#[bench]
fn full_edges_default(bench: &mut Bencher) {
let a = stable_digraph().full_a();
bench.iter(|| a.edges(node_index(1)).count())
}
#[bench]
fn full_edges_out(bench: &mut Bencher) {
let a = stable_digraph().full_a();
bench.iter(|| a.edges_directed(node_index(1), Outgoing).count())
}
#[bench]
fn full_edges_in(bench: &mut Bencher) {
let a = stable_digraph().full_a();
bench.iter(|| a.edges_directed(node_index(1), Incoming).count())
}
#[bench]
fn neighbors_default(bench: &mut Bencher) {
let a = stable_digraph().full_a();
bench.iter(|| a.neighbors(node_index(1)).count())
}
#[bench]
fn neighbors_out(bench: &mut Bencher) {
let a = stable_digraph().full_a();
bench.iter(|| a.neighbors_directed(node_index(1), Outgoing).count())
}
#[bench]
fn neighbors_in(bench: &mut Bencher) {
let a = stable_digraph().full_a();
bench.iter(|| a.neighbors_directed(node_index(1), Incoming).count())
}
#[bench]
fn sccs_kosaraju_stable_graph(bench: &mut Bencher) {
let a = stable_digraph().bigger();
bench.iter(|| petgraph::algo::kosaraju_scc(&a));
}
#[bench]
fn sccs_kosaraju_graph(bench: &mut Bencher) {
let a = digraph().bigger();
bench.iter(|| petgraph::algo::kosaraju_scc(&a));
}
#[bench]
fn sccs_tarjan_stable_graph(bench: &mut Bencher) {
let a = stable_digraph().bigger();
bench.iter(|| petgraph::algo::tarjan_scc(&a));
}
#[bench]
fn sccs_tarjan_graph(bench: &mut Bencher) {
let a = digraph().bigger();
bench.iter(|| petgraph::algo::tarjan_scc(&a));
}
#[bench]
fn stable_graph_map(bench: &mut Bencher) {
let a = stable_digraph().bigger();
bench.iter(|| a.map(|i, _| i, |i, _| i));
}
#[bench]
fn graph_map(bench: &mut Bencher) {
let a = digraph().bigger();
bench.iter(|| a.map(|i, _| i, |i, _| i));
}
#[bench]
fn stable_graph_retain_nodes(bench: &mut Bencher) {
let mut a = stable_digraph().bigger();
bench.iter(|| a.retain_nodes(|_gr, i| (i.index() + 1) % 3700 != 0));
}
#[bench]
fn stable_graph_retain_edges(bench: &mut Bencher) {
let mut a = stable_digraph().bigger();
bench.iter(|| a.retain_edges(|_gr, i| (i.index() + 1) % 3700 != 0));
}

108
vendor/petgraph/benches/unionfind.rs vendored Normal file
View File

@@ -0,0 +1,108 @@
#![feature(test)]
extern crate petgraph;
extern crate test;
use test::Bencher;
#[allow(dead_code)]
mod common;
use common::*;
use petgraph::algo::{connected_components, is_cyclic_undirected};
#[bench]
fn connected_components_praust_undir_bench(bench: &mut Bencher) {
let a = ungraph().praust_a();
let b = ungraph().praust_b();
bench.iter(|| (connected_components(&a), connected_components(&b)));
}
#[bench]
fn connected_components_praust_dir_bench(bench: &mut Bencher) {
let a = digraph().praust_a();
let b = digraph().praust_b();
bench.iter(|| (connected_components(&a), connected_components(&b)));
}
#[bench]
fn connected_components_full_undir_bench(bench: &mut Bencher) {
let a = ungraph().full_a();
let b = ungraph().full_b();
bench.iter(|| (connected_components(&a), connected_components(&b)));
}
#[bench]
fn connected_components_full_dir_bench(bench: &mut Bencher) {
let a = digraph().full_a();
let b = digraph().full_b();
bench.iter(|| (connected_components(&a), connected_components(&b)));
}
#[bench]
fn connected_components_petersen_undir_bench(bench: &mut Bencher) {
let a = ungraph().petersen_a();
let b = ungraph().petersen_b();
bench.iter(|| (connected_components(&a), connected_components(&b)));
}
#[bench]
fn connected_components_petersen_dir_bench(bench: &mut Bencher) {
let a = digraph().petersen_a();
let b = digraph().petersen_b();
bench.iter(|| (connected_components(&a), connected_components(&b)));
}
#[bench]
fn is_cyclic_undirected_praust_undir_bench(bench: &mut Bencher) {
let a = ungraph().praust_a();
let b = ungraph().praust_b();
bench.iter(|| (is_cyclic_undirected(&a), is_cyclic_undirected(&b)));
}
#[bench]
fn is_cyclic_undirected_praust_dir_bench(bench: &mut Bencher) {
let a = digraph().praust_a();
let b = digraph().praust_b();
bench.iter(|| (is_cyclic_undirected(&a), is_cyclic_undirected(&b)));
}
#[bench]
fn is_cyclic_undirected_full_undir_bench(bench: &mut Bencher) {
let a = ungraph().full_a();
let b = ungraph().full_b();
bench.iter(|| (is_cyclic_undirected(&a), is_cyclic_undirected(&b)));
}
#[bench]
fn is_cyclic_undirected_full_dir_bench(bench: &mut Bencher) {
let a = digraph().full_a();
let b = digraph().full_b();
bench.iter(|| (is_cyclic_undirected(&a), is_cyclic_undirected(&b)));
}
#[bench]
fn is_cyclic_undirected_petersen_undir_bench(bench: &mut Bencher) {
let a = ungraph().petersen_a();
let b = ungraph().petersen_b();
bench.iter(|| (is_cyclic_undirected(&a), is_cyclic_undirected(&b)));
}
#[bench]
fn is_cyclic_undirected_petersen_dir_bench(bench: &mut Bencher) {
let a = digraph().petersen_a();
let b = digraph().petersen_b();
bench.iter(|| (is_cyclic_undirected(&a), is_cyclic_undirected(&b)));
}