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

Function pop

src/tree/binary/builder/tournament.rs:36–52  ·  view source on GitHub ↗
(tree: &mut Tree<K, V>)

Source from the content-addressed store, hash-verified

34}
35
36fn pop<K, V>(tree: &mut Tree<K, V>) -> Option<K>
37where
38 K: Copy + std::cmp::Ord + Minimal,
39{
40 let nq = NodeQuery::new(tree.root);
41 match nq.get_key() {
42 Some(key) if *key != K::minimal() => {
43 let key = *key;
44 // 每次取出锦标赛树的根节点后,自顶向下将其替换为min
45 let leaf = replace_max_by_min(nq.node.unwrap(), key);
46 // 由叶子节点向上回溯,设置新的最大值
47 setup_new_max(leaf);
48 Some(key)
49 }
50 _ => None,
51 }
52}
53
54// 返回叶子节点的序号
55fn replace_max_by_min<K, V>(node: NonNull<Node<K, V>>, root_key: K) -> NonNull<Node<K, V>>

Callers 1

tournament_tree_popMethod · 0.70

Calls 3

replace_max_by_minFunction · 0.85
setup_new_maxFunction · 0.85
get_keyMethod · 0.80

Tested by

no test coverage detected