Add from __future__ import annotations
This makes the code work on Python versions 3.7 and 3.8.
This commit is contained in:
parent
147640329f
commit
d3475834ab
|
@ -389,12 +389,11 @@ class Blossom:
|
||||||
# "tree_blossoms" is the set of all top-level blossoms that belong
|
# "tree_blossoms" is the set of all top-level blossoms that belong
|
||||||
# to the same alternating tree. The same set instance is shared by
|
# to the same alternating tree. The same set instance is shared by
|
||||||
# all top-level blossoms in the tree.
|
# all top-level blossoms in the tree.
|
||||||
self.tree_blossoms: "Optional[set[Blossom]]" = None
|
self.tree_blossoms: Optional[set[Blossom]] = None
|
||||||
|
|
||||||
# Each top-level blossom maintains a union-find datastructure
|
# Each top-level blossom maintains a union-find datastructure
|
||||||
# containing all vertices in the blossom.
|
# containing all vertices in the blossom.
|
||||||
self.vertex_set: "UnionFindQueue[Blossom, int]"
|
self.vertex_set: UnionFindQueue[Blossom, int] = UnionFindQueue(self)
|
||||||
self.vertex_set = UnionFindQueue(self)
|
|
||||||
|
|
||||||
# If this is a top-level unlabeled blossom with an edge to an
|
# If this is a top-level unlabeled blossom with an edge to an
|
||||||
# S-blossom, "delta2_node" is the corresponding node in the delta2
|
# S-blossom, "delta2_node" is the corresponding node in the delta2
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Data structures for matching."""
|
"""Data structures for matching."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Generic, Optional, TypeVar
|
from typing import Generic, Optional, TypeVar
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
|
||||||
"parent", "left", "right")
|
"parent", "left", "right")
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
owner: "UnionFindQueue[_NameT2, _ElemT2]",
|
owner: UnionFindQueue[_NameT2, _ElemT2],
|
||||||
data: _ElemT2,
|
data: _ElemT2,
|
||||||
prio: float
|
prio: float
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -47,14 +49,14 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
|
||||||
This method should not be called directly.
|
This method should not be called directly.
|
||||||
Instead, call UnionFindQueue.insert().
|
Instead, call UnionFindQueue.insert().
|
||||||
"""
|
"""
|
||||||
self.owner: "Optional[UnionFindQueue[_NameT2, _ElemT2]]" = owner
|
self.owner: Optional[UnionFindQueue[_NameT2, _ElemT2]] = owner
|
||||||
self.data = data
|
self.data = data
|
||||||
self.prio = prio
|
self.prio = prio
|
||||||
self.min_node = self
|
self.min_node = self
|
||||||
self.height = 1
|
self.height = 1
|
||||||
self.parent: "Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]"
|
self.parent: Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]
|
||||||
self.left: "Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]"
|
self.left: Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]
|
||||||
self.right: "Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]"
|
self.right: Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]
|
||||||
self.parent = None
|
self.parent = None
|
||||||
self.left = None
|
self.left = None
|
||||||
self.right = None
|
self.right = None
|
||||||
|
@ -98,9 +100,9 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
|
||||||
name: Name to assign to the new queue.
|
name: Name to assign to the new queue.
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.tree: "Optional[UnionFindQueue.Node[_NameT, _ElemT]]" = None
|
self.tree: Optional[UnionFindQueue.Node[_NameT, _ElemT]] = None
|
||||||
self.sub_queues: "list[UnionFindQueue[_NameT, _ElemT]]" = []
|
self.sub_queues: list[UnionFindQueue[_NameT, _ElemT]] = []
|
||||||
self.split_nodes: "list[UnionFindQueue.Node[_NameT, _ElemT]]" = []
|
self.split_nodes: list[UnionFindQueue.Node[_NameT, _ElemT]] = []
|
||||||
|
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
"""Remove all elements from the queue.
|
"""Remove all elements from the queue.
|
||||||
|
@ -165,7 +167,7 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
|
||||||
return node.min_node.data
|
return node.min_node.data
|
||||||
|
|
||||||
def merge(self,
|
def merge(self,
|
||||||
sub_queues: "list[UnionFindQueue[_NameT, _ElemT]]"
|
sub_queues: list[UnionFindQueue[_NameT, _ElemT]]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Merge the specified queues.
|
"""Merge the specified queues.
|
||||||
|
|
||||||
|
@ -712,7 +714,7 @@ class PriorityQueue(Generic[_ElemT]):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize an empty queue."""
|
"""Initialize an empty queue."""
|
||||||
self.heap: "list[PriorityQueue.Node[_ElemT]]" = []
|
self.heap: list[PriorityQueue.Node[_ElemT]] = []
|
||||||
|
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
"""Remove all elements from the queue.
|
"""Remove all elements from the queue.
|
||||||
|
|
Loading…
Reference in New Issue