1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Return the subgraph with the vertices that satisfy the predicate.
//!
//! # Examples
//!
//! ```
//! use graaf::{
//! AdjacencyMap,
//! Arcs,
//! FilterVertices,
//! Vertices,
//! Wheel,
//! };
//!
//! let mut digraph = AdjacencyMap::wheel(9);
//! let subgraph = digraph.filter_vertices(|u| u % 2 == 0 && u < 6);
//!
//! assert!(subgraph.arcs().eq([(0, 2), (0, 4), (2, 0), (4, 0)]));
//! assert!(subgraph.vertices().eq([0, 2, 4]));
//! ```
/// Filter vertices
pub trait FilterVertices {
/// Return the subgraph with the vertices that satisfy the predicate.
///
/// # Panics
///
/// Panics if the subgraph has zero vertices.
///
/// # Examples
///
/// ```
/// use graaf::{
/// AdjacencyMap,
/// Arcs,
/// FilterVertices,
/// Vertices,
/// Wheel,
/// };
///
/// let mut digraph = AdjacencyMap::wheel(9);
/// let subgraph = digraph.filter_vertices(|u| u % 2 == 0 && u < 6);
///
/// assert!(subgraph.arcs().eq([(0, 2), (0, 4), (2, 0), (4, 0)]));
/// assert!(subgraph.vertices().eq([0, 2, 4]));
/// ```
#[must_use]
fn filter_vertices<P>(&self, predicate: P) -> Self
where
P: Fn(usize) -> bool;
}