| from bitstring import BitArray |
| log = structlog.get_logger() |
| def __init__(self, max_entries, offset): |
| self.max_entries = max_entries |
| self.indices = BitArray(self.max_entries) |
| _pos = self.indices.find('0b0') |
| self.indices.set(1, _pos) |
| return self.offset + _pos[0] |
| log.info("exception-fail-to-allocate-id-all-bits-in-use") |
| def release(self, index): |
| self.indices.set(0, _pos) |
| log.info("bit-position-{}-out-of-range".format(index)) |
| #index or multiple indices to set all of them to 1 - need to be a tuple |
| def pre_allocate(self, index): |
| if(isinstance(index, tuple)): |
| for i in range(len(_lst)): |
| self.indices.set(1, index) |