Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commita06125b

Browse files
committed
Make ArrayStringMap file
1 parent1dd6f68 commita06125b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

‎arrayStringMap.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
exportdefaultclassArrayStringMap<Kextendsany[],V>implementsMap<K,V>{
2+
privatereadonly_map:Map<string,V>=newMap<string,V>();
3+
privatereadonly_converterInfo:Map<string,K>=newMap<string,K>();
4+
privatereadonly_sep:string;
5+
6+
publicconstructor(sep:string='\u200b'){
7+
this._sep=sep;
8+
}
9+
10+
11+
publicgetsep():string{
12+
returnthis._sep;
13+
}
14+
15+
publicget[Symbol.toStringTag]():string{
16+
return"ArrayStringMap";
17+
}
18+
19+
publicgetsize():number{
20+
returnthis._map.size;
21+
}
22+
23+
privateencodeArray(arr:K):string{
24+
returnarr.map(x=>x.toString()).join(this._sep)
25+
}
26+
27+
28+
[Symbol.iterator]():IterableIterator<[K,V]>{
29+
returnthis.entries();
30+
}
31+
32+
clear():void{
33+
this._map.clear();
34+
this._converterInfo.clear();
35+
}
36+
37+
delete(key:K):boolean{
38+
returnfalse;
39+
}
40+
41+
*entries():IterableIterator<[K,V]>{
42+
for(const[key,value]ofthis._map.entries()){
43+
// TypeScript complains that this will be undefined, but the items in
44+
// `this._converterInfo` and `this._map` will always be defined in each other.
45+
constarr:K=this._converterInfo.get(key)asK;
46+
yield[arr,value];
47+
}
48+
}
49+
50+
forEach(callbackfn:(value:V,key:K,map:Map<K,V>)=>void,thisArg?:any):void{
51+
this._converterInfo.forEach((value,key)=>{
52+
// TypeScript complains that this will be undefined, but the items in
53+
// `this._converterInfo` and `this._map` will always be defined in each other.
54+
returncallbackfn(this._map.get(key)!,value,thisArg);
55+
});
56+
}
57+
58+
get(key:K):V|undefined{
59+
returnthis._map.get(this.encodeArray(key));
60+
}
61+
62+
has(key:K):boolean{
63+
returnthis._map.has(this.encodeArray(key));
64+
}
65+
66+
keys():IterableIterator<K>{
67+
returnthis._converterInfo.values();
68+
}
69+
70+
set(key:K,value:V): this{
71+
constencodedKey=this.encodeArray(key);
72+
this._map.set(encodedKey,value);
73+
this._converterInfo.set(encodedKey,key);
74+
returnthis;
75+
}
76+
77+
values():IterableIterator<V>{
78+
returnthis._map.values();
79+
}
80+
81+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp