| Total Complexity | 4 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | |||
| 9 | class IdGenerator(object): |
||
| 10 | def __init__(self): |
||
| 11 | self.reusableIDs = [] |
||
| 12 | self.allocatedIds = 0 |
||
| 13 | self.idIncrement = 0 |
||
| 14 | |||
| 15 | def gen_id(self): |
||
| 16 | |||
| 17 | self.allocatedIds += 1 |
||
| 18 | if self.reusableIDs: |
||
| 19 | uid = self.reusableIDs.pop(0) |
||
| 20 | else: |
||
| 21 | self.idIncrement += 1 |
||
| 22 | uid = self.idIncrement |
||
| 23 | |||
| 24 | return uid |
||
| 25 | |||
| 26 | def del_id(self, uid): |
||
| 27 | self.allocatedIds -= 1 |
||
| 28 | self.reusableIDs.append(uid) |
||
| 29 | |||
| 30 |