IntPool

class emlib.containers.IntPool(capacity, start=0)[source]

Bases: object

A 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

pop()[source]

Take an item from the pool

Return type:

int

push(token)[source]

Return an item to the pool

Raises ValueError if the token is already in the pool or the token is not within the range of the pool

Return type:

None