graaf/op/is_superdigraph.rs
1//! Check whether a digraph is another digraph's superdigraph.
2//!
3//! If digraph `H` is a subdigraph of digraph `D`, then `D` is a superdigraph
4//! of `H`; the vertex set of `H` is a subset of the vertex set of `D` and the
5//! arc set of `H` is a subset of the arc set of `D`. Additionally, the
6//! end-vertices of each arc in `H` must be vertices in `H`.
7//!
8//! # Examples
9//!
10//! ```
11//! use graaf::{
12//! AddArc,
13//! AdjacencyList,
14//! Circuit,
15//! Empty,
16//! IsSuperdigraph,
17//! };
18//!
19//! let mut h = AdjacencyList::empty(3);
20//!
21//! h.add_arc(0, 1);
22//!
23//! let d = AdjacencyList::circuit(3);
24//!
25//! assert!(d.is_superdigraph(&h));
26//!
27//! h.add_arc(0, 2);
28//!
29//! assert!(!d.is_superdigraph(&h));
30//! ```
31//!
32//! Every digraph is a superdigraph of itself.
33//!
34//! ```
35//! use graaf::{
36//! AdjacencyList,
37//! IsSuperdigraph,
38//! RandomTournament,
39//! };
40//!
41//! let tournament = AdjacencyList::random_tournament(4, 0);
42//!
43//! assert!(tournament.is_superdigraph(&tournament));
44//! ```
45
46use crate::IsSubdigraph;
47
48/// Check whether a digraph is another digraph's superdigraph.
49pub trait IsSuperdigraph {
50 /// Check whether the digraph is another digraph's superdigraph.
51 ///
52 /// # Arguments
53 ///
54 /// * `d`: The digraph to compare against.
55 ///
56 /// # Examples
57 ///
58 /// ```
59 /// use graaf::{
60 /// AddArc,
61 /// AdjacencyList,
62 /// Circuit,
63 /// Empty,
64 /// IsSuperdigraph,
65 /// };
66 ///
67 /// let mut h = AdjacencyList::empty(3);
68 ///
69 /// h.add_arc(0, 1);
70 ///
71 /// let d = AdjacencyList::circuit(4);
72 ///
73 /// assert!(d.is_superdigraph(&h));
74 ///
75 /// h.add_arc(0, 2);
76 ///
77 /// assert!(!d.is_superdigraph(&h));
78 /// ```
79 ///
80 /// Every digraph is a superdigraph of itself.
81 ///
82 /// ```
83 /// use graaf::{
84 /// AdjacencyList,
85 /// IsSuperdigraph,
86 /// RandomTournament,
87 /// };
88 ///
89 /// let tournament = AdjacencyList::random_tournament(4, 0);
90 ///
91 /// assert!(tournament.is_superdigraph(&tournament));
92 /// ```
93 #[must_use]
94 fn is_superdigraph(&self, d: &Self) -> bool;
95}
96
97impl<D> IsSuperdigraph for D
98where
99 D: IsSubdigraph,
100{
101 fn is_superdigraph(&self, d: &Self) -> bool {
102 d.is_subdigraph(self)
103 }
104}