新增identifierPool用于实体id复用

This commit is contained in:
yhh
2021-05-11 17:23:04 +08:00
parent e94b7b23e4
commit 63d307b95a
6 changed files with 65 additions and 11 deletions

View File

@@ -0,0 +1,22 @@
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);
}
}
}