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

Method add_edge

code/chapter08/graph_adjlist.rs:137–152  ·  view source on GitHub ↗
(&mut self, from: &T, to: &T, wt: i32)

Source from the content-addressed store, hash-verified

135 }
136
137 fn add_edge(&mut self, from: &T, to: &T, wt: i32) {
138 // 若点不存在要先添加点
139 if !self.contains(from) {
140 let _fvert = self.add_vertex(from);
141 }
142
143 if !self.contains(to) {
144 let _tvert = self.add_vertex(to);
145 }
146
147 // 添加边
148 self.edgenums += 1;
149 self.vertices.get_mut(from)
150 .unwrap()
151 .add_neighbor(to.clone(), wt);
152 }
153
154 // 判断两个点是否相邻
155 fn is_adjacent(&self, from: &T, to: &T) -> bool {

Callers 1

mainFunction · 0.45

Calls 4

containsMethod · 0.45
add_vertexMethod · 0.45
add_neighborMethod · 0.45
get_mutMethod · 0.45

Tested by

no test coverage detected