From e7b6893c530e537bd747e14898a643739b6a14d3 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 3 Sep 2023 22:09:39 +0300 Subject: [PATCH] insndb/core: support operands comparison --- src/openpower/insndb/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 867f9c4b..8e489b46 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -988,6 +988,7 @@ class Record(Dataclass): return self["Rc"].value +@_functools.total_ordering class Operand: def __init__(self, record, name): self.__record = record @@ -1000,6 +1001,19 @@ class Operand: def __repr__(self): return f"{self.__class__.__name__}({self.name})" + def __lt__(self, other): + if self.__class__ is not other.__class__: + return NotImplemented + return ((self.name < other.name) or (self.span < other.span)) + + def __eq__(self, other): + if self.__class__ is not other.__class__: + return NotImplemented + return ((self.name == other.name) and (self.span == other.span)) + + def __hash__(self): + return hash((self.name, self.span),) + @property def name(self): return self.__name -- 2.30.2