Skip to content

Commit 126d82b

Browse files
committed
feat: create sync actions
添加 GitHub Actions,实现仓库内容自动同步至 Gitee,并部署到 Gitee Pages
1 parent 53b3c03 commit 126d82b

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.github/workflows/gradle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Algorithms Test
1111
strategy:
1212
matrix:
13-
os: [ubuntu-latest, macos-latest, windows-latest]
13+
os: [ubuntu-latest]
1414
java-version: [1.8]
1515
runs-on: ${{ matrix.os }}
1616

.github/workflows/sync.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Sync
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Sync to Gitee
14+
uses: wearerequired/git-mirror-action@master
15+
env:
16+
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
17+
with:
18+
source-repo: "[email protected]:doocs/data-structure-and-algorithm.git"
19+
destination-repo: "[email protected]:Doocs/data-structure-and-algorithm.git"
20+
21+
- name: Rebuild Gitee Pages
22+
uses: mizuka-wu/[email protected]
23+
with:
24+
repository: doocs/data-structure-and-algorithm
25+
cookie: ${{ secrets.GITEE_COOKIE }}
26+
branch: master

src/main/java/array/DynamicArray.java

+22
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,31 @@ public E remove(int index) {
136136
elements[i - 1] = elements[i];
137137
}
138138
elements[--size] = null;
139+
140+
// 裁剪数组
141+
trim();
142+
139143
return oldElement;
140144
}
141145

146+
/**
147+
* 数组缩容
148+
*/
149+
private void trim() {
150+
int capacity = elements.length;
151+
if (size >= (capacity >> 1) || capacity <= DEFAULT_CAPACITY) {
152+
// 不进行缩容
153+
return;
154+
}
155+
156+
// 缩容
157+
int newCapacity = capacity >> 1;
158+
E[] newElements = (E[]) new Object[newCapacity];
159+
System.arraycopy(elements, 0, newElements, 0, size);
160+
elements = newElements;
161+
162+
}
163+
142164
/**
143165
* 清空数组
144166
*/

0 commit comments

Comments
 (0)