Skip to content

Commit

Permalink
update image
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed May 21, 2024
1 parent 29bbcde commit 969595a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions MD/HashMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> 以下基于 JDK1.7 分析。
![](https://ws2.sinaimg.cn/large/006tNc79gy1fn84b0ftj4j30eb0560sv.jpg)
![](https://i.loli.net/2019/05/08/5cd1d2be77958.jpg)

如图所示,HashMap 底层是基于数组和链表实现的。其中有两个重要的参数:

Expand Down Expand Up @@ -61,7 +61,7 @@ map.forEach((key,value)->{

并发场景发生扩容,调用 `resize()` 方法里的 `rehash()` 时,容易出现环形链表。这样当获取一个不存在的 `key` 时,计算出的 `index` 正好是环形链表的下标时就会出现死循环。

![](https://ws2.sinaimg.cn/large/006tNc79gy1fn85u0a0d9j30n20ii0tp.jpg)
![](https://i.loli.net/2019/05/08/5cd1d2c4ede54.jpg)

> 所以 HashMap 只能在单线程中使用,并且尽量的预设容量,尽可能的减少扩容。
Expand Down
2 changes: 1 addition & 1 deletion MD/LinkedList.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LinkedList 底层分析

![](https://ws4.sinaimg.cn/large/006tKfTcly1fqzb66c00gj30p7056q38.jpg)
![](https://i.loli.net/2019/07/04/5d1cdc7b0c7d526575.jpg)

如图所示 `LinkedList` 底层是基于双向链表实现的,也是实现了 `List` 接口,所以也拥有 List 的一些特点(JDK1.7/8 之后取消了循环,修改为双向链表)。

Expand Down
4 changes: 2 additions & 2 deletions MD/collection/LinkedHashMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

调试可以看到 `map` 的组成:

![](https://ws2.sinaimg.cn/large/006tKfTcly1fo6l9xp91lj319m0s4tgi.jpg)
![](https://i.loli.net/2019/05/08/5cd1ba2adf7c0.jpg)


打开源码可以看到:
Expand Down Expand Up @@ -66,7 +66,7 @@

上边的 demo 总结成一张图如下:

![](https://ws1.sinaimg.cn/large/006tKfTcgy1fodggwc523j30za0n4wgj.jpg)
![](https://i.loli.net/2019/05/08/5cd1ba2d418b6.jpg)

第一个类似于 `HashMap` 的结构,利用 `Entry` 中的 `next` 指针进行关联。

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.crossoverjie.interview</groupId>
<artifactId>interview</artifactId>
<artifactId>JCSprout</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

Expand Down

0 comments on commit 969595a

Please sign in to comment.