diff --git a/rbt.py b/rbt.py index 3adbf0d..8a7b7ea 100644 --- a/rbt.py +++ b/rbt.py @@ -10,12 +10,24 @@ T = TypeVar("T", bound=Comparable) class Colour(enum.IntEnum): + """ + Represents colour of the edge or node. + """ Red = 0 Black = 1 -def is_double_black(x: Optional[Node]) -> bool: - return x and 2 in Node.differences(x) +def has_double_black(x: Optional[Node]) -> bool: + """ + Checks for double black child of x. + + Args: + x: Node to be checked. + + Returns: + `true`, if `x` has a double black node, `false` otherwise. + """ + return x is not None and 2 in Node.differences(x) class RBTree(RankedTree[T]): @@ -143,7 +155,7 @@ class RBTree(RankedTree[T]): if not node and not parent: return - while node != self.root and is_double_black(parent): + while node != self.root and has_double_black(parent): if node == parent.left: node, parent = self._delete_rebalance_step( node,