MCPcopy Create free account
hub / github.com/douchuan/algorithm / succ

Function succ

src/tree/binary/bst.rs:146–170  ·  view source on GitHub ↗

# Safety This is highly unsafe, due to pointer

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

Source from the content-addressed store, hash-verified

144///
145/// This is highly unsafe, due to pointer
146unsafe fn succ<'a, K: 'a, V: 'a>(
147 p: Option<NonNull<Node<K, V>>>,
148 mut key: &'a K,
149) -> Option<NonNull<Node<K, V>>>
150where
151 K: Ord,
152{
153 find(p, key).and_then(|node| {
154 let mut nq = NodeQuery::new(Some(node));
155 match nq.right().node {
156 //右分支的最小值
157 Some(r) => find_min(Some(r)),
158 None => {
159 //右分支为空,向上找
160 loop {
161 nq = nq.parent();
162 match nq.right_key() {
163 Some(r) if r == key => key = nq.get_key().unwrap(),
164 _ => return nq.node,
165 }
166 }
167 }
168 }
169 })
170}
171
172/// # Safety
173///

Callers 1

succMethod · 0.85

Calls 6

find_minFunction · 0.85
parentMethod · 0.80
right_keyMethod · 0.80
get_keyMethod · 0.80
findFunction · 0.70
rightMethod · 0.45

Tested by

no test coverage detected