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

Commit 1b04fa6

Browse files
authored
Update 06_Comparing_Map_Implementations.md
1 parent 1ecd04c commit 1b04fa6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

‎ch16/06_Comparing_Map_Implementations.md‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33

44
## 比较 Map 的实现
55

6-
`16-1` 显示了 `Map` 的不同平台实现的相对性能("next"栏显示迭代器在密钥集上的下一次操作的开销)。 与队列的实现一样,您对 `map` 类的选择可能更多地受到应用程序的功能需求和所需的并发属性的影响。
6+
`16-1` 显示了 `Map` 的不同平台实现的相对性能("next"栏显示迭代器在密钥集上的下一次操作的开销)。 与队列的实现一样,您对 `map` 类的选择可能更多地受
7+
到应用程序的功能需求和所需的并发属性的影响。
78

8-
一些特殊情况决定了实现:`EnumMap` 应该总是(并且仅仅)用于从枚举映射。 诸如第 `16.2.4` 节描述的图遍历等问题需要 `IdentityHashMap`。 对于有排序的映射,请使用不需要线程安全性的 `TreeMap`,否则使用 `ConcurrentSkipListMap`
9+
一些特殊情况决定了实现:`EnumMap` 应该总是(并且仅仅)用于从枚举映射。 诸如第 `16.2.4` 节描述的图遍历等问题需要 `IdentityHashMap`。 对于有排序的
10+
`Map`,请使用不需要线程安全性的 `TreeMap`,否则使用 `ConcurrentSkipListMap`
911

1012
`16-1`。 不同 `Map` 实现的比较性能
1113

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)|
2023

2124
这就为通用地图留下了实施的选择。 对于并发应用程序,`ConcurrentHashMap` 是唯一的选择。 否则,如果您需要使用映射的插入或访问顺序(例如,将其用作缓存),则可以优先使用 `HashMap` 上的 `LinkedHashMap`(并接受其稍差的性能)。
2225

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /