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

Function is_bst

src/tree/binary/bst.rs:262–275  ·  view source on GitHub ↗

is the tree rooted at x a BST with all keys strictly between min and max (if min or max is null, treat as empty constraint)

(x: Option<NonNull<Node<K, V>>>, min: Option<&K>, max: Option<&K>)

Source from the content-addressed store, hash-verified

260/// is the tree rooted at x a BST with all keys strictly between min and max
261/// (if min or max is null, treat as empty constraint)
262pub fn is_bst<K, V>(x: Option<NonNull<Node<K, V>>>, min: Option<&K>, max: Option<&K>) -> bool
263where
264 K: Ord,
265{
266 x.map_or(true, |x| {
267 let x = NodeQuery::new(Some(x));
268 let key = x.get_key();
269 if (min.is_some() && key.lt(&min)) || (max.is_some() && key.gt(&max)) {
270 false
271 } else {
272 is_bst(x.left().node, min, key) && is_bst(x.right().node, key, max)
273 }
274 })
275}
276
277/// Returns the number of key-value pairs
278pub fn calc_size<K, V>(x: Option<NonNull<Node<K, V>>>) -> usize {

Callers

nothing calls this directly

Calls 4

get_keyMethod · 0.80
is_someMethod · 0.80
leftMethod · 0.45
rightMethod · 0.45

Tested by

no test coverage detected