// Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. export class IndexMap { protected indexMap: Map = new Map(); constructor(private counter: { lastIndex: number } = { lastIndex: 0 }) {} public add(value: T): number { const index = ++this.counter.lastIndex; this.indexMap.set(index, value); return index; } public get(index: number): T | undefined { return this.indexMap.get(index); } public remove(index: number): void { this.indexMap.delete(index); } public get size(): number { return this.indexMap.size; } }