core :: DisjointSet :: to_subpartition
es
, a subset of elementsvar s = new DisjointSet[Int]
s.add_all([1,2,3,4,5,6])
s.union(1,2)
s.union(1,3)
s.union(4,5)
var p = s.to_subpartition([1,2,4])
assert p.length == 2
# Construct a partitioning on `es`, a subset of elements
#
# var s = new DisjointSet[Int]
# s.add_all([1,2,3,4,5,6])
# s.union(1,2)
# s.union(1,3)
# s.union(4,5)
# var p = s.to_subpartition([1,2,4])
# assert p.length == 2
fun to_subpartition(es: Collection[E]): Collection[Set[E]]
do
var map = new HashMap[DisjointSetNode, Set[E]]
for e in es do
var ne = find(e)
var set = map.get_or_null(ne)
if set == null then
set = new HashSet[E]
map[ne] = set
end
set.add(e)
end
return map.values
end
lib/core/collection/union_find.nit:175,2--197,4