fix(rbt): improve naming and add docstrings
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
2b02eac10e
commit
7b5bf0ec3a
1 changed files with 15 additions and 3 deletions
18
rbt.py
18
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,
|
||||
|
|
Loading…
Reference in a new issue