IntPool¶
- class emlib.containers.IntPool(capacity, start=0)[source]¶
Bases:
objectA pool of unique intergers with fixed size
A pool will contain the integers in the range [start, start + capacity). Internally an IntPool is really a set. This means that items within the pool are unordered.
- Parameters:
capacity (
int) – the capacity (size) of the pool.start – first element
Example
>>> from emlib.containers import IntPool >>> pool = IntPool(10) >>> token = pool.pop() >>> len(pool) 9 >>> pool.push(token) >>> len(pool) 10 >>> pool.push(4) ValueError: token 4 already in pool
Methods Summary
pop()Take an item from the pool
push(token)Return an item to the pool
Methods Documentation