import { AStarNode } from "./AStarNode"; export class UniqueAStarNodePositions { private items: { [key: string]: { position: T, node: AStarNode } } = {}; private length = 0; constructor(private getKey: (key: T) => string = (key) => key.toString()) { } get count(): number { return this.length; } getNode(position: T): AStarNode { const item = this.items[this.getKey(position)]; return item !== undefined ? item.node : undefined; } add(position: T, node: AStarNode): void { const key = this.getKey(position); if(this.items[key] === undefined) { this.length++; this.items[key] = { position, node }; } } remove(position: T): void { const key = this.getKey(position); if(this.items[key] !== undefined) { this.length--; delete this.items[key]; } } }