-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
106 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ export default hopeTheme({ | |
|
||
// 作者信息 | ||
author: { | ||
name: "友人CoderMast", | ||
name: "友人", | ||
url: "https://www.codermast.com", | ||
email: "[email protected]", | ||
}, | ||
|
@@ -38,22 +38,18 @@ export default hopeTheme({ | |
repo: "https://github.com/codermast/codermast-notes", | ||
|
||
// 文档在仓库中的目录 | ||
docsDir: "src", | ||
docsDir: "docs", | ||
|
||
// 文档存放的分值 | ||
docsBranch: "main", | ||
|
||
encrypt: { | ||
config: { | ||
"/demo/encrypt.html": ["1234"], | ||
}, | ||
}, | ||
// encrypt: { | ||
// config: { | ||
// "/demo/encrypt.html": ["1234"], | ||
// }, | ||
// }, | ||
|
||
plugins: { | ||
// 配置博客信息 | ||
blog: { | ||
|
||
}, | ||
// 配置评论框 | ||
comment: { | ||
provider: "Giscus", | ||
|
@@ -104,62 +100,5 @@ export default hopeTheme({ | |
vPre: true, | ||
vuePlayground: true, | ||
}, | ||
|
||
// uncomment these if you want a pwa | ||
// pwa: { | ||
// favicon: "/favicon.ico", | ||
// cacheHTML: true, | ||
// cachePic: true, | ||
// appendBase: true, | ||
// apple: { | ||
// icon: "/assets/icon/apple-icon-152.png", | ||
// statusBarColor: "black", | ||
// }, | ||
// msTile: { | ||
// image: "/assets/icon/ms-icon-144.png", | ||
// color: "#ffffff", | ||
// }, | ||
// manifest: { | ||
// icons: [ | ||
// { | ||
// src: "/assets/icon/chrome-mask-512.png", | ||
// sizes: "512x512", | ||
// purpose: "maskable", | ||
// type: "image/png", | ||
// }, | ||
// { | ||
// src: "/assets/icon/chrome-mask-192.png", | ||
// sizes: "192x192", | ||
// purpose: "maskable", | ||
// type: "image/png", | ||
// }, | ||
// { | ||
// src: "/assets/icon/chrome-512.png", | ||
// sizes: "512x512", | ||
// type: "image/png", | ||
// }, | ||
// { | ||
// src: "/assets/icon/chrome-192.png", | ||
// sizes: "192x192", | ||
// type: "image/png", | ||
// }, | ||
// ], | ||
// shortcuts: [ | ||
// { | ||
// name: "Demo", | ||
// short_name: "Demo", | ||
// url: "/demo/", | ||
// icons: [ | ||
// { | ||
// src: "/assets/icon/guide-maskable.png", | ||
// sizes: "192x192", | ||
// purpose: "maskable", | ||
// type: "image/png", | ||
// }, | ||
// ], | ||
// }, | ||
// ], | ||
// }, | ||
// }, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
order : 3 | ||
--- | ||
# Collection - Satck源码解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
order : 4 | ||
--- | ||
# Map - HashMap 源码解析 | ||
|
||
## 介绍 | ||
|
||
HashMap 是一个散列表,它存储的内容是键值对(key-value)映射,实现了 Map 接口,能够根据键的哈希值(HashCode)存储数据,具有很高的访问效率,最多允许一条键位 null 的值,不支持线程同步,即线程不安全。也不保证元素顺序,即根据需要容器可能会对元素重新哈希,元素的顺序就会被打乱,和 TreeMap 有所区别。 | ||
|
||
|
||
HashMap 是 HashSet、HashTable、ConcurrentHashMap 这三种数据结构的基础。 | ||
|
||
## 常用API | ||
|
||
1. 添加元素 | ||
- `put(K key, V value)`: 将指定的键值对存储到 HashMap 中。 | ||
- `putAll(Map<? extends K, ? extends V> m)`: 将另一个 Map 中的所有键值对添加到当前 HashMap 中。 | ||
|
||
2. 获取元素 | ||
- `get(Object key)`: 获取指定键对应的值。 | ||
- `getOrDefault(key, defaultValue)`:获取指定键对应的值,如果指定键不存在则返回 defaultValue | ||
- `keySet()`: 返回 HashMap 中所有键组成的 Set 集合。 | ||
- `values()`: 返回 HashMap 中所有值组成的 Collection 集合。 | ||
- `entrySet()`: 返回 HashMap 中所有键值对组成的 Set 集合,每个元素都是 Map.Entry 对象,包含键值对信息。 | ||
|
||
3. 删除元素 | ||
- `remove(Object key)`: 删除指定键对应的键值对。 | ||
- `clear()`: 清空 HashMap 中的所有键值对。 | ||
|
||
4. 修改元素 | ||
- `replace(K key, V oldValue, V newValue)`: 将指定键对应的值从 oldValue 替换为 newValue。 | ||
- `replaceAll(BiFunction<? super K,? super V,? extends V> function)`: 使用给定的函数对每个键值对执行替换操作。 | ||
|
||
5. 判断元素 | ||
- `containsKey(Object key)`: 判断 HashMap 是否包含指定的键。 | ||
- `containsValue(Object value)`: 判断 HashMap 是否包含指定的值。 | ||
- `isEmpty()`: 判断 HashMap 是否为空。 | ||
|
||
6. 其他操作 | ||
- `size()`: 返回 HashMap 中键值对的数量。 | ||
|
||
|
||
## 实现方式 | ||
|
||
### 底层存储 | ||
|
||
HashMap 在底层实际上是一个可以扩容的动态数组,数组中存储的是发生冲突的链表节点的头结点,或者是红黑树的根节点。 | ||
|
||
1. 在 JDK8 之前是直接将发生冲突的元素通过链表存储起来。 | ||
|
||
![](../../../assets/map-hashmap/2024-04-05-03-12-28.png) | ||
|
||
|
||
2. 在 JDK8 之后,考虑到了链表的效率不高,根据链表的结点数量将其动态的调整为红黑树。 | ||
|
||
![](../../../assets/map-hashmap/2024-04-05-03-12-35.png) | ||
|
||
::: important | ||
[!caution] | ||
警告文字 | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
order : 6 | ||
--- | ||
# Map - LinkedHashMap源码解析 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
order : 5 | ||
--- | ||
# Map - TreeMap 源码解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Queue - Deque源码解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Queue - Queue源码解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
order : 7 | ||
--- | ||
# Set - HashSet源码解析 | ||
|
||
::: tip 写在前面 | ||
本篇主要是对 Java 中 HashSet 的源码解析,在 Java 中这两种的实现方式是类似的,HashSet 的底层存储还是使用的 HashMap,仅仅通过方法的包装来实现 Set 接口,故本篇不再赘述 HashMap 的底层存储逻辑,详情请看[《Map - HashMap源码解析》](https://www.codermast.com/java/collection/map-hashmap.html)。 | ||
::: | ||
|
||
## 介绍 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
order : 9 | ||
--- | ||
# Set - LinkedHashSet源码解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
order : 8 | ||
--- | ||
# Set - TreeSet源码解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters