@@ -732,12 +732,18 @@ class PairSet:
732732
733733 __slots__ = ("_data" ,)
734734
735+ _data : Dict [str , Dict [str , bool ]]
736+
735737 def __init__ (self ) -> None :
736- self ._data : Dict [ str , Dict [ str , bool ]] = {}
738+ self ._data = {}
737739
738740 def has (self , a : str , b : str , are_mutually_exclusive : bool ) -> bool :
739- first = self ._data .get (a )
740- result = first and first .get (b )
741+ key1 , key2 = (a , b ) if a < b else (b , a )
742+
743+ map_ = self ._data .get (key1 )
744+ if map_ is None :
745+ return False
746+ result = map_ .get (key2 )
741747 if result is None :
742748 return False
743749 # `are_mutually_exclusive` being False is a superset of being True, hence if we
@@ -747,13 +753,11 @@ def has(self, a: str, b: str, are_mutually_exclusive: bool) -> bool:
747753 return not result
748754 return True
749755
750- def add (self , a : str , b : str , are_mutually_exclusive : bool ) -> "PairSet" :
751- self ._pair_set_add (a , b , are_mutually_exclusive )
752- self ._pair_set_add (b , a , are_mutually_exclusive )
753- return self
756+ def add (self , a : str , b : str , are_mutually_exclusive : bool ) -> None :
757+ key1 , key2 = (a , b ) if a < b else (b , a )
754758
755- def _pair_set_add ( self , a : str , b : str , are_mutually_exclusive : bool ) -> None :
756- a_map = self . _data . get ( a )
757- if not a_map :
758- self . _data [ a ] = a_map = {}
759- a_map [ b ] = are_mutually_exclusive
759+ map_ = self . _data . get ( key1 )
760+ if map_ is None :
761+ self . _data [ key1 ] = { key2 : are_mutually_exclusive }
762+ else :
763+ map_ [ key2 ] = are_mutually_exclusive
0 commit comments