@@ -732,12 +732,18 @@ class PairSet:
732
732
733
733
__slots__ = ("_data" ,)
734
734
735
+ _data : Dict [str , Dict [str , bool ]]
736
+
735
737
def __init__ (self ) -> None :
736
- self ._data : Dict [ str , Dict [ str , bool ]] = {}
738
+ self ._data = {}
737
739
738
740
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 )
741
747
if result is None :
742
748
return False
743
749
# `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:
747
753
return not result
748
754
return True
749
755
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 )
754
758
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