Skip to content

Commit 1ee83fe

Browse files
committed
Make subnets hashable (all legit)
1 parent 90d98aa commit 1ee83fe

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cma/AssimCclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ def sender_key_id(self):
19081908
if not ret:
19091909
# print('Returning None(!)', self.get_framesettype(), file=stderr)
19101910
return None
1911-
print('SENDER_KEY_ID:', type(ret), ret, file=stderr)
1911+
# print('SENDER_KEY_ID:', type(ret), ret, file=stderr)
19121912
pyret = u_string_at(ret)
19131913
# print('PYRET:', type(pyret), 'pyret:', pyret, file=stderr)
19141914
return pyret

cma/graphnodes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,18 @@ def __init__(self, domain, ipaddr, cidrmask=None, context=SUBNET_GLOBAL, net_seg
791791
assert context is None or isinstance(context, str)
792792
assert not str(self).startswith("::/")
793793

794+
def __hash__(self) -> int:
795+
"""
796+
Hash our Subnet. The name of a subnet is unique, and is the only thing used by __eq__
797+
in comparisions.
798+
799+
So, it's perfectly legit to hash our name, so we can be put in sets or
800+
appear as keys in dicts.
801+
802+
:return: int: hash of our name
803+
"""
804+
return hash(self.name)
805+
794806
@staticmethod
795807
def str_to_ip_cidr(ipaddr, cidrmask):
796808
"""

0 commit comments

Comments
 (0)