Skip to content

Commit bed5dff

Browse files
committed
小傅哥,文章代码更新。晚上好!
面经手册 · 第4篇《HashMap数据插入、查找、删除、遍历,源码分析》
1 parent b4ec05e commit bed5dff

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
2. [面经手册 · 第1篇《认知自己的技术栈盲区》](https://bugstack.cn/interview/2020/07/30/%E9%9D%A2%E7%BB%8F%E6%89%8B%E5%86%8C-%E7%AC%AC1%E7%AF%87-%E8%AE%A4%E7%9F%A5%E8%87%AA%E5%B7%B1%E7%9A%84%E6%8A%80%E6%9C%AF%E6%A0%88%E7%9B%B2%E5%8C%BA.html)
1313
3. [面经手册 · 第2篇《数据结构,HashCode为什么使用31作为乘数?》](https://bugstack.cn/interview/2020/08/04/%E9%9D%A2%E7%BB%8F%E6%89%8B%E5%86%8C-%E7%AC%AC2%E7%AF%87-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84-HashCode%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BD%BF%E7%94%A831%E4%BD%9C%E4%B8%BA%E4%B9%98%E6%95%B0.html)
1414
4. [面经手册 · 第3篇《HashMap核心知识,扰动函数、负载因子、扩容链表拆分,深度学习》](https://bugstack.cn/interview/2020/08/07/%E9%9D%A2%E7%BB%8F%E6%89%8B%E5%86%8C-%E7%AC%AC3%E7%AF%87-HashMap%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86-%E6%89%B0%E5%8A%A8%E5%87%BD%E6%95%B0-%E8%B4%9F%E8%BD%BD%E5%9B%A0%E5%AD%90-%E6%89%A9%E5%AE%B9%E9%93%BE%E8%A1%A8%E6%8B%86%E5%88%86-%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0.html)
15-
15+
5. [面经手册 · 第4篇《HashMap数据插入、查找、删除、遍历,源码分析》](https://bugstack.cn/interview/2020/08/13/%E9%9D%A2%E7%BB%8F%E6%89%8B%E5%86%8C-%E7%AC%AC4%E7%AF%87-HashMap%E6%95%B0%E6%8D%AE%E6%8F%92%E5%85%A5-%E6%9F%A5%E6%89%BE-%E5%88%A0%E9%99%A4-%E9%81%8D%E5%8E%86-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90.html)

interview-05/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>interview</artifactId>
7+
<groupId>org.itstack</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>interview-05</artifactId>
13+
14+
15+
</project>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package org.itstack.interview.test;
2+
3+
import org.junit.Test;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Set;
8+
import java.util.concurrent.ConcurrentHashMap;
9+
10+
public class ApiTest {
11+
12+
public static void main(String[] args) {
13+
System.out.println("");
14+
Map<String, String> map = new HashMap<String, String>();
15+
map.put("", "");
16+
map.get("");
17+
map.remove("");
18+
19+
20+
}
21+
22+
@Test
23+
public void test_Iterator() {
24+
Map<String, String> map = new HashMap<String, String>(64);
25+
map.put("24", "Idx:2");
26+
map.put("46", "Idx:2");
27+
map.put("68", "Idx:2");
28+
map.put("29", "Idx:7");
29+
map.put("150", "Idx:12");
30+
map.put("172", "Idx:12");
31+
map.put("194", "Idx:12");
32+
map.put("271", "Idx:12");
33+
34+
System.out.println("排序01:");
35+
for (String key : map.keySet()) {
36+
System.out.print(key + " ");
37+
}
38+
39+
map.put("293", "Idx:12");
40+
map.put("370", "Idx:12");
41+
map.put("392", "Idx:12");
42+
map.put("491", "Idx:12");
43+
map.put("590", "Idx:12");
44+
45+
System.out.println("\n\n排序02:");
46+
for (String key : map.keySet()) {
47+
System.out.print(key + " ");
48+
}
49+
50+
map.remove("293");
51+
map.remove("370");
52+
map.remove("392");
53+
map.remove("491");
54+
map.remove("590");
55+
56+
System.out.println("\n\n排序03:");
57+
for (String key : map.keySet()) {
58+
System.out.print(key + " ");
59+
}
60+
61+
}
62+
63+
@Test
64+
public void test_idx12() {
65+
66+
for (int i = 1; i < 1000; i++) {
67+
String key = String.valueOf(i);
68+
int hash = key.hashCode() ^ (key.hashCode() >>> 16);
69+
int idx = (64 - 1) & hash;
70+
71+
if (idx == 2) {
72+
System.out.println(i + " Idx:" + idx);
73+
}
74+
75+
if (idx == 7) {
76+
System.out.println(i + " Idx:" + idx);
77+
}
78+
79+
if (idx == 12) {
80+
System.out.println(i + " Idx:" + idx);
81+
}
82+
}
83+
84+
/**
85+
* idx:12
86+
* 40
87+
* 51
88+
* 62
89+
* 73
90+
* 84
91+
* 95
92+
* 150
93+
* 161
94+
*
95+
* idx:2
96+
* 13
97+
* 24
98+
*
99+
* idx:7
100+
*
101+
* 18
102+
* 29
103+
* 90
104+
*/
105+
106+
}
107+
108+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<module>interview-02</module>
1414
<module>interview-03</module>
1515
<module>interview-04</module>
16+
<module>interview-05</module>
1617
</modules>
1718

1819
<dependencies>

0 commit comments

Comments
 (0)