IntPool¶
- class emlib.containers.IntPool(capacity, start=0, fixedsize=True)[source]¶
Bases:
objectA pool of intergers
A pool will contain the integers in the range [start, start + capacity)
- Parameters:
capacity (
int) – the capacity (size) of the pool.start – first element
fixedsize – if True, this pool cannot be extended. Otherwise, when a pop operation would result in an empty pool the pool is doubled in size, adding the new items. A pool cannot be extended by adding elements outside its range, so a push operation might still fail if the item is outside the range of the pool
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