diff --git a/src/sage/combinat/bijectionist.py b/src/sage/combinat/bijectionist.py index e5ba051562b..7cfe72e3246 100644 --- a/src/sage/combinat/bijectionist.py +++ b/src/sage/combinat/bijectionist.py @@ -614,7 +614,7 @@ def set_constant_blocks(self, P): P = sorted(self._sorter["A"](p) for p in P) for p in P: for a in p: - self._P.join(p[0], a) + self._P.union(p[0], a) self._compute_possible_block_values() @@ -1678,7 +1678,7 @@ def merge_until_split(): try: solution = different_values(tP[i1], tP[i2]) except StopIteration: - tmp_P.join(tP[i1], tP[i2]) + tmp_P.union(tP[i1], tP[i2]) if len(multiple_preimages[tZ]) == 2: del multiple_preimages[tZ] else: @@ -2198,7 +2198,7 @@ def _preprocess_intertwining_relations(self): for a_tuple, image_set in updated_images.items(): image = image_set.pop() while image_set: - P.join(image, image_set.pop()) + P.union(image, image_set.pop()) something_changed = True # we keep a representative image_set.add(image) @@ -3091,9 +3091,9 @@ def _disjoint_set_roots(d): sage: from sage.combinat.bijectionist import _disjoint_set_roots sage: d = DisjointSet('abcde') - sage: d.join("a", "b") - sage: d.join("a", "c") - sage: d.join("e", "d") + sage: d.union("a", "b") + sage: d.union("a", "c") + sage: d.union("e", "d") sage: _disjoint_set_roots(d) dict_keys(['a', 'e']) """ diff --git a/src/sage/combinat/designs/designs_pyx.pyx b/src/sage/combinat/designs/designs_pyx.pyx index 155e2d04902..11c9c5abe9d 100644 --- a/src/sage/combinat/designs/designs_pyx.pyx +++ b/src/sage/combinat/designs/designs_pyx.pyx @@ -492,7 +492,7 @@ def is_group_divisible_design(groups,blocks,v,G=None,K=None,lambd=1,verbose=Fals for i in range(n): for j in range(i + 1, n): if matrix[i * n + j] == 0: - groups.join(i, j) + groups.union(i, j) groups = list(groups.root_to_elements_dict().values()) # Group sizes are element of G diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index cb1cfbcbc2f..97dcf4f366b 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -1029,7 +1029,7 @@ def is_connected(self) -> bool: for B in self._blocks: x = B[0] for i in range(1, len(B)): - D.join(x, B[i]) + D.union(x, B[i]) return D.number_of_subsets() == 1 def is_simple(self) -> bool: diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 2732692074b..d8d25a11fa5 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -3230,7 +3230,7 @@ def fill_to_interval(S): if part: # Skip empty parts c = part[0] for e in fill_to_interval(part): - cong.join(e, c) + cong.union(e, c) t = cong.number_of_subsets() # Following is needed for cases like @@ -3238,7 +3238,7 @@ def fill_to_interval(S): for c in list(cong): r = c[0] for v in fill_to_interval(c): - cong.join(r, v) + cong.union(r, v) todo = {cong.find(e) for part in parts for e in part} @@ -3291,7 +3291,7 @@ def fill_to_interval(S): while c is not None: newblock = cong.find(c) for i in self.interval(c, d): - cong.join(newblock, i) + cong.union(newblock, i) C = cong.root_to_elements_dict()[cong.find(newblock)] mins = [i for i in C if all(i_ not in C for i_ in self.neighbor_in_iterator(i))] maxs = [i for i in C if all(i_ not in C for i_ in self.neighbor_out_iterator(i))] diff --git a/src/sage/combinat/set_partition.py b/src/sage/combinat/set_partition.py index a5c899be44e..a820cd9bd69 100644 --- a/src/sage/combinat/set_partition.py +++ b/src/sage/combinat/set_partition.py @@ -2356,7 +2356,7 @@ def from_arcs(self, arcs, n): """ P = DisjointSet(range(1, n + 1)) for i, j in arcs: - P.join(i, j) + P.union(i, j) return self.element_class(self, P) def from_rook_placement_gamma(self, rooks, n): diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index bc863cf125e..6ac287f2679 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -5201,16 +5201,16 @@ def overlap_partition(self, other, delay=0, p=None, involution=None): S = zip(islice(self, int(delay), None), other) if involution is None: for a, b in S: - p.join(a, b) + p.union(a, b) elif isinstance(involution, WordMorphism): for a, b in S: - p.join(a, b) + p.union(a, b) # take the first letter of the word - p.join(involution(a)[0], involution(b)[0]) + p.union(involution(a)[0], involution(b)[0]) elif callable(involution): for a, b in S: - p.join(a, b) - p.join(involution(a), involution(b)) + p.union(a, b) + p.union(involution(a), involution(b)) else: raise TypeError("involution (=%s) must be callable" % involution) return p diff --git a/src/sage/graphs/connectivity.pyx b/src/sage/graphs/connectivity.pyx index 04452fdda7c..3d9e1a1eda5 100644 --- a/src/sage/graphs/connectivity.pyx +++ b/src/sage/graphs/connectivity.pyx @@ -2540,7 +2540,7 @@ def spqr_tree(G, algorithm="Hopcroft_Tarjan", solver=None, verbose=0, if cocycles_count[fe] == 2 and len(virtual_edge_to_cycles[fe]) == 2: # This virtual edge is only between 2 cycles C1, C2 = virtual_edge_to_cycles[fe] - DS.join(C1, C2) + DS.union(C1, C2) cycles_list[C1].delete_edge(fe) cycles_list[C2].delete_edge(fe) cocycles_count[fe] -= 2 diff --git a/src/sage/graphs/generators/random.py b/src/sage/graphs/generators/random.py index 23ac88813bd..8bf3614ecda 100644 --- a/src/sage/graphs/generators/random.py +++ b/src/sage/graphs/generators/random.py @@ -576,7 +576,7 @@ def RandomBlockGraph(m, k, kmax=None, incidence_structure=False, seed=None): # structure to keep a unique identifier per merged vertices DS = DisjointSet([i for u in B for i in B[u]]) for u, v in T.edges(sort=True, labels=0): - DS.join(choice(B[u]), choice(B[v])) + DS.union(choice(B[u]), choice(B[v])) # We relabel vertices in the range [0, m*(k-1)] and build the incidence # structure diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index a4ca9b04e25..f9cf7f8961a 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -12657,7 +12657,7 @@ def contract_edges(self, edges): DS = DisjointSet(self.vertex_iterator()) for u, v, label in edge_list: - DS.join(u, v) + DS.union(u, v) self.delete_edges(edge_list) edges_incident = [] diff --git a/src/sage/graphs/graph_decompositions/modular_decomposition.py b/src/sage/graphs/graph_decompositions/modular_decomposition.py index 412b12ec36c..d62c28c7922 100644 --- a/src/sage/graphs/graph_decompositions/modular_decomposition.py +++ b/src/sage/graphs/graph_decompositions/modular_decomposition.py @@ -456,7 +456,7 @@ def gamma_classes(graph): e = frozenset([v1, v]) for vi in component[1:]: ei = frozenset([vi, v]) - pieces.join(e, ei) + pieces.union(e, ei) return {frozenset(chain.from_iterable(loe)): loe for loe in pieces} diff --git a/src/sage/graphs/graph_decompositions/tree_decomposition.pyx b/src/sage/graphs/graph_decompositions/tree_decomposition.pyx index 7910591fea8..64bf05b0889 100644 --- a/src/sage/graphs/graph_decompositions/tree_decomposition.pyx +++ b/src/sage/graphs/graph_decompositions/tree_decomposition.pyx @@ -233,7 +233,7 @@ def is_valid_tree_decomposition(G, T): for Xi in X: for Xj in T.neighbor_iterator(Xi): if Xj in X: - D.join(Xi, Xj) + D.union(Xi, Xj) if D.number_of_subsets() > 1: return False diff --git a/src/sage/graphs/partial_cube.py b/src/sage/graphs/partial_cube.py index 39c21b17d37..5f181f557d0 100644 --- a/src/sage/graphs/partial_cube.py +++ b/src/sage/graphs/partial_cube.py @@ -335,9 +335,9 @@ def is_partial_cube(G, certificate=False): if diff not in neighbors: return fail neighbor = neighbors[diff] - unionfind.join(contracted.edge_label(v, w), + unionfind.union(contracted.edge_label(v, w), contracted.edge_label(root, neighbor)) - unionfind.join(contracted.edge_label(w, v), + unionfind.union(contracted.edge_label(w, v), contracted.edge_label(neighbor, root)) labeled.add_edge(v, w) @@ -356,7 +356,7 @@ def is_partial_cube(G, certificate=False): if vi == wi: return fail if newgraph.has_edge(vi, wi): - unionfind.join(newgraph.edge_label(vi, wi), t) + unionfind.union(newgraph.edge_label(vi, wi), t) else: newgraph.add_edge(vi, wi, t) contracted = newgraph diff --git a/src/sage/graphs/spanning_tree.pyx b/src/sage/graphs/spanning_tree.pyx index fdfb70edd41..84088d585d0 100644 --- a/src/sage/graphs/spanning_tree.pyx +++ b/src/sage/graphs/spanning_tree.pyx @@ -345,17 +345,17 @@ def kruskal_iterator(G, by_weight=True, weight_function=None, check_weight=False yield from G.edge_iterator() return - cdef DisjointSet_of_hashables disjointset = DisjointSet_of_hashables(G) + cdef DisjointSet_of_hashables union_find = DisjointSet_of_hashables(G) by_weight, weight_function = G._get_weight_function(by_weight=by_weight, weight_function=weight_function, check_weight=check_weight) - yield from kruskal_iterator_from_edges(G.edge_iterator(), disjointset, + yield from kruskal_iterator_from_edges(G.edge_iterator(), union_find, by_weight=by_weight, weight_function=weight_function, check_weight=False) -def kruskal_iterator_from_edges(edges, disjointset, by_weight=True, +def kruskal_iterator_from_edges(edges, union_find, by_weight=True, weight_function=None, check_weight=False): """ Return an iterator implementation of Kruskal algorithm on list of edges. @@ -364,7 +364,7 @@ def kruskal_iterator_from_edges(edges, disjointset, by_weight=True, - ``edges`` -- list of edges - - ``disjointset`` -- a + - ``union_find`` -- a :class:`~sage.sets.disjoint_set.DisjointSet_of_hashables` encoding a forest @@ -416,13 +416,13 @@ def kruskal_iterator_from_edges(edges, disjointset, by_weight=True, # Kruskal's algorithm for e in edges: # acyclic test via union-find - u = disjointset.find(e[0]) - v = disjointset.find(e[1]) + u = union_find.find(e[0]) + v = union_find.find(e[1]) if u != v: yield e # merge the trees - disjointset.join(u, v) - if disjointset.number_of_subsets() == 1: + union_find.union(u, v) + if union_find.number_of_subsets() == 1: return @@ -657,7 +657,7 @@ def filter_kruskal_iterator(G, threshold=10000, by_weight=True, weight_function= # Parameter to equally divide edges with weight equal the to pivot cdef bint ch = True # Data structure to record the vertices in each tree of the forest - cdef DisjointSet_of_hashables disjointset = DisjointSet_of_hashables(g) + cdef DisjointSet_of_hashables union_find = DisjointSet_of_hashables(g) # # Iteratively partition the list of edges @@ -668,12 +668,12 @@ def filter_kruskal_iterator(G, threshold=10000, by_weight=True, weight_function= if end - begin < threshold: # Filter edges connecting vertices of a same tree L = [edges[e_index[i]] for i in range(begin, end + 1) - if disjointset.find(edges[e_index[i]][0]) != disjointset.find(edges[e_index[i]][1])] - yield from kruskal_iterator_from_edges(L, disjointset, + if union_find.find(edges[e_index[i]][0]) != union_find.find(edges[e_index[i]][1])] + yield from kruskal_iterator_from_edges(L, union_find, by_weight=by_weight, weight_function=weight_function, check_weight=False) - if disjointset.number_of_subsets() == 1: + if union_find.number_of_subsets() == 1: return continue @@ -908,7 +908,7 @@ def boruvka(G, by_weight=True, weight_function=None, check_weight=True, check=Fa component2 = partitions.find(e[1]) if component1 != component2: - partitions.join(component1, component2) + partitions.union(component1, component2) T.append(e) numConComp = numConComp - 1 @@ -1436,7 +1436,7 @@ def edge_disjoint_spanning_trees(G, k, by_weight=False, weight_function=None, ch if augmenting_sequence_found: # We perform the corresponding augmentation - partition[i].join(v, w) + partition[i].union(v, w) while fe in edge_label: F[edge_index[fe]].delete_edge(fe) @@ -1450,7 +1450,7 @@ def edge_disjoint_spanning_trees(G, k, by_weight=False, weight_function=None, ch else: # x and y are in a same tree in every Fi, so in a same clump - partition[0].join(x, y) + partition[0].union(x, y) res = [F[i] for i in range(1, k + 1) if F[i].size() == G.order() - 1] if len(res) != k: diff --git a/src/sage/groups/perm_gps/permgroup.py b/src/sage/groups/perm_gps/permgroup.py index 09236f6502d..4b33600db9f 100644 --- a/src/sage/groups/perm_gps/permgroup.py +++ b/src/sage/groups/perm_gps/permgroup.py @@ -5347,7 +5347,7 @@ def __init__(self, gens, action, domain, gap_group=None, category=None, canonica for g_orbit in g_orbits: for o in g_orbit: for i in range(1, len(o)): - D.join(o[0], o[i]) + D.union(o[0], o[i]) self._orbits = tuple(tuple(o) for o in D) PermutationGroup_generic.__init__(self, gens=gens, diff --git a/src/sage/matroids/graphic_matroid.py b/src/sage/matroids/graphic_matroid.py index 5cfd1481d77..6aedb5e3702 100644 --- a/src/sage/matroids/graphic_matroid.py +++ b/src/sage/matroids/graphic_matroid.py @@ -286,7 +286,7 @@ def _rank(self, X): # This counts components: DS_vertices = DisjointSet(vertices) for (u, v, l) in edges: - DS_vertices.join(u, v) + DS_vertices.union(u, v) return (len(vertices) - DS_vertices.number_of_subsets()) # Representation: @@ -665,7 +665,7 @@ def _corank(self, X): not_our_edges = self.groundset_to_edges(self._groundset.difference(X)) DS_vertices = DisjointSet(all_vertices) for u, v, l in not_our_edges: - DS_vertices.join(u, v) + DS_vertices.union(u, v) return len(X) - (DS_vertices.number_of_subsets() - Integer(1)) def _is_circuit(self, X): @@ -777,7 +777,7 @@ def _max_independent(self, X): DS_vertices = DisjointSet(vertices) for (u, v, l) in edges: if DS_vertices.find(u) != DS_vertices.find(v): - DS_vertices.join(u, v) + DS_vertices.union(u, v) our_set.add(l) return frozenset(our_set) @@ -811,13 +811,13 @@ def _max_coindependent(self, X): our_set = set() DS_vertices = DisjointSet(all_vertices) for (u, v, l) in not_our_edges: - DS_vertices.join(u, v) + DS_vertices.union(u, v) for (u, v, l) in edges: if DS_vertices.find(u) == DS_vertices.find(v): our_set.add(l) else: - DS_vertices.join(u, v) + DS_vertices.union(u, v) return frozenset(our_set) def _circuit(self, X): @@ -876,7 +876,7 @@ def _circuit(self, X): for u, v, l in edges: edge_set.add((u, v, l)) if DS_vertices.find(u) != DS_vertices.find(v): - DS_vertices.join(u, v) + DS_vertices.union(u, v) else: break else: diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 9c2e098b0fc..214743af282 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -1062,7 +1062,7 @@ def connected_components(self): DS = DisjointSet(set().union(*vss)) for u, *vs in vss: for v in vs: - DS.join(u, v) + DS.union(u, v) Ps = {} # map root element -> polynomials in this component for f, vs in zip(self, vss): diff --git a/src/sage/sets/disjoint_set.pxd b/src/sage/sets/disjoint_set.pxd index 9be7051dc67..7e40eeef000 100644 --- a/src/sage/sets/disjoint_set.pxd +++ b/src/sage/sets/disjoint_set.pxd @@ -20,8 +20,8 @@ cdef class DisjointSet_class(SageObject): cpdef number_of_subsets(self) cdef class DisjointSet_of_integers(DisjointSet_class): - cpdef find(self, int i) - cpdef join(self, int i, int j) + cpdef int find(self, int i) + cpdef void union(self, int i, int j) cpdef root_to_elements_dict(self) cpdef element_to_root_dict(self) cpdef to_digraph(self) @@ -30,8 +30,8 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): cdef list _int_to_el cdef dict _el_to_int cdef DisjointSet_of_integers _d - cpdef find(self, e) - cpdef join(self, e, f) + cpdef int find(self, e) + cpdef void union(self, e, f) cpdef root_to_elements_dict(self) cpdef element_to_root_dict(self) cpdef to_digraph(self) diff --git a/src/sage/sets/disjoint_set.pyx b/src/sage/sets/disjoint_set.pyx index 53b451bf442..63dab95917d 100644 --- a/src/sage/sets/disjoint_set.pyx +++ b/src/sage/sets/disjoint_set.pyx @@ -19,12 +19,11 @@ EXAMPLES: Disjoint set of integers from ``0`` to ``n - 1``:: - sage: s = DisjointSet(6) - sage: s + sage: s = DisjointSet(6); s {{0}, {1}, {2}, {3}, {4}, {5}} - sage: s.join(2, 4) - sage: s.join(1, 3) - sage: s.join(5, 1) + sage: s.union(2, 4) + sage: s.union(1, 3) + sage: s.union(5, 1) sage: s {{0}, {1, 3, 5}, {2, 4}} sage: s.find(3) @@ -36,12 +35,11 @@ Disjoint set of integers from ``0`` to ``n - 1``:: Disjoint set of hashables objects:: - sage: d = DisjointSet('abcde') - sage: d + sage: d = DisjointSet('abcde'); d {{'a'}, {'b'}, {'c'}, {'d'}, {'e'}} - sage: d.join('a','b') - sage: d.join('b','c') - sage: d.join('c','d') + sage: d.union('a', 'b') + sage: d.union('b', 'c') + sage: d.union('c', 'd') sage: d {{'a', 'b', 'c', 'd'}, {'e'}} sage: d.find('c') @@ -65,7 +63,7 @@ from sage.groups.perm_gps.partn_ref.data_structures cimport * cpdef DisjointSet(arg): r""" - Constructs a disjoint set where each element of ``arg`` is in its + Construct a disjoint set where each element of ``arg`` is in its own set. If ``arg`` is an integer, then the disjoint set returned is made of the integers from ``0`` to ``arg - 1``. @@ -76,7 +74,7 @@ cpdef DisjointSet(arg): - :meth:`~sage.sets.disjoint_set.DisjointSet_of_hashables.find` -- Determine which set a particular element is in. - - :meth:`~sage.sets.disjoint_set.DisjointSet_of_hashables.join` -- + - :meth:`~sage.sets.disjoint_set.DisjointSet_of_hashables.union` -- Combine or merge two sets into a single set. REFERENCES: @@ -85,7 +83,7 @@ cpdef DisjointSet(arg): INPUT: - - ``arg`` -- non negative integer or an iterable of hashable objects. + - ``arg`` -- non negative integer or an iterable of hashable objects EXAMPLES: @@ -100,7 +98,7 @@ cpdef DisjointSet(arg): {{'a'}, {'b'}, {'c'}, {'d'}, {'e'}} sage: DisjointSet(range(6)) {{0}, {1}, {2}, {3}, {4}, {5}} - sage: DisjointSet(['yi',45,'cheval']) + sage: DisjointSet(['yi', 45, 'cheval']) {{'cheval'}, {'yi'}, {45}} TESTS:: @@ -152,19 +150,19 @@ cdef class DisjointSet_class(SageObject): EXAMPLES:: sage: e = DisjointSet(5) - sage: e.join(2,4); e._repr_() + sage: e.union(2, 4); e._repr_() '{{0}, {1}, {2, 4}, {3}}' sage: e = DisjointSet(5) - sage: e.join(4,2); e._repr_() + sage: e.union(4, 2); e._repr_() '{{0}, {1}, {2, 4}, {3}}' :: sage: e = DisjointSet(range(5)) - sage: e.join(2,4); e._repr_() + sage: e.union(2, 4); e._repr_() '{{0}, {1}, {2, 4}, {3}}' sage: e = DisjointSet(range(5)) - sage: e.join(4,2); e._repr_() + sage: e.union(4, 2); e._repr_() '{{0}, {1}, {2, 4}, {3}}' """ res = [] @@ -181,7 +179,7 @@ cdef class DisjointSet_class(SageObject): EXAMPLES:: sage: d = DisjointSet(4) - sage: d.join(2,0) + sage: d.union(2, 0) sage: sorted(d) [[0, 2], [1], [3]] @@ -209,10 +207,10 @@ cdef class DisjointSet_class(SageObject): :: - sage: d.join(0,3) - sage: d.join(3,4) - sage: e.join(4,0) - sage: e.join(3,0) + sage: d.union(0, 3) + sage: d.union(3, 4) + sage: e.union(4, 0) + sage: e.union(3, 0) sage: e == d True @@ -227,12 +225,12 @@ cdef class DisjointSet_class(SageObject): sage: d = DisjointSet('abcde') sage: e = DisjointSet('abcde') - sage: d.join('a','b') - sage: d.join('b','c') - sage: e.join('c','a') + sage: d.union('a', 'b') + sage: d.union('b', 'c') + sage: e.union('c', 'a') sage: e == d False - sage: e.join('a','b') + sage: e.union('a', 'b') sage: e == d True """ @@ -253,13 +251,13 @@ cdef class DisjointSet_class(SageObject): sage: d = DisjointSet(5) sage: d.cardinality() 5 - sage: d.join(2, 4) + sage: d.union(2, 4) sage: d.cardinality() 5 sage: d = DisjointSet(range(5)) sage: d.cardinality() 5 - sage: d.join(2, 4) + sage: d.union(2, 4) sage: d.cardinality() 5 """ @@ -274,13 +272,13 @@ cdef class DisjointSet_class(SageObject): sage: d = DisjointSet(5) sage: d.number_of_subsets() 5 - sage: d.join(2, 4) + sage: d.union(2, 4) sage: d.number_of_subsets() 4 sage: d = DisjointSet(range(5)) sage: d.number_of_subsets() 5 - sage: d.join(2, 4) + sage: d.union(2, 4) sage: d.number_of_subsets() 4 """ @@ -295,8 +293,8 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d = DisjointSet(5) sage: d {{0}, {1}, {2}, {3}, {4}} - sage: d.join(2,4) - sage: d.join(0,2) + sage: d.union(2, 4) + sage: d.union(0, 2) sage: d {{0, 2, 4}, {1}, {3}} sage: d.find(2) @@ -310,18 +308,18 @@ cdef class DisjointSet_of_integers(DisjointSet_class): :: - sage: a.join(3,4) + sage: a.union(3, 4) sage: a == loads(dumps(a)) True """ def __init__(self, n): r""" - Construction of the DisjointSet where each element (integers from ``0`` + Construct the ``DisjointSet`` where each element (integers from ``0`` to ``n-1``) is in its own set. INPUT: - - ``n`` -- Non negative integer + - ``n`` -- non negative integer EXAMPLES:: @@ -336,7 +334,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): def __dealloc__(self): r""" - Deallocates self, i.e. the self._nodes + Deallocate ``self`` (i.e. the ``self._nodes``). EXAMPLES:: @@ -361,8 +359,8 @@ cdef class DisjointSet_of_integers(DisjointSet_class): :: - sage: d.join(2,4) - sage: d.join(1,3) + sage: d.union(2, 4) + sage: d.union(1, 3) sage: d.__reduce__() (, (5,), [0, 1, 2, 1, 2]) """ @@ -377,10 +375,10 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d = DisjointSet(5) sage: d.__getstate__() [0, 1, 2, 3, 4] - sage: d.join(2,3) + sage: d.union(2, 3) sage: d.__getstate__() [0, 1, 2, 2, 4] - sage: d.join(3,0) + sage: d.union(3, 0) sage: d.__getstate__() [2, 1, 2, 2, 4] @@ -388,10 +386,10 @@ cdef class DisjointSet_of_integers(DisjointSet_class): distinct order:: sage: d = DisjointSet(5) - sage: d.join(0,3) + sage: d.union(0, 3) sage: d.__getstate__() [0, 1, 2, 0, 4] - sage: d.join(2,0) + sage: d.union(2, 0) sage: d.__getstate__() [0, 1, 0, 0, 4] """ @@ -404,7 +402,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): def __setstate__(self, l): r""" - Merge the nodes ``i`` and ``l[i]`` (using join) for ``i`` in + Merge the nodes ``i`` and ``l[i]`` (using union) for ``i`` in ``range(len(l))``. INPUT: @@ -414,35 +412,35 @@ cdef class DisjointSet_of_integers(DisjointSet_class): EXAMPLES:: sage: d = DisjointSet(5) - sage: d.__setstate__([0,1,2,3,4]) + sage: d.__setstate__([0, 1, 2, 3, 4]) sage: d {{0}, {1}, {2}, {3}, {4}} :: sage: d = DisjointSet(5) - sage: d.__setstate__([1,2,3,4,0]) + sage: d.__setstate__([1, 2, 3, 4, 0]) sage: d {{0, 1, 2, 3, 4}} :: sage: d = DisjointSet(5) - sage: d.__setstate__([1,1,1]) + sage: d.__setstate__([1, 1, 1]) sage: d {{0, 1, 2}, {3}, {4}} :: sage: d = DisjointSet(5) - sage: d.__setstate__([3,3,3]) + sage: d.__setstate__([3, 3, 3]) sage: d {{0, 1, 2, 3}, {4}} """ for i, parent in enumerate(l): - self.join(parent, i) + self.union(parent, i) - cpdef find(self, int i): + cpdef int find(self, int i): r""" Return the representative of the set that ``i`` currently belongs to. @@ -453,19 +451,19 @@ cdef class DisjointSet_of_integers(DisjointSet_class): EXAMPLES:: sage: e = DisjointSet(5) - sage: e.join(4,2); e + sage: e.union(4, 2); e {{0}, {1}, {2, 4}, {3}} sage: e.find(2) 4 sage: e.find(4) 4 - sage: e.join(1,3); e + sage: e.union(1, 3); e {{0}, {1, 3}, {2, 4}} sage: e.find(1) 1 sage: e.find(3) 1 - sage: e.join(3,2); e + sage: e.union(3, 2); e {{0}, {1, 2, 3, 4}} sage: [e.find(i) for i in range(5)] [0, 1, 1, 1, 1] @@ -474,7 +472,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): """ return OP_find(self._nodes, i) - cpdef join(self, int i, int j): + cpdef void union(self, int i, int j): r""" Combine the set of ``i`` and the set of ``j`` into one. @@ -490,13 +488,13 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d = DisjointSet(5); d {{0}, {1}, {2}, {3}, {4}} - sage: d.join(0,1); d + sage: d.union(0, 1); d {{0, 1}, {2}, {3}, {4}} - sage: d.join(2,4); d + sage: d.union(2, 4); d {{0, 1}, {2, 4}, {3}} - sage: d.join(1,4); d + sage: d.union(1, 4); d {{0, 1, 2, 4}, {3}} - sage: d.join(1,5); d # no input checking + sage: d.union(1, 5); d # no input checking {{0, 1, 2, 4}, {3}} """ OP_join(self._nodes, i, j) @@ -511,10 +509,10 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d = DisjointSet(5) sage: sorted(d.root_to_elements_dict().items()) [(0, [0]), (1, [1]), (2, [2]), (3, [3]), (4, [4])] - sage: d.join(2,3) + sage: d.union(2, 3) sage: sorted(d.root_to_elements_dict().items()) [(0, [0]), (1, [1]), (2, [2, 3]), (4, [4])] - sage: d.join(3,0) + sage: d.union(3, 0) sage: sorted(d.root_to_elements_dict().items()) [(1, [1]), (2, [0, 2, 3]), (4, [4])] sage: d @@ -537,8 +535,8 @@ cdef class DisjointSet_of_integers(DisjointSet_class): EXAMPLES:: sage: d = DisjointSet(5) - sage: d.join(2,3) - sage: d.join(4,1) + sage: d.union(2, 3) + sage: d.union(4, 1) sage: e = d.element_to_root_dict(); e {0: 0, 1: 4, 2: 2, 3: 2, 4: 4} sage: WordMorphism(e) # needs sage.combinat @@ -558,9 +556,9 @@ cdef class DisjointSet_of_integers(DisjointSet_class): EXAMPLES:: sage: d = DisjointSet(5) - sage: d.join(2,3) - sage: d.join(4,1) - sage: d.join(3,4) + sage: d.union(2, 3) + sage: d.union(4, 1) + sage: d.union(3, 4) sage: d {{0}, {1, 2, 3, 4}} sage: g = d.to_digraph(); g # needs sage.graphs @@ -571,9 +569,9 @@ cdef class DisjointSet_of_integers(DisjointSet_class): The result depends on the ordering of the join:: sage: d = DisjointSet(5) - sage: d.join(1,2) - sage: d.join(1,3) - sage: d.join(1,4) + sage: d.union(1, 2) + sage: d.union(1, 3) + sage: d.union(1, 4) sage: d {{0}, {1, 2, 3, 4}} sage: d.to_digraph().edges(sort=True) # needs sage.graphs @@ -591,7 +589,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: d = DisjointSet('abcde'); d {{'a'}, {'b'}, {'c'}, {'d'}, {'e'}} - sage: d.join('a', 'c'); d + sage: d.union('a', 'c'); d {{'a', 'c'}, {'b'}, {'d'}, {'e'}} sage: d.find('a') 'a' @@ -604,18 +602,17 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): :: - sage: a.join('a','c') + sage: a.union('a', 'c') sage: a == loads(dumps(a)) True """ def __init__(self, iterable): r""" - Construction of the trivial disjoint set where each element is in its - own set. + Construct the trivial disjoint set where each element is in its own set. INPUT: - - ``iterable`` -- An iterable of hashable objects. + - ``iterable`` -- iterable of hashable objects EXAMPLES:: @@ -656,8 +653,8 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): :: - sage: d.join(2,4) - sage: d.join(1,3) + sage: d.union(2, 4) + sage: d.union(1, 3) sage: d.__reduce__() (, ([0, 1, 2, 3, 4],), @@ -674,10 +671,10 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: d = DisjointSet('abcde') sage: d.__getstate__() [('a', 'a'), ('b', 'b'), ('c', 'c'), ('d', 'd'), ('e', 'e')] - sage: d.join('c','d') + sage: d.union('c', 'd') sage: d.__getstate__() [('a', 'a'), ('b', 'b'), ('c', 'c'), ('d', 'c'), ('e', 'e')] - sage: d.join('d','a') + sage: d.union('d', 'a') sage: d.__getstate__() [('a', 'c'), ('b', 'b'), ('c', 'c'), ('d', 'c'), ('e', 'e')] @@ -685,7 +682,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): different order:: sage: d = DisjointSet('abcde') - sage: d.join('d','c') + sage: d.union('d', 'c') sage: d.__getstate__() [('a', 'a'), ('b', 'b'), ('c', 'd'), ('d', 'd'), ('e', 'e')] """ @@ -699,7 +696,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): def __setstate__(self, l): r""" Merge the nodes ``a`` and ``b`` for each pair of nodes - ``(a,b)`` in ``l``. + ``(a, b)`` in ``l``. INPUT: @@ -708,21 +705,21 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): EXAMPLES:: sage: d = DisjointSet('abcde') - sage: d.__setstate__([('a','a'),('b','b'),('c','c')]) + sage: d.__setstate__([('a', 'a'),('b', 'b'),('c', 'c')]) sage: d {{'a'}, {'b'}, {'c'}, {'d'}, {'e'}} :: sage: d = DisjointSet('abcde') - sage: d.__setstate__([('a','b'),('b','c'),('c','d'),('d','e')]) + sage: d.__setstate__([('a', 'b'),('b', 'c'),('c', 'd'),('d', 'e')]) sage: d {{'a', 'b', 'c', 'd', 'e'}} """ for a, b in l: - self.join(a, b) + self.union(a, b) - cpdef find(self, e): + cpdef int find(self, e): r""" Return the representative of the set that ``e`` currently belongs to. @@ -733,19 +730,19 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): EXAMPLES:: sage: e = DisjointSet(range(5)) - sage: e.join(4,2); e + sage: e.union(4, 2); e {{0}, {1}, {2, 4}, {3}} sage: e.find(2) 4 sage: e.find(4) 4 - sage: e.join(1,3); e + sage: e.union(1,3); e {{0}, {1, 3}, {2, 4}} sage: e.find(1) 1 sage: e.find(3) 1 - sage: e.join(3,2); e + sage: e.union(3, 2); e {{0}, {1, 2, 3, 4}} sage: [e.find(i) for i in range(5)] [0, 1, 1, 1, 1] @@ -758,7 +755,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): cdef int r = self._d.find(i) return self._int_to_el[r] - cpdef join(self, e, f): + cpdef void union(self, e, f): r""" Combine the set of ``e`` and the set of ``f`` into one. @@ -774,16 +771,16 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: e = DisjointSet('abcde'); e {{'a'}, {'b'}, {'c'}, {'d'}, {'e'}} - sage: e.join('a','b'); e + sage: e.union('a', 'b'); e {{'a', 'b'}, {'c'}, {'d'}, {'e'}} - sage: e.join('c','e'); e + sage: e.union('c', 'e'); e {{'a', 'b'}, {'c', 'e'}, {'d'}} - sage: e.join('b','e'); e + sage: e.union('b', 'e'); e {{'a', 'b', 'c', 'e'}, {'d'}} """ cdef int i = self._el_to_int[e] cdef int j = self._el_to_int[f] - self._d.join(i, j) + self._d.union(i, j) cpdef root_to_elements_dict(self): r""" @@ -793,8 +790,8 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): EXAMPLES:: sage: d = DisjointSet(range(5)) - sage: d.join(2,3) - sage: d.join(4,1) + sage: d.union(2, 3) + sage: d.union(4, 1) sage: e = d.root_to_elements_dict() sage: sorted(e.items()) [(0, [0]), (2, [2, 3]), (4, [1, 4])] @@ -815,8 +812,8 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): EXAMPLES:: sage: d = DisjointSet(range(5)) - sage: d.join(2,3) - sage: d.join(4,1) + sage: d.union(2, 3) + sage: d.union(4, 1) sage: e = d.element_to_root_dict() sage: sorted(e.items()) [(0, 0), (1, 4), (2, 2), (3, 2), (4, 4)] @@ -830,15 +827,15 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): cpdef to_digraph(self): r""" - Return the current digraph of ``self`` where `(a,b)` is an oriented + Return the current digraph of ``self`` where `(a, b)` is an oriented edge if `b` is the parent of `a`. EXAMPLES:: sage: d = DisjointSet(range(5)) - sage: d.join(2,3) - sage: d.join(4,1) - sage: d.join(3,4) + sage: d.union(2, 3) + sage: d.union(4, 1) + sage: d.union(3, 4) sage: d {{0}, {1, 2, 3, 4}} sage: g = d.to_digraph(); g # needs sage.graphs @@ -849,9 +846,9 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): The result depends on the ordering of the join:: sage: d = DisjointSet(range(5)) - sage: d.join(1,2) - sage: d.join(1,3) - sage: d.join(1,4) + sage: d.union(1, 2) + sage: d.union(1, 3) + sage: d.union(1, 4) sage: d {{0}, {1, 2, 3, 4}} sage: d.to_digraph().edges(sort=True) # needs sage.graphs