[#BloombergLP-bslalg-RbTreeUtil-isWellFormed] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslalg.adoc[bslalg]::xref:BloombergLP/bslalg/RbTreeUtil.adoc[RbTreeUtil]::isWellFormed :relfileprefix: ../../../ :mrdocs: Return `true` if the specified `tree` is well‐formed and refers to a valid red‐black tree, and `false` otherwise. For a `RbTreeAnchor` to be considered well‐formed _all_ of the following must be true: == Synopsis Declared in `<bslalg_rbtreeutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class NODE_COMPARATOR> static bool isWellFormed( xref:BloombergLP/bslalg/RbTreeAnchor.adoc[RbTreeAnchor] const& tree, NODE_COMPARATOR const& comparator); ---- == Description 1. `tree.rootNode()` must refer to a valid red‐black tree, whose nodes are organized according to `comparator` (see `validateRbTree`). 2. `tree.firstNode()` must refer to `tree.sentinel()` if `tree.rootNode()` is 0, and leftmost(tree.rootNode())' otherwise. 3. `tree.nodeCount()` must be the count of nodes in `tree` (not including the sentinel node). 4. `tree.sentinel()‐>leftchild()` is `tree.rootNode()`, and (if `tree.rootNode()` is not 0) `tree.rootNode()‐>parent()` is `tree.sentinel()`. 5. `tree.rootNode()` is 0 or `tree.rootNode().isBlack()` is `true` The behavior is undefined unless `tree.rootNode()` is 0 or refers to a valid binary tree. Note that the implementation of this function is recursive and has linear complexity with respect to the number of nodes in `tree`, it is intended for debugging purposes only. Note also that the final condition, that the root node be either 0 or colored black, is not a canonical requirement of a red‐black tree but an additional invariant enforced by the methods of `RbTreeUtil` to simplify the implementations. [.small]#Created with https://www.mrdocs.com[MrDocs]#