1
0
Fork 0

Add __slots__ in datastruct.py

It does not make a clear difference for performance.
But it should at least reduce memory usage a bit.
This commit is contained in:
Joris van Rantwijk 2024-07-06 22:53:41 +02:00
parent d2debb6d6f
commit b2d4de41f9
1 changed files with 7 additions and 0 deletions

View File

@ -29,9 +29,14 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
tracking added to it.
"""
__slots__ = ("name", "tree", "sub_queues", "split_nodes")
class Node(Generic[_NameT2, _ElemT2]):
"""Node in a UnionFindQueue."""
__slots__ = ("owner", "data", "prio", "min_node", "height",
"parent", "left", "right")
def __init__(self,
owner: "UnionFindQueue[_NameT2, _ElemT2]",
data: _ElemT2,
@ -688,6 +693,8 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
class PriorityQueue(Generic[_ElemT]):
"""Priority queue based on a binary heap."""
__slots__ = ("heap", )
class Node(Generic[_ElemT2]):
"""Node in the priority queue."""