
On Aug 18, 2009, at 9:19 PM, Job Vranish wrote:
data IndexedCollection a = IndexedCollection { nextKey :: Int, availableKeys :: [Int], items :: (IntMap Int a) } deriving (Show)
emptyIndexedCollection :: IndexedCollection a emptyIndexedCollection = IndexedCollection 0 [] empty [...] Does anyone know of a better/already existent data structure for handling this problem? Or perhaps a better way of keeping a "key pool" than my availableKeys solution?
just a slight simplification: you could drop the nextKey field and initialise availableKeys with [0..] in emptyIndexCollection. The add function would consume the head of this list, the remove function add the deleted key as new head. -- Underestimating the novelty of the future is a time-honored tradition. (D.G.)