Join given arguments into the same set. Accepts one or more arguments.
(self, a, *args)
| 868 | return item in self._mapping |
| 869 | |
| 870 | def join(self, a, *args): |
| 871 | """ |
| 872 | Join given arguments into the same set. Accepts one or more arguments. |
| 873 | """ |
| 874 | mapping = self._mapping |
| 875 | try: |
| 876 | set_a = mapping[a] |
| 877 | except KeyError: |
| 878 | set_a = mapping[a] = weakref.WeakSet([a]) |
| 879 | self._ordering[a] = self._next_order |
| 880 | self._next_order += 1 |
| 881 | for arg in args: |
| 882 | try: |
| 883 | set_b = mapping[arg] |
| 884 | except KeyError: |
| 885 | set_b = mapping[arg] = weakref.WeakSet([arg]) |
| 886 | self._ordering[arg] = self._next_order |
| 887 | self._next_order += 1 |
| 888 | if set_b is not set_a: |
| 889 | if len(set_b) > len(set_a): |
| 890 | set_a, set_b = set_b, set_a |
| 891 | set_a.update(set_b) |
| 892 | for elem in set_b: |
| 893 | mapping[elem] = set_a |
| 894 | |
| 895 | def joined(self, a, b): |
| 896 | """Return whether *a* and *b* are members of the same set.""" |