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

Method add_edge

code/chapter08/word_ladder.rs:118–132  ·  view source on GitHub ↗

添加边

(&mut self, from: &T, to: &T, wt: u32)

Source from the content-addressed store, hash-verified

116
117 // 添加边
118 fn add_edge(&mut self, from: &T, to: &T, wt: u32) {
119 // 点不存在需要先添加
120 if !self.contains(from) {
121 let _fvert = self.add_vertex(from);
122 }
123 if !self.contains(to) {
124 let _tvert = self.add_vertex(to);
125 }
126
127 self.edgenums += 1;
128 self.vertices
129 .get_mut(from)
130 .unwrap()
131 .add_neighbor(to.clone(), wt);
132 }
133}
134
135// 根据单词及模式构建图

Callers 1

build_word_graphFunction · 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