insndb/core: support operands comparison
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 3 Sep 2023 19:09:39 +0000 (22:09 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Wed, 6 Sep 2023 18:56:09 +0000 (21:56 +0300)
src/openpower/insndb/core.py

index 867f9c4b76c7c3c498cda18c1a3c5b9e484fed44..8e489b46a04c8cc33fcc5e831729698da4f8398f 100644 (file)
@@ -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