Files
esengine/source/src/ECS/Utils/IdentifierPool.ts
2021-05-11 17:23:04 +08:00

22 lines
477 B
TypeScript

module es {
export class IdentifierPool {
private ids: Bag<number>;
private nextAvailableId_ = 0;
constructor() {
this.ids = new Bag<number>();
}
public checkOut(): number {
if (this.ids.size() > 0) {
return this.ids.removeLast();
}
return this.nextAvailableId_++;
}
public checkIn(id: number): void {
this.ids.add(id);
}
}
}