From 1acaebf41d941010e33a647041de5c5b97d566e7 Mon Sep 17 00:00:00 2001 From: Adam Peter Banham Date: Thu, 6 Feb 2025 20:09:59 +1000 Subject: [PATCH] added eq and safe hash to ComplexEvent --- pmkoalas/complex.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pmkoalas/complex.py b/pmkoalas/complex.py index a2a636a..20f7353 100644 --- a/pmkoalas/complex.py +++ b/pmkoalas/complex.py @@ -29,13 +29,6 @@ class ComplexEvent(): def __init__(self, activity:str, data:Mapping[str,object]) -> None: self._act = activity self._map = deepcopy(data) - self._hash = hash( - tuple( - [self._act,]+ - [hash(tuple([key,val])) for key,val - in self._map.items()] - ) - ) def activity(self) -> str: """ the process activity denoted by this event """ @@ -71,7 +64,18 @@ def __repr__(self) -> str: return repr def __hash__(self) -> int: - return self._hash + return hash( + tuple( + [self._act,]+ + [hash(tuple([key,val])) for key,val + in self._map.items()] + ) + ) + + def __eq__(self, value): + if (isinstance(value, ComplexEvent)): + return self.activity() == value.activity() \ + and self.data() == value.data() class ComplexTrace(): """