pyln-client/gossmap: make node and node_id comparable with __lt__ and __eq__

This commit is contained in:
Michael Schmoock 2021-09-08 06:26:06 +09:30 committed by Rusty Russell
parent 47efea92c6
commit fa8e74a2ad

View file

@ -65,8 +65,12 @@ class GossmapNodeId(object):
def __eq__(self, other):
if not isinstance(other, GossmapNodeId):
return False
return self.nodeid.__eq__(other.nodeid)
return self.nodeid == other.nodeid
def __lt__(self, other):
if not isinstance(other, GossmapNodeId):
raise ValueError(f"Cannot compare GossmapNodeId with {type(other)}")
return self.nodeid.__lt__(other.nodeid) # yes, that works
def __hash__(self):
return self.nodeid.__hash__()
@ -143,6 +147,16 @@ class GossmapNode(object):
def __repr__(self):
return "GossmapNode[{}]".format(self.node_id.nodeid.hex())
def __eq__(self, other):
if not isinstance(other, GossmapNode):
return False
return self.node_id.__eq__(other.node_id)
def __lt__(self, other):
if not isinstance(other, GossmapNode):
raise ValueError(f"Cannot compare GossmapNode with {type(other)}")
return self.node_id.__lt__(other.node_id)
class Gossmap(object):
"""Class to represent the gossip map of the network"""