JuliaCollections / JuliaCollections/DataStructures.jl
Conversion DisjointSets to set of sets
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Julia
- Stars
- 745
- Forks
- 261
- PR merge metrics
- No merged PRs in 30d
Description
Feature requested by Ed. Scheinerman of Hopkins
(doing cool graph theory stuff with julia)
He offers a solution as well
using DataStructures
# This takes a DisjointSets object and returns its ground set
function ground_set{T}(DS::DisjointSets{T})
G = Set{T}()
for item in keys(DS.intmap)
push!(G,item)
end
return G
end
function set_of_sets{T}(DS::DisjointSets{T})
n = num_groups(DS)
GS = ground_set(DS)
# Get root elements
roots = Set{Int}()
for item in GS
r = find_root(DS,item)
push!(roots,r)
end
roots = collect(roots)
# Map root numbers to [1:n]
rootmap = Dict{Int,Int}()
for k=1:n
rootmap[roots[k]] = k
end
# Create an array of sets to hold the parts
parts = Array(Set{T},n)
for k=1:n
parts[k] = Set{T}()
end
# place each ground set item in its appropriate part
for item in GS
index = rootmap[find_root(DS,item)]
push!(parts[index], item)
end
# now take those parts and pack them into a set
P = Set{Set{T}}() # This is a set of sets
for item in parts
push!(P,item)
end
return P
end
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the DisjointSets implementation and reviewing its num_groups, find_root, and internal mapping APIs. Compare the requested ground_set and set_of_sets behavior with existing collection conventions, then verify that the conversion preserves every element and group in the returned set of sets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100