A Map with an upsert method that is like a "get or set" method. Also supports gc'ing empty upserts.
npm install upsert-map
const UpsertMap = require('upsert-map')
const map = new UpsertMap(() => new Set(), set => !set.size)
map.upsert(10).add(1)
map.upsert(10).add(2)
console.log(...m.values()) // new Set(1, 2)
map.get(10).delete(1)
map.get(10).delete(1)
console.log(...m.values()) // <empty>
Make a new upsert map.
createValue(key)
should return a value to be upserted for a key.isEmpty(val)
can optionally be added for auto gc of empty values.
Returns the value for key if already exists, otherwise it is created and inserted into the map.
Similar to Map.get
Similar to Map.has
Similar to Map.delete
Similar to Map.size
Similar to Map.values()
Similar to Map.keys()
Similar to MapSymbol.iterator
MIT