/**字典数据结构类 */
// interface IDictionaryGetSet<KT, VT> {
// readonly [key:string] : any;
// }
class Dictionary<KT, VT> {
private keys: KT[] = [];
private values: VT[] = [];
protected catheData : {[key : string]:any} = {};
protected nElements: number;
private isCache: boolean;
public get count(): number {
return this.Count();
}
public constructor(isCache: boolean = true) {
this.isCache = isCache;
}
/**给字典增加一条数据,返回字典的长度 */
public Add(key: any, value: any): number {
if(this.ContainsKey(key))
{
this.SetDicValue(key,value);
}
else{
if (this.isCache) {
this.catheData[key as string] = value;
}
this.keys.push(key);
this.values.push(value);
this.nElements ++;
}
return this.nElements;
}
public Remove(key: any) {
var index = this.keys.indexOf(key, 0);
if(index != -1)
{
this.keys.splice(index, 1);
this.values.splice(index, 1);
if (th
【Laya】字典的使用
最新推荐文章于 2022-09-05 22:51:47 发布