(self, a, b)
Add the pair (a,b) in the set
Add the pair (a,b) in the set
Add the pair ( a b ) in the set
def add(self, a, b):
        """Add the pair (a,b) in the set"""
        leadera = self.leader.get(a)
        leaderb = self.leader.get(b)
        if leadera is not None:
            if leaderb is not None:
                if leadera == leaderb:
                    return # nothing to do
                groupa = self.group[leadera]
                groupb = self.group[leaderb]
                if self.comp is not None and self.comp(leadera, leaderb) > 0:
                    a, leadera, groupa, b, leaderb, groupb = b, leaderb, groupb,\
                                                             a, leadera, groupa
                groupa |= groupb
                del group[leaderb]
                for k in groupb:
                    self.leader[k] = leadera
            else:
                self.group[leadera].add(b)
                self.leader[b] = leadera
        else:
            if leaderb is not None:
                self.group[leaderb].add(a)
                self.leader[a] = leaderb
            else:
                if self.comp is not None and self.comp(a, b) > 0:
                    a, b = b, a
                self.leader[a] = self.leader[b] = a
                self.group[a] = set([a, b])
def add ( self , a , b ) : leadera = self . leader . get ( a ) leaderb = self . leader . get ( b ) if leadera is not None : if leaderb is not None : if leadera == leaderb : return # nothing to do groupa = self . group [ leadera ] groupb = self . group [ leaderb ] if self . comp is not None and self . comp ( leadera , leaderb ) > 0 : a , leadera , groupa , b , leaderb , groupb = b , leaderb , groupb , a , leadera , groupa groupa |= groupb del group [ leaderb ] for k in groupb : self . leader [ k ] = leadera else : self . group [ leadera ] . add ( b ) self . leader [ b ] = leadera else : if leaderb is not None : self . group [ leaderb ] . add ( a ) self . leader [ a ] = leaderb else : if self . comp is not None and self . comp ( a , b ) > 0 : a , b = b , a self . leader [ a ] = self . leader [ b ] = a self . group [ a ] = set ( [ a , b ] )