eta_graph/
weighted_graph.rs1use crate::edge_storage::EdgeStorage;
2use crate::graph::{Graph};
3use crate::handles::types::{VHandle, Ci, Weight};
4use crate::traits::{StoreVertex, WeightedEdgeManipulate};
5use crate::vertex_storage::VertexStorage;
6
7pub struct WeightedGraph<VertexType, VertexStorageType, EdgeStorageType>
8where
9 EdgeStorageType: WeightedEdgeManipulate,
10 VertexStorageType: StoreVertex<VertexType=VertexType>
11{
12 pub graph: Graph<VertexType, VertexStorageType, EdgeStorageType>,
13}
14
15impl<VertexType, VertexStorageType, EdgeStorageType> Clone for WeightedGraph<VertexType, VertexStorageType, EdgeStorageType>
16where
17 EdgeStorageType: WeightedEdgeManipulate,
18 VertexType: Clone,
19 VertexStorageType: StoreVertex<VertexType=VertexType> + Clone {
20 fn clone(&self) -> Self {
21 WeightedGraph{
22 graph: self.graph.clone(),
23 }
24 }
25}
26
27impl<VertexType> Default for WeightedGraph<VertexType, VertexStorage<VertexType>, EdgeStorage> {
28 fn default() -> Self {
29 Self::new()
30 }
31}
32
33impl<VertexType> WeightedGraph<VertexType, VertexStorage<VertexType>, EdgeStorage>
34{
35 pub fn new() -> Self {
36 WeightedGraph{
37 graph: Graph::new(),
38 }
39 }
40 pub fn new_large() -> Self {
41 WeightedGraph{
42 graph: Graph::new_large(),
43 }
44 }
45 pub fn with_reserve(reserve: Ci) -> Self {
46 WeightedGraph{
47 graph: Graph::with_reserve(reserve),
48 }
49 }
50}
51impl<VertexType, StoreVertexType, EdgeStorageType> WeightedGraph<VertexType, StoreVertexType, EdgeStorageType>
52where
53 EdgeStorageType: WeightedEdgeManipulate,
54 StoreVertexType: StoreVertex<VertexType=VertexType> {
55 pub fn create_and_connect_weighted(&mut self, src_vertex: VHandle, val: VertexType, weight: Weight, edge_count: Ci) -> VHandle {
56 let new_vertex = self.graph.create(val, edge_count);
57 self.graph.edge_storage.connect_weighted(src_vertex, new_vertex, weight);
58 new_vertex
59 }
60
61 pub fn create_and_connect_weighted_0(&mut self, src_vertex: VHandle, val: VertexType, weight: Weight) -> VHandle {
62 self.create_and_connect_weighted(src_vertex, val, weight, 0)
63 }
64
65}