From b2d4de41f97085cd037a23916c818cd84e3df185 Mon Sep 17 00:00:00 2001 From: Joris van Rantwijk Date: Sat, 6 Jul 2024 22:53:41 +0200 Subject: [PATCH] Add __slots__ in datastruct.py It does not make a clear difference for performance. But it should at least reduce memory usage a bit. --- python/datastruct.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/datastruct.py b/python/datastruct.py index 22e0647..48df054 100644 --- a/python/datastruct.py +++ b/python/datastruct.py @@ -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."""