Skip to content

Commit

Permalink
update collection
Browse files Browse the repository at this point in the history
  • Loading branch information
codermast committed Apr 4, 2024
1 parent 9627a2e commit e7e87e4
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 72 deletions.
75 changes: 7 additions & 68 deletions docs/.vuepress/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default hopeTheme({

// 作者信息
author: {
name: "友人CoderMast",
name: "友人",
url: "https://www.codermast.com",
email: "[email protected]",
},
Expand All @@ -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",
Expand Down Expand Up @@ -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",
// },
// ],
// },
// ],
// },
// },
},
});
2 changes: 1 addition & 1 deletion docs/java/collection/list-arraylist.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ArrayList 是 List 接口基于数组的一个实现类,故其是一个顺序

ArrayList 继承了 AbstractList ,并实现了 List 接口。

## 使用
## 常用API

ArrayList 位于 java.util 包下,语法格式如下:

Expand Down
4 changes: 4 additions & 0 deletions docs/java/collection/list-stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
order : 3
---
# Collection - Satck源码解析
61 changes: 61 additions & 0 deletions docs/java/collection/map-hashmap.md
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]
警告文字
:::
5 changes: 5 additions & 0 deletions docs/java/collection/map-linkedhashmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
order : 6
---
# Map - LinkedHashMap源码解析

4 changes: 4 additions & 0 deletions docs/java/collection/map-treemap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
order : 5
---
# Map - TreeMap 源码解析
1 change: 1 addition & 0 deletions docs/java/collection/queue-deque.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Queue - Deque源码解析
1 change: 1 addition & 0 deletions docs/java/collection/queue-queue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Queue - Queue源码解析
11 changes: 11 additions & 0 deletions docs/java/collection/set-hashset.md
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)
:::

## 介绍

4 changes: 4 additions & 0 deletions docs/java/collection/set-linkedhashset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
order : 9
---
# Set - LinkedHashSet源码解析
4 changes: 4 additions & 0 deletions docs/java/collection/set-treeset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
order : 8
---
# Set - TreeSet源码解析
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vuepress-theme-hope-template",
"version": "2.0.0",
"description": "A project of vuepress-theme-hope",
"name": "CoderMast-Notes",
"version": "1.0.0",
"description": "A Project Of CoderMast Notes",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down

0 comments on commit e7e87e4

Please sign in to comment.