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

Function is23

src/tree/binary/rb2.rs:402–414  ·  view source on GitHub ↗

Does the tree have no red right links, and at most one (left) red links in a row on any path?

(root: Option<NonNull<Node<K, V>>>, x: Option<NonNull<Node<K, V>>>)

Source from the content-addressed store, hash-verified

400/// Does the tree have no red right links, and at most one (left)
401/// red links in a row on any path?
402fn is23<K, V>(root: Option<NonNull<Node<K, V>>>, x: Option<NonNull<Node<K, V>>>) -> bool {
403 if x.is_none() {
404 true
405 } else {
406 let x = NodeQuery::new(x);
407 let root = NodeQuery::new(root);
408 if x.right().is_red() || (x.node != root.node && x.is_red() && x.left().is_red()) {
409 false
410 } else {
411 is23(root.node, x.left().node) && is23(root.node, x.right().node)
412 }
413 }
414}
415
416fn calc_blacks<K, V>(x: Option<NonNull<Node<K, V>>>) -> usize {
417 let mut x = NodeQuery::new(x);

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected