Skip to content

Commit

Permalink
return tuple in ancestors()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener committed Oct 13, 2022
1 parent 098ab02 commit 433c9e7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions loopy/schedule/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

from immutables import Map
from typing import FrozenSet, Generic, Hashable, TypeVar, Iterator, Optional, List
from typing import FrozenSet, Generic, Hashable, Tuple, TypeVar, Iterator, Optional, List
from dataclasses import dataclass

# {{{ tree data structure
Expand Down Expand Up @@ -52,7 +52,7 @@ class Tree(Generic[NodeT]):
_child_to_parent: Map[NodeT, Optional[NodeT]]

@staticmethod
def from_root(root: NodeT):
def from_root(root: NodeT) -> "Tree[NodeT]":
return Tree(Map({root: frozenset()}),
Map({root: None}))

Expand All @@ -66,21 +66,21 @@ def root(self) -> NodeT:

return guess

def ancestors(self, node: NodeT) -> FrozenSet[NodeT]:
def ancestors(self, node: NodeT) -> Tuple[NodeT, ...]:
"""
Returns a :class:`frozenset` of nodes that are ancestors of *node*.
Returns a :class:`tuple` of nodes that are ancestors of *node*.
"""
if not self.is_a_node(node):
raise ValueError(f"'{node}' not in tree.")

if self.is_root(node):
# => root
return frozenset()
return tuple()

parent = self._child_to_parent[node]
assert parent is not None

return frozenset([parent]) | self.ancestors(parent)
return (parent,) + self.ancestors(parent)

def parent(self, node: NodeT) -> Optional[NodeT]:
"""
Expand Down

0 comments on commit 433c9e7

Please sign in to comment.