代码更新

This commit is contained in:
2022-08-25 11:00:54 +08:00
parent 26c90f894c
commit eed38ad91b
43 changed files with 58165 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

BIN
java/java 基础/SQL.xmind Normal file

Binary file not shown.

View File

@@ -0,0 +1,38 @@
## 1 数据结构分类
数据结构中,数组和链表是物理结构,即在内存中实际的储存方式(有序、无序)
### 1.1 线性结构
#### 1.1.1 数组
1.数组作为一段连续的存储相同类型变量的有序集合,每个元素都有从0开始的唯一索引;而因为其在内存中连续且顺序存储
2.对于数组而言,常见的增删改查时间复杂度如下:
- 带下标查找O(1);
- 不带下表查找,如果为遍历则为O(n),如果为有序数组,采用二分查找发,为O(logn);
- 增、删涉及到元素的移动,复杂度为O(n);
- 改只用根据索引查找改动,复杂度为O(1);
#### 1.1.2 链表
1.链表则是在物理上非连续、非顺序的数据结构,存储的方式时随机存储,有若干节点(node)组成;其中分为单项链表和双向链表,data为存储的数据,next指针指向下一节点,其中尾节点(最后一个节点)next指针指向空,而双向链表多了一个prev节点,指向上一节点,同样其首节点(第一个节点)prev节点指向空
2.对于链表而言,常见的增删改查时间复杂度如下:
- 查找需要遍历整个链表,所以复杂度为O(n);
- 增删(不考虑找到指定位置操作)时,只需处理节点的及其前、后置节点的引用即可,复杂度为O(1);
- 改(不考虑找到指定位置操作)时,只用修改data同样复杂度为O(1);
​
#### 1.1.3 栈和队列
1.栈是一种线性逻辑结构,其中元素只能先进后出(FILO),最早进入的元素在栈顶(bottom),最后(进入)的元素在栈顶(top),而其既能使用数组实现,也能使用链表实现;
2.栈的常见操作有入栈(push)和出栈(pop),入栈即新增一个元素成为栈顶,出栈即将栈顶元素弹出,前一个元素成为新的栈顶;
3.队列同样是一种线性结构,但是其元素是采用先进先出(FIFO),队列的出口端叫作队头(front),队列的入口端叫作队尾(rear),同样可以使用数组或者链表来实现;
4.队列的常见操作有入队(enqueue)和出队(dequeue),入队即把新元素放在队尾,队尾的下一位置称为新的队尾,出队则是把队头的元素移出队列,队头的后一元素成为新的队头;

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

View File

@@ -0,0 +1,108 @@
## 1.put方法
1.1put方法
```java
// 1.首先计算出key的hash值 然后调用putVal()
return putVal(hash(key), key, value, false, true);
```
1.2putVal方法
```java
HashMap.Node<K,V>[] tab; HashMap.Node<K,V> p; int n, i;
// 判断table数组是否为空
if ((tab = table) == null || (n = tab.length) == 0)
// 为空就扩容
n = (tab = resize()).length;
// hash值和n-1与运算 计算出要插入桶的位置
if ((p = tab[i = (n - 1) & hash]) == null)
// 如果为空 就直接放置一个node节点将put的数据加入进去
tab[i] = newNode(hash, key, value, null);
// 如果不为空则走以下代码(也就是hash冲突)
else {
HashMap.Node<K,V> e; K k;
// 判断当前node的key与要put的key是否相等
if (p.hash == hash &&
((k = p.key) == key || (key != null && key.equals(k))))
e = p;
// 判断当前node是否是红黑树的节点
else if (p instanceof HashMap.TreeNode)
// 如果是就将要put进去的数据加入到红黑树当中
e = ((HashMap.TreeNode<K,V>)p).putTreeVal(this, tab, hash, key, value);
// 如果要put的key与当前node节点的key不相同;也不是红黑树的节点,那么就说明要new一个node加入到链表当 中
else {
// 遍历链表(jdk1.8是在链表的尾部插入节点)
for (int binCount = 0; ; ++binCount) {
// 判断p.next是否为空并将e作为p.next的引用
if ((e = p.next) == null) {
// 如果为空则将要put的数据赋值给p,next也就是e
p.next = newNode(hash, key, value, null);
// 判断链表的长度是否大于或者等于红黑树的阈值(8)
if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st
// 若果大于或者等于 则将链表转化为红黑树
treeifyBin(tab, hash);
break;
}
// 在链表中继续寻找是否存在完全相同的key,如果找到则停止链表的遍历并跳到下一步
if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k))))
break;
p = e;
}
}
// 如果这里为true,说明在链表当中找到了相同的key或者没有走到链表代码中(头节点的key与要put的key相 同),则是一个更新的操作
if (e != null) { // existing mapping for key
V oldValue = e.value;
if (!onlyIfAbsent || oldValue == null)
e.value = value;
afterNodeAccess(e);
return oldValue;
}
}
// 插入节点
++modCount;
// 若果当前size大于临界值就扩容 (先插入节点在扩容)
if (++size > threshold)
resize();
afterNodeInsertion(evict);
return null;
```
## 2.get方法
2.1get()
```java
Node<K,V> e;
// 如果为空则返回null,不为空则调用getnode()
return (e = getNode(hash(key), key)) == null ? null : e.value;
```
2.2getNode()
```java
HashMap.Node<K,V>[] tab; HashMap.Node<K,V> first, e; int n; K k;
// 判断此数组是否为空,如果为空返回null,不为空则计算出key的桶位置
if ((tab = table) != null && (n = tab.length) > 0 &&
(first = tab[(n - 1) & hash]) != null) {
// 判断头节点是否是要查询的key,如果是直接返回
if (first.hash == hash && // always check first node
((k = first.key) == key || (key != null && key.equals(k))))
return first;
// 如果头结点不是,就需要循环遍历链表;判断下一节点是否为空,为空则返回null
if ((e = first.next) != null) {
// 判断是否是红黑树,如果是则调用树的查找
if (first instanceof HashMap.TreeNode)
return ((HashMap.TreeNode<K,V>)first).getTreeNode(hash, key);
// 一直循环直到找到相同的key,没有则返回null
do {
if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k))))
return e;
} while ((e = e.next) != null);
}
}
return null;
```