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

Function counter

src/tree/binary/rb2.rs:359–369  ·  view source on GitHub ↗
(h: Option<NonNull<Node<K, V>>>, mut black: usize)

Source from the content-addressed store, hash-verified

357/// does every path from the root to a leaf have the given number of black links?
358fn is_balance<K, V>(root: Option<NonNull<Node<K, V>>>) -> bool {
359 fn counter<K, V>(h: Option<NonNull<Node<K, V>>>, mut black: usize) -> bool {
360 if h.is_none() {
361 0 == black
362 } else {
363 let h = NodeQuery::new(h);
364 if !h.is_red() {
365 black -= 1;
366 }
367 counter(h.left().node, black) && counter(h.right().node, black)
368 }
369 }
370
371 let black = calc_blacks(root);
372 counter(root, black)

Callers 1

is_balanceFunction · 0.85

Calls 4

is_noneMethod · 0.80
is_redMethod · 0.80
leftMethod · 0.45
rightMethod · 0.45

Tested by

no test coverage detected