IdPool
IdPool
Pool of unsigned integer IDs, useful when you don't want to just keep incrementing ID counter and want to re-use IDs after they are no longer needed Main use case is when your IDs are array indices, having compact IDs lets you use fixed size array even as objects are added and removed as you're able to reuse slots in an efficient manner
Kind: global class
- IdPool
- .peek() ⇒
number
- .get() ⇒
number
- .getSpecific(id) ⇒
boolean
- .isUsed(id) ⇒
boolean
- .traverseUsed(visitor)
- .release(id)
- .reset()
- .peek() ⇒
idPool.peek() ⇒ number
Looks up next available ID without reserving it If you want to also reserve the ID - use get instead
Kind: instance method of IdPool
idPool.get() ⇒ number
Kind: instance method of IdPool
idPool.getSpecific(id) ⇒ boolean
Attempt to request a specific ID from the pool.
Kind: instance method of IdPool
Returns: boolean
- true if request succeeds, false otherwise
Param | Type |
---|---|
id | number |
idPool.isUsed(id) ⇒ boolean
Kind: instance method of IdPool
Param | Type |
---|---|
id | number |
idPool.traverseUsed(visitor)
Traverse all IDs currently in use
Kind: instance method of IdPool
Param | Type |
---|---|
visitor | function |
idPool.release(id)
Kind: instance method of IdPool
Param | Type |
---|---|
id | number |
idPool.reset()
Release all used IDs
Kind: instance method of IdPool