refactor(tree): split dot generation

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-02-03 11:08:19 +01:00
parent 458ffdb3ff
commit a4c896edbf
No known key found for this signature in database
GPG key ID: 332171FADF1DB90B

View file

@ -1,6 +1,6 @@
from abc import abstractmethod
from node import Node, Comparable from node import Node, Comparable
from abc import abstractmethod
from collections import deque from collections import deque
import logging import logging
from typing import Deque, Optional, Tuple, TypeVar, Generic from typing import Deque, Optional, Tuple, TypeVar, Generic
@ -13,12 +13,10 @@ class RankedTree(Generic[T]):
def __init__(self) -> None: def __init__(self) -> None:
self.root: Optional[Node[T]] = None self.root: Optional[Node[T]] = None
def __str__(self) -> str: def _get_unwrapped_graph(self) -> str:
result = "digraph {\n" result = ""
queue: Deque[Optional[Node[T]]] = deque()
queue.append(self.root)
queue: Deque[Optional[Node[T]]] = deque([self.root])
edges = [] edges = []
while queue: while queue:
node = queue.popleft() node = queue.popleft()
@ -37,7 +35,10 @@ class RankedTree(Generic[T]):
label = f'[label="{Node.difference(to_node)}"]' label = f'[label="{Node.difference(to_node)}"]'
result += f'"{str(from_node)}" -> "{str(to_node)}" {label}\n' result += f'"{str(from_node)}" -> "{str(to_node)}" {label}\n'
return result + "}\n" return result
def __str__(self) -> str:
return "digraph {\n" + self._get_unwrapped_graph() + "}\n"
# region TreeSpecificMethods # region TreeSpecificMethods