MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / add_edge

Method add_edge

publication/code/chapter09/cooking_topological_sort.rs:60–75  ·  view source on GitHub ↗
(&mut self, src: &T, des: &T)

Source from the content-addressed store, hash-verified

58 }
59
60 fn add_edge(&mut self, src: &T, des: &T) {
61 if !self.vertices.contains_key(src) { let _sv = self.add_vertex(src); }
62 if !self.vertices.contains_key(des) { let _dv = self.add_vertex(des); }
63
64 // 添加点
65 self.edgenums += 1;
66 self.vertices.get_mut(src)
67 .unwrap()
68 .add_neighbor(des.clone());
69
70 // 添加边
71 if !self.edges.contains_key(src) {
72 let _eg = self.edges.insert(src.clone(), Vec::new());
73 }
74 self.edges.get_mut(src).unwrap().push(des.clone());
75 }
76}
77
78// 构建课程关系图

Callers 1

build_course_graphFunction · 0.45

Calls 5

add_vertexMethod · 0.45
add_neighborMethod · 0.45
get_mutMethod · 0.45
insertMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected