sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.37k stars 462 forks source link

Add hashable/immutable variant for `DisjointSet` objects #38416

Open maxale opened 2 months ago

maxale commented 2 months ago

Problem Description

Currently it impossible to use DisjointSet objects as keys due to the lack of hashability. For example, hash(DisjointSet(5)) gives an error TypeError: unhashable type: 'sage.sets.disjoint_set.DisjointSet_of_integers'

Proposed Solution

Add immutability option for DisjointSet objects (say, like the one in graphs).

Alternatives Considered

Alternatively, a reasonable option is to convert to a SetPartition object, which is hashable. However, the reverse conversion is currently broken - see #38415

Additional Information

No response

Is there an existing issue for this?

Deepakchowdavarapu commented 2 months ago

I can work on this Issue , please Assign it to me