File tree 1 file changed +13
-10
lines changed
1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change 3
3
4
4
## 比较 Map 的实现
5
5
6
- 表 ` 16-1 ` 显示了 ` Map ` 的不同平台实现的相对性能(“next”栏显示迭代器在密钥集上的下一次操作的开销)。 与队列的实现一样,您对 ` map ` 类的选择可能更多地受到应用程序的功能需求和所需的并发属性的影响。
6
+ 表 ` 16-1 ` 显示了 ` Map ` 的不同平台实现的相对性能(“next”栏显示迭代器在密钥集上的下一次操作的开销)。 与队列的实现一样,您对 ` map ` 类的选择可能更多地受
7
+ 到应用程序的功能需求和所需的并发属性的影响。
7
8
8
- 一些特殊情况决定了实现:` EnumMap ` 应该总是(并且仅仅)用于从枚举映射。 诸如第 ` 16.2.4 ` 节描述的图遍历等问题需要 ` IdentityHashMap ` 。 对于有排序的映射,请使用不需要线程安全性的 ` TreeMap ` ,否则使用 ` ConcurrentSkipListMap ` 。
9
+ 一些特殊情况决定了实现:` EnumMap ` 应该总是(并且仅仅)用于从枚举映射。 诸如第 ` 16.2.4 ` 节描述的图遍历等问题需要 ` IdentityHashMap ` 。 对于有排序的
10
+ ` Map ` ,请使用不需要线程安全性的 ` TreeMap ` ,否则使用 ` ConcurrentSkipListMap ` 。
9
11
10
12
表 ` 16-1 ` 。 不同 ` Map ` 实现的比较性能
11
13
12
- get containsKey next Notes
13
- HashMap O(1) O(1) O(h/n) h is the table capacity
14
- LinkedHashMap O(1) O(1) O(1)
15
- IdentityHashMap O(1) O(1) O(h/n) h is the table capacity
16
- EnumMap O(1) O(1) O(1)
17
- TreeMap O(log n) O(log n) O(log n)
18
- ConcurrentHashMap O(1) O(1) O(h/n) h is the table capacity
19
- ConcurrentSkipListMap O(log n) O(log n) O(1)
14
+ |get |containsKey| next |Notes
15
+ ---|--- |--- |--- |---
16
+ HashMap |O(1) |O(1) |O(h/n) |h是表格容量
17
+ LinkedHashMap |O(1) |O(1)| O(1)|
18
+ IdentityHashMap |O(1) |O(1) |O(h/n) |h是表格容量
19
+ EnumMap |O(1) |O(1) |O(1)|
20
+ TreeMap |O(log n) |O(log n)| O(log n)|
21
+ ConcurrentHashMap |O(1) |O(1) |O(h/n)| h是表格容量
22
+ ConcurrentSkipListMap| O(log n)| O(log n)| O(1)|
20
23
21
24
这就为通用地图留下了实施的选择。 对于并发应用程序,` ConcurrentHashMap ` 是唯一的选择。 否则,如果您需要使用映射的插入或访问顺序(例如,将其用作缓存),则可以优先使用 ` HashMap ` 上的 ` LinkedHashMap ` (并接受其稍差的性能)。
22
25
You can’t perform that action at this time.
0 commit comments