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

Method add_edge

publication/code/chapter09/graph_adjlist.rs:136–150  ·  view source on GitHub ↗
(&mut self, from: &T, to: &T, wt: i32)

Source from the content-addressed store, hash-verified

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