I have a collection of coordinates which is a fixed set. I collect these into groups using some arbitrary clustering scheme. Consequently I now hold some collection of arrays. I need to be able to merge groups together, or split groups into smaller groups.
Obviously this is Dict
like behaviour. I require that keys are integers which count from 1 -> n
, with no gaps. Splits or merges may happen many, many times, so if a split occurs, I can’t simply delete a key and replace it with two new (higher valued) keys, as this will lead to a growing maximum value of a key, and consequently an eventual overflow.
What data structure has this property? Essentially each time I merge groups I want to permit a gap in the sequence of keys to form, and each time I split a group I want to preferentially fill any existing gaps before creating new key(s). Obviously I can implement this with a queue to which deleted keys are added, and drawn from preferentially before generating new keys, but this is both clumsy and probably reinventing the wheel.
Any advice would be hugely helpful, as the last thing I need is some weird custom behaviour happening behind the scenes.