UNPKG

@tolokoban/tgd

Version:

ToloGameDev library for WebGL2

22 lines 761 B
/** * A Reference Map counts how many time you want to insert the same key. * And it tells you when you delete it as many times. */ export default class ReferenceMap<KeyType, ValueType> { private readonly map; private readonly count; /** * If `key` is already stored in the map, * we add a reference to the mapped value and return it. * If not, we create the mapped value by calling `factory()`. */ add(key: KeyType, factory: () => ValueType): ValueType; /** * Delete a reference to `key`. * If the last reference has been removed, * then return the mapped value, otherwise * return `undefined`. */ delete(key: KeyType): ValueType | undefined; } //# sourceMappingURL=reference-map.d.ts.map