Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/sage/sets/disjoint_set.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ from sage.rings.integer cimport Integer
from sage.structure.sage_object cimport SageObject
from cpython.object cimport PyObject_RichCompare
from sage.groups.perm_gps.partn_ref.data_structures cimport *
from sage.combinat.set_partition import SetPartition

cpdef DisjointSet(arg):
r"""
Expand Down Expand Up @@ -103,6 +104,14 @@ cpdef DisjointSet(arg):
sage: DisjointSet(['yi', 45, 'cheval'])
{{'cheval'}, {'yi'}, {45}}

From a set partition (see :issue:`38693`)::

sage: SP = SetPartition(DisjointSet(5))
sage: DisjointSet(SP)
{{0}, {1}, {2}, {3}, {4}}
sage: DisjointSet(SP) == DisjointSet(5)
True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 empty line is enough

TESTS::

sage: DisjointSet(0)
Expand Down Expand Up @@ -137,6 +146,8 @@ cpdef DisjointSet(arg):
if arg < 0:
raise ValueError('arg must be a nonnegative integer (%s given)' % arg)
return DisjointSet_of_integers(arg)
elif isinstance(arg, SetPartition):
return DisjointSet(arg.base_set())
else:
return DisjointSet_of_hashables(arg)

Expand Down