Skip to content

Commit

Permalink
Merge branch 'ft-843-equals-event-log-objects' into 'integration'
Browse files Browse the repository at this point in the history
equals for event log objects are missing

See merge request pm4py/pm4py-core!321
  • Loading branch information
fit-sebastiaan-van-zelst committed Mar 17, 2021
2 parents 24778a7 + 7531430 commit b615445
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions pm4py/objects/log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def __repr__(self):
return str(dict(self))

def __hash__(self):
return hash(frozenset(dict(self)))
return hash(frozenset((str(x), str(y)) for x, y in self.items()))

def __eq__(self, other):
return frozenset((str(x), str(y)) for x, y in self.items()) == frozenset((str(x), str(y)) for x, y in other.items())

def __copy__(self):
event = Event()
Expand All @@ -78,7 +81,28 @@ def __init__(self, *args, **kwargs):
self._list = list(*args)

def __hash__(self):
return hash(tuple(self))
ret = 0
for ev in self._list:
ret += hash(ev)
ret = ret % 479001599
return ret

def __eq__(self, other):
if len(self) != len(other):
return False
elif self.attributes != other.attributes:
return False
elif self.extensions != other.extensions:
return False
elif self.omni_present != other.omni_present:
return False
elif self.classifiers != other.classifiers:
return False
else:
for i in range(len(self._list)):
if self[i] != other[i]:
return False
return True

def __getitem__(self, key):
return self._list[key]
Expand Down Expand Up @@ -144,10 +168,23 @@ def __init__(self, *args, **kwargs):
self._list = list(*args)

def __hash__(self):
tup = tuple(tuple(((x, y) for x, y in event.items())) for event in self._list)
ret = hash(tup)
ret = 0
for ev in self._list:
ret += hash(ev)
ret = ret % 479001599
return ret

def __eq__(self, other):
if len(self) != len(other):
return False
elif self.attributes != other.attributes:
return False
else:
for i in range(len(self._list)):
if self[i] != other[i]:
return False
return True

def __getitem__(self, key):
return self._list[key]

Expand Down Expand Up @@ -231,3 +268,27 @@ def __copy__(self):
log._classifiers = copy.copy(self._classifiers)
log._list = copy.copy(self._list)
return log

def __hash__(self):
ret = 0
for trace in self._list:
ret += hash(trace)
ret = ret % 479001599
return ret

def __eq__(self, other):
if len(self) != len(other):
return False
elif self.attributes != other.attributes:
return False
elif self.extensions != other.extensions:
return False
elif self.omni_present != other.omni_present:
return False
elif self.classifiers != other.classifiers:
return False
else:
for i in range(len(self._list)):
if self[i] != other[i]:
return False
return True

0 comments on commit b615445

Please sign in to comment.