amis-rpc-design/node_modules/monaco-editor/esm/vs/base/common/collections.js
2023-10-07 19:42:30 +08:00

42 lines
1.1 KiB
JavaScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export class SetMap {
constructor() {
this.map = new Map();
}
add(key, value) {
let values = this.map.get(key);
if (!values) {
values = new Set();
this.map.set(key, values);
}
values.add(value);
}
delete(key, value) {
const values = this.map.get(key);
if (!values) {
return;
}
values.delete(value);
if (values.size === 0) {
this.map.delete(key);
}
}
forEach(key, fn) {
const values = this.map.get(key);
if (!values) {
return;
}
values.forEach(fn);
}
get(key) {
const values = this.map.get(key);
if (!values) {
return new Set();
}
return values;
}
}