graph_base/interfaces/
edge.rs1use std::fmt::Display;
2use std::hash::Hash;
3use std::collections::HashSet;
4
5use super::hypergraph::IdVector;
6
7pub trait Hyperedge: Eq + Hash + Clone + IdVector {
8 fn id_set(&self) -> HashSet<usize>;
9 fn is_subset(&self, other: &Self) -> bool {
10 self.id_set().is_subset(&other.id_set())
11 }
12 fn is_equal(&self, other: &Self) -> bool {
13 self.id_set().is_subset(&other.id_set()) && other.id_set().is_subset(&self.id_set())
14 }
15 fn has_intersection(&self, other: &Self) -> bool {
16 !self.is_disjoint(other)
17 }
18 fn is_disjoint(&self, other: &Self) -> bool {
19 self.id_set().is_disjoint(&other.id_set())
20 }
21 fn is_empty(&self) -> bool {
22 self.id_set().is_empty()
23 }
24 fn is_singleton(&self) -> bool {
25 self.id_set().len() == 1
26 }
27}
28
29pub trait DirectedHyperedge: Hyperedge {
30 fn src(&self) -> HashSet<usize>;
31 fn dst(&self) -> HashSet<usize>;
32 fn id_set_pair(&self) -> (HashSet<usize>, HashSet<usize>) {
33 (self.src(), self.dst())
34 }
35}
36
37impl<T> Hyperedge for T
38where T: DirectedHyperedge {
39 fn id_set(&self) -> HashSet<usize> {
40 self.src().union(&self.dst()).cloned().collect()
41 }
42}
43
44pub trait NodeSet: Hyperedge {
46 fn from_nodes(nodes: Vec<usize>) -> Self;
47}
48
49pub trait NodeSetPair: DirectedHyperedge {
51 type Node;
52 fn from_nodes_pair(src: Vec<usize>, dst: Vec<usize>) -> Self;
53}
54