Debian Codegraph @

node/@xterm/xterm/src/common/MultiKeyMap.ts

raw
1 /**
2 * Copyright (c) 2022 The xterm.js authors. All rights reserved.
3 * @license MIT
4 */
5
6 export class TwoKeyMap<TFirst extends string | number, TSecond extends string | number, TValue> {
7 private _data: { [bg: string | number]: { [fg: string | number]: TValue | undefined } | undefined } = {};
8
9 public set(first: TFirst, second: TSecond, value: TValue): void {
10 if (!this._data[first]) {
11 this._data[first] = {};
12 }
13 this._data[first as string | number]![second] = value;
14 }
15
16 public get(first: TFirst, second: TSecond): TValue | undefined {
17 return this._data[first as string | number] ? this._data[first as string | number]![second] : undefined;
18 }
19
20 public clear(): void {
21 this._data = {};
22 }
23 }
24
25 export class FourKeyMap<TFirst extends string | number, TSecond extends string | number, TThird extends string | number, TFourth extends string | number, TValue> {
26 private _data: TwoKeyMap<TFirst, TSecond, TwoKeyMap<TThird, TFourth, TValue>> = new TwoKeyMap();
27
28 public set(first: TFirst, second: TSecond, third: TThird, fourth: TFourth, value: TValue): void {
29 if (!this._data.get(first, second)) {
30 this._data.set(first, second, new TwoKeyMap());
31 }
32 this._data.get(first, second)!.set(third, fourth, value);
33 }
34
35 public get(first: TFirst, second: TSecond, third: TThird, fourth: TFourth): TValue | undefined {
36 return this._data.get(first, second)?.get(third, fourth);
37 }
38
39 public clear(): void {
40 this._data.clear();
41 }
42 }