1use crate::{HashEdge, HyperMap, VertexSet, iter};
6use core::hash::{BuildHasher, Hash};
7use rshyper::error::Result;
8use rshyper::idx::{EdgeId, HyperIndex, VertexId};
9use rshyper::prelude::{GraphProps, GraphType, Node, Weight};
10use rshyper::traits::{HyperGraph, HyperGraphIterEdge, HyperGraphIterNode, RawHyperGraph};
11
12impl<N, E, A, S> RawHyperGraph<A> for HyperMap<N, E, A, S>
13where
14 A: GraphProps,
15 S: BuildHasher,
16{
17 type Node<_N> = Node<_N, A::Ix>;
18 type Edge<_E> = HashEdge<_E, A::Kind, A::Ix, S>;
19}
20
21impl<N, E, A, S, K, Ix> HyperGraph<N, E, A> for HyperMap<N, E, A, S>
22where
23 A: GraphProps<Kind = K, Ix = Ix>,
24 S: BuildHasher + Default,
25 K: GraphType,
26 Ix: HyperIndex,
27{
28 fn add_node(&mut self, weight: Weight<N>) -> Result<VertexId<A::Ix>> {
29 self.add_node(weight)
30 }
31
32 fn add_surface<I>(&mut self, iter: I, weight: Weight<E>) -> Result<EdgeId<A::Ix>>
33 where
34 I: IntoIterator<Item = VertexId<A::Ix>>,
35 {
36 self.add_edge(iter, weight)
37 }
38
39 fn get_edge_domain(&self, index: &EdgeId<A::Ix>) -> Result<&VertexSet<A::Ix, S>> {
40 self.get_domain(index)
41 }
42
43 fn get_edge_domain_mut(&mut self, index: &EdgeId<A::Ix>) -> Result<&mut VertexSet<A::Ix, S>> {
44 self.get_domain_mut(index)
45 }
46
47 fn get_edge(&self, index: &EdgeId<A::Ix>) -> Result<&HashEdge<E, A::Kind, A::Ix, S>> {
48 self.get_edge(index)
49 }
50
51 fn get_edge_mut(
52 &mut self,
53 index: &EdgeId<A::Ix>,
54 ) -> Result<&mut HashEdge<E, A::Kind, A::Ix, S>> {
55 self.get_edge_mut(index)
56 }
57
58 fn get_edge_weight(&self, index: &EdgeId<A::Ix>) -> Result<&Weight<E>> {
59 self.get_edge_weight(index)
60 }
61
62 fn get_edge_weight_mut(&mut self, index: &EdgeId<A::Ix>) -> Result<&mut Weight<E>> {
63 self.get_edge_weight_mut(index)
64 }
65
66 fn get_node(&self, index: &VertexId<A::Ix>) -> Result<&Node<N, A::Ix>> {
67 self.get_node(index)
68 }
69
70 fn get_node_mut(&mut self, index: &VertexId<A::Ix>) -> Result<&mut Node<N, A::Ix>> {
71 self.get_node_mut(index)
72 }
73
74 fn get_node_weight(&self, index: &VertexId<<A as GraphProps>::Ix>) -> Result<&Weight<N>> {
75 self.get_node_weight(index)
76 }
77
78 fn get_node_weight_mut(&mut self, index: &VertexId<A::Ix>) -> Result<&mut Weight<N>> {
79 self.get_node_weight_mut(index)
80 }
81
82 fn contains_edge(&self, index: &EdgeId<A::Ix>) -> bool {
83 self.contains_edge(index)
84 }
85
86 fn contains_node(&self, index: &VertexId<A::Ix>) -> bool {
87 self.contains_node(index)
88 }
89
90 fn find_edges_with_node(
91 &self,
92 index: &VertexId<A::Ix>,
93 ) -> impl Iterator<Item = &EdgeId<A::Ix>> {
94 self.find_edges_with_node(index)
95 }
96}
97
98impl<N, E, A, S> HyperGraphIterNode<N, E, A> for HyperMap<N, E, A, S>
99where
100 A: GraphProps,
101 S: BuildHasher + Default,
102 E: Eq + Hash,
103 N: Eq + Hash,
104 A::Ix: HyperIndex,
105{
106 type Nodes<'a>
107 = iter::NodeIter<'a, N, A::Ix>
108 where
109 Self: 'a,
110 Self::Node<N>: 'a;
111 type Verts<'a>
112 = iter::NodeKeys<'a, N, A::Ix>
113 where
114 Self: 'a;
115
116 fn iter_nodes(&self) -> Self::Nodes<'_> {
117 self.iter_nodes()
118 }
119
120 fn vertices(&self) -> Self::Verts<'_> {
121 self.vertices()
122 }
123}
124
125impl<N, E, A, S> HyperGraphIterEdge<N, E, A> for HyperMap<N, E, A, S>
126where
127 A: GraphProps,
128 S: BuildHasher + Default,
129 E: Eq + Hash,
130 N: Eq + Hash,
131 A::Ix: HyperIndex,
132{
133 type Surfaces<'a>
134 = iter::EdgeIter<'a, E, A::Kind, A::Ix, S>
135 where
136 Self: 'a,
137 Self::Edge<E>: 'a;
138
139 type Edges<'a>
140 = iter::EdgeKeys<'a, E, A::Kind, A::Ix, S>
141 where
142 Self: 'a,
143 Self::Edge<E>: 'a;
144
145 fn iter_surfaces(&self) -> Self::Surfaces<'_> {
146 self.iter_edges()
147 }
148
149 fn edges(&self) -> Self::Edges<'_> {
150 self.iter_edge_keys()
151 }
152}