rshyper_hmap/impls/
impl_ops.rs1use crate::{HashEdge, HyperMap};
6use core::hash::BuildHasher;
7use core::ops;
8use rshyper::error::Result;
9use rshyper::idx::{EdgeId, HashIndex, HyperIndex, VertexId};
10use rshyper::node::Node;
11use rshyper::{Combine, GraphProps};
12
13impl<N, E, A, S, Ix> Combine<EdgeId<Ix>, EdgeId<Ix>> for HyperMap<N, E, A, S>
14where
15 A: GraphProps<Ix = Ix>,
16 S: BuildHasher + Default,
17 Ix: HyperIndex,
18 for<'a> &'a E: ops::Add<Output = E>,
19{
20 type Output = EdgeId<Ix>;
21
22 fn combine(&mut self, src: EdgeId<Ix>, tgt: EdgeId<Ix>) -> Result<Self::Output> {
23 self.merge_edges(&src, &tgt)
24 }
25}
26
27impl<'a, N, E, A, S, Ix> Combine<&'a EdgeId<Ix>, &'a EdgeId<Ix>> for HyperMap<N, E, A, S>
28where
29 A: GraphProps<Ix = Ix>,
30 S: BuildHasher + Default,
31 Ix: HyperIndex,
32 for<'b> &'b E: ops::Add<Output = E>,
33{
34 type Output = EdgeId<Ix>;
35
36 fn combine(&mut self, src: &'a EdgeId<Ix>, tgt: &'a EdgeId<Ix>) -> Result<Self::Output> {
37 self.merge_edges(src, tgt)
38 }
39}
40
41impl<N, E, A, S, Ix> ops::Index<&EdgeId<Ix>> for HyperMap<N, E, A, S>
42where
43 A: GraphProps<Ix = Ix>,
44 S: BuildHasher,
45 Ix: HashIndex,
46{
47 type Output = HashEdge<E, A::Kind, Ix, S>;
48
49 fn index(&self, index: &EdgeId<Ix>) -> &Self::Output {
50 self.get_edge(index).expect("Edge not found")
51 }
52}
53
54impl<N, E, A, S, Ix> ops::IndexMut<&EdgeId<Ix>> for HyperMap<N, E, A, S>
55where
56 A: GraphProps<Ix = Ix>,
57 S: BuildHasher,
58 Ix: HashIndex,
59{
60 fn index_mut(&mut self, index: &EdgeId<Ix>) -> &mut Self::Output {
61 self.get_edge_mut(index).expect("Edge not found")
62 }
63}
64
65impl<N, E, A, S, Ix> ops::Index<&VertexId<Ix>> for HyperMap<N, E, A, S>
66where
67 A: GraphProps<Ix = Ix>,
68 S: BuildHasher,
69 Ix: HashIndex,
70{
71 type Output = Node<N, Ix>;
72
73 fn index(&self, index: &VertexId<Ix>) -> &Self::Output {
74 self.get_node(index).expect("Node not found")
75 }
76}
77
78impl<N, E, A, S, Ix> ops::IndexMut<&VertexId<Ix>> for HyperMap<N, E, A, S>
79where
80 A: GraphProps<Ix = Ix>,
81 S: BuildHasher,
82 Ix: HashIndex,
83{
84 fn index_mut(&mut self, index: &VertexId<Ix>) -> &mut Self::Output {
85 self.get_node_mut(index).expect("Node not found")
86 }
87}