Skip to content

Commit 8a590b8

Browse files
author
xingdali
committed
fix快速排序,添加归并排序、希尔排序
1 parent db5c337 commit 8a590b8

File tree

3 files changed

+79
-29
lines changed

3 files changed

+79
-29
lines changed

入门(Java)/力扣经典算法.md

+6
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@ public static int[] heapSort(int[] array) {
540540
}
541541
```
542542

543+
#### 桶排序
544+
545+
```java
546+
547+
```
548+
543549
### 链表
544550

545551
#### 头插法

入门(Java)/经典算法TS实现.md

+58-28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[TOC]
2+
13
### 排序算法
24

35
| 算法 | 稳定 | 原地排序 | 时间复杂度 | 空间复杂度 | 备注 |
@@ -66,43 +68,71 @@ const insertSort = function (nums: number[]) {
6668

6769
#### 希尔排序
6870

69-
```java
70-
71+
```tsx
72+
const shellSort = (nums: number[]) => {
73+
const len = nums.length
74+
let h = len >> 1
75+
while (h >= 1) {
76+
for (let i = h; i < len; i++) {
77+
for (let j = i; j >= h && nums[j] < nums[j - h]; j -= h) {
78+
[nums[j], nums[j - h]] = [nums[j - h], nums[j]]
79+
}
80+
}
81+
h >>= 1
82+
}
83+
}
7184
```
7285

7386
#### 归并排序
7487

75-
```java
76-
88+
```tsx
89+
const mergeSort = (nums: number[], left: number, right: number) => {
90+
if (left === right) return [nums[left]]
91+
const mid = left + ((right - left) >> 1)
92+
const leftArray = mergeSort(nums, left, mid)
93+
const rightArray = mergeSort(nums, mid + 1, right)
94+
const newArray: number[] = new Array(leftArray.length + rightArray.length)
95+
let i = 0, j = 0, k = 0
96+
while (i < leftArray.length && j < rightArray.length) {
97+
newArray[k++] = leftArray[i] < rightArray[j] ? leftArray[i++] : rightArray[j++]
98+
}
99+
while (i < leftArray.length) {
100+
newArray[k++] = leftArray[i++]
101+
}
102+
while (j < rightArray.length) {
103+
newArray[k++] = rightArray[j++]
104+
}
105+
return newArray
106+
}
77107
```
78108

79109
#### 快速排序
80110

81-
```java
111+
```tsx
82112
const quickSort = (nums: number[], start: number, end: number) => {
83-
let left = start,
84-
right = end
85-
const pivot = start
86-
while (left < right) {
87-
while (left < right && nums[right] > nums[pivot]) {
88-
right--
89-
}
90-
while (left < right && nums[left] < nums[pivot]) {
91-
left++
92-
}
93-
if (nums[left] === nums[right] && left < right) {
94-
left++
95-
} else {
96-
;[nums[left], nums[right]] = [nums[right], nums[left]]
97-
}
98-
}
99-
if (start < left - 1) {
100-
quickSort(nums, start, left - 1)
101-
}
102-
if (right + 1 < end) {
103-
quickSort(nums, right + 1, end)
104-
}
105-
return nums
113+
let left = start,
114+
right = end
115+
const pivot = nums[start]
116+
while (left < right) {
117+
while (left < right && nums[right] > pivot) {
118+
right--
119+
}
120+
while (left < right && nums[left] < pivot) {
121+
left++
122+
}
123+
if (nums[left] === nums[right] && left < right) {
124+
left++
125+
} else {
126+
;[nums[left], nums[right]] = [nums[right], nums[left]]
127+
}
128+
}
129+
if (start < left - 1) {
130+
quickSort(nums, start, left - 1)
131+
}
132+
if (right + 1 < end) {
133+
quickSort(nums, right + 1, end)
134+
}
135+
return nums
106136
}
107137
```
108138

论文/论文FaaSNet-ali.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,18 @@ FaaSNet将繁重的元数据管理任务卸载到现有的FaaS调度程序,使
6464

6565
3.5 优化
6666

67-
I/O高效数据格式:
67+
I/O高效数据格式:常规的镜像拉取和启动时低效耗时的,本文设计了一种基于块的图像获取机制,将原始数据分割成固定大小的块并进行压缩,偏移表记录块的偏移量,一个code packages被压缩成二进制文件,由VM代理提取并装入函数容器中。
68+
69+
按需IO:按需加载,从元数据中下载图像压缩清单,解压缩算法比块存储和网络传输好。
70+
71+
RPC和数据流:构建了一个用户级,零copy的RPC库,实现请求流水化和无序接受,类似http2的多路复用。
72+
73+
### 4、实验评估
74+
75+
4.1 实验环境
76+
77+
部署了两个规模的资源池:500vm,1000vm。每个vm实例2CPUs,4GB内存,1Gbps网络带宽,FaaSNet使用512KB的块进行按需提取和流式传输。使用Python3.8运行程序2s,程序容器镜像758MB,函数使用3008MB内存,每个VM运行一个容器化函数。
78+
79+
将FaaSNet与kraken,baseline,on-demand,DADI+P2P进行比较。
80+
81+
4.2 FaaS应用工作负载

0 commit comments

Comments
 (0)