1 | # 哈希 HashMap\<T>
|
2 | HashMap是受限的哈希表,只能通过字符串作为键,由于不需要序列化和类型转换,速度快于HashMap。具体详见哈希表
|
3 |
|
4 | ## 基本操作的API及示例
|
5 |
|
6 | ### Constructor
|
7 | ##### new HashMap(number? size)
|
8 | ``` text
|
9 | 实例:
|
10 | const hashMap = new HashMap();
|
11 |
|
12 | const array = Array(50).fill(0);
|
13 | const hashMap2 = new HashMap(array.length);
|
14 | ```
|
15 |
|
16 | ### 插入 put
|
17 | ##### HashMap put(any key, T value)
|
18 | ``` text
|
19 | 实例:
|
20 | const hashMap = new HashMap();
|
21 | hashMap.put("1", 1);
|
22 | 描述:
|
23 | 对象类型通过JSON序列化为字符串
|
24 | ```
|
25 |
|
26 | ### 获取 get
|
27 | ##### T get(any key)
|
28 | ``` text
|
29 | 实例:
|
30 | const hashMap = new HashMap();
|
31 | hashMap.put("1", 1);
|
32 |
|
33 | hashMap.get("1");
|
34 | // 1
|
35 | ```
|
36 | ### 删除 remove
|
37 | ##### bollean remove(any key)
|
38 | ``` text
|
39 | 实例:
|
40 | const hashMap = new HashMap();
|
41 | hashMap.put("1", 1);
|
42 |
|
43 | hashMap.remove("1");
|
44 | // true
|
45 | ```
|
46 |
|
47 | ### 是否包含指定的key contains
|
48 | ##### bollean contains(any key)
|
49 | ``` text
|
50 | 实例:
|
51 | const hashMap = new HashMap();
|
52 | hashMap.put("1", 1);
|
53 |
|
54 | hashMap.contains("1");
|
55 | // true
|
56 | ```
|
57 |
|
58 | ### 获取所有键 keys
|
59 | ##### string[] keys()
|
60 | ``` text
|
61 | 实例:
|
62 | const hashMap = new HashMap();
|
63 | hashMap.put("1", 1);
|
64 | hashMap.put("2", 2);
|
65 | hashMap.put("3", 3);
|
66 | hashMap.put("4", 4);
|
67 | const keys = hashMap.getKeys();
|
68 | // ["1", "2", "3", "4"]
|
69 | ```
|
70 |
|
71 |
|
72 | ### 获取所有值 values
|
73 | ##### string[] values()
|
74 | ``` text
|
75 | 实例:
|
76 | const hashMap = new HashMap();
|
77 | hashMap.put("1", 1);
|
78 | hashMap.put("2", 2);
|
79 | hashMap.put("3", 3);
|
80 | hashMap.put("4", 4);
|
81 | const keys = hashMap.values();
|
82 | // [1, 2, 3, 4]
|
83 | ``` |
\ | No newline at end of file |