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

Method contains

publication/code/chapter08/binary_tree.rs:163–179  ·  view source on GitHub ↗

查询 key 是否存在于树中

(&self, key: &T)

Source from the content-addressed store, hash-verified

161
162 // 查询 key 是否存在于树中
163 fn contains(&self, key: &T) -> bool {
164 match &self.key.cmp(key) {
165 Equal => true,
166 Greater => {
167 match &self.left {
168 Some(left) => left.contains(key),
169 None => false,
170 }
171 },
172 Less => {
173 match &self.right {
174 Some(right) => right.contains(key),
175 None => false,
176 }
177 },
178 }
179 }
180
181 // 新子节点作为根节点的左子节点
182 fn insert_left_tree(&mut self, key: T) {

Callers

nothing calls this directly

Calls 1

cmpMethod · 0.45

Tested by

no test coverage detected