MCPcopy Index your code
hub / github.com/douchuan/algorithm / pred

Function pred

src/tree/binary/bst.rs:175–199  ·  view source on GitHub ↗

# Safety This is highly unsafe, due to pointer

(
    node: Option<NonNull<Node<K, V>>>,
    mut key: &'a K,
)

Source from the content-addressed store, hash-verified

173///
174/// This is highly unsafe, due to pointer
175unsafe fn pred<'a, K: 'a, V: 'a>(
176 node: Option<NonNull<Node<K, V>>>,
177 mut key: &'a K,
178) -> Option<NonNull<Node<K, V>>>
179where
180 K: Ord,
181{
182 find(node, key).and_then(|node| {
183 let mut nq = NodeQuery::new(Some(node));
184 match nq.left().node {
185 //左分支的最大值
186 Some(l) => find_max(Some(l)),
187 None => {
188 //左分支为空,向上找
189 loop {
190 nq = nq.parent();
191 match nq.left_key() {
192 Some(l) if l == key => key = nq.get_key().unwrap(),
193 _ => return nq.node,
194 }
195 }
196 }
197 }
198 })
199}
200
201/// # Safety
202///

Callers 1

predMethod · 0.85

Calls 6

find_maxFunction · 0.85
parentMethod · 0.80
left_keyMethod · 0.80
get_keyMethod · 0.80
findFunction · 0.70
leftMethod · 0.45

Tested by

no test coverage detected