From 31846d1640b3285be62dec5973fa465a2ad17348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 29 Jun 2020 22:13:07 +0200 Subject: [PATCH] Using a Set for groups --- back/src/Model/Group.ts | 4 ++-- back/src/Model/World.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/back/src/Model/Group.ts b/back/src/Model/Group.ts index 16cd5ffe..4c597557 100644 --- a/back/src/Model/Group.ts +++ b/back/src/Model/Group.ts @@ -68,7 +68,7 @@ export class Group { leave(user: UserInterface): void { - let success = this.users.delete(user); + const success = this.users.delete(user); if (success === false) { throw new Error("Could not find user "+user.id+" in the group "+this.id); } @@ -84,7 +84,7 @@ export class Group { */ destroy(): void { - for (let user of this.users) { + for (const user of this.users) { this.leave(user); } } diff --git a/back/src/Model/World.ts b/back/src/Model/World.ts index e4ce5c32..6d4fc205 100644 --- a/back/src/Model/World.ts +++ b/back/src/Model/World.ts @@ -20,7 +20,7 @@ export class World { // Users, sorted by ID private readonly users: Map; - private readonly groups: Map; + private readonly groups: Set; private readonly connectCallback: ConnectCallback; private readonly disconnectCallback: DisconnectCallback; @@ -35,7 +35,7 @@ export class World { groupDeletedCallback: GroupDeletedCallback) { this.users = new Map(); - this.groups = new Map(); + this.groups = new Set(); this.connectCallback = connectCallback; this.disconnectCallback = disconnectCallback; this.minDistance = minDistance; @@ -99,7 +99,7 @@ export class World { user, closestUser ], this.connectCallback, this.disconnectCallback); - this.groups.set(group.getId(), group); + this.groups.add(group); } } @@ -132,10 +132,10 @@ export class World { if (group.isEmpty()) { this.groupDeletedCallback(group.getId(), user); group.destroy(); - if (!this.groups.has(group.getId())) { + if (!this.groups.has(group)) { throw new Error("Could not find group "+group.getId()+" referenced by user "+user.id+" in World."); } - this.groups.delete(group.getId()); + this.groups.delete(group); } else { this.groupUpdatedCallback(group); }