How about you have your groups::Dict{Int,Whatever} but also have an unused_keys::Vector{Int}. When you do a merge, push! the result onto unused_keys. When you do a split, pop! a key if unused_keys is not empty. I’m not sure if there’s a data structure like this already implemented.
2 Likes