-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHashMap.js
84 lines (84 loc) · 2.11 KB
/
HashMap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var HashMap = (function () {
function HashMap() {
//���峤��
//����һ������
this.obj = {};
}
/**
* �ж�Map�Ƿ�Ϊ��
*/
HashMap.prototype.isEmpty = function () {
return Object.keys(this.obj).length == 0;
};
/**
* �ж϶������Ƿ���������Key
*/
HashMap.prototype.containsKey = function (key) {
return (key in this.obj);
};
/**
* �ж϶������Ƿ�����������Value
*/
HashMap.prototype.containsValue = function (value) {
for (var key in this.obj) {
if (this.obj[key] == value) {
return true;
}
}
return false;
};
/**
*��map����������
*/
HashMap.prototype.put = function (key, value) {
this.obj[key] = value;
};
/**
* ���ݸ�����Key����Value
*/
HashMap.prototype.get = function (key) {
return this.containsKey(key) ? this.obj[key] : null;
};
/**
* ���ݸ�����Keyɾ��һ��ֵ
*/
HashMap.prototype.remove = function (key) {
if (this.containsKey(key)) {
delete this.obj[key];
}
};
/**
* ����Map�����Value
*/
HashMap.prototype.values = function () {
var _values = new Array();
for (var key in this.obj) {
_values.push(this.obj[key]);
}
return _values;
};
/**
* ����Map�����Key
*/
HashMap.prototype.keySet = function () {
var _keys = new Array();
for (var key in this.obj) {
_keys.push(key);
}
return _keys;
};
/**
* ����Map�ij���
*/
HashMap.prototype.size = function () {
return Object.keys(this.obj).length;
};
/**
* ����Map
*/
HashMap.prototype.clear = function () {
this.obj = {};
};
return HashMap;
})();
//# sourceMappingURL=HashMap.js.map