-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from zhangzhuang15/dev
Update
- Loading branch information
Showing
45 changed files
with
2,076 additions
and
42 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
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,42 @@ | ||
--- | ||
title: "业务开发算法篇" | ||
page: true | ||
aside: true | ||
--- | ||
|
||
## 双端队列 | ||
|
||
## HashMap | ||
|
||
## TreeMap 和 红黑树 | ||
|
||
## 拓扑排序和webpack | ||
|
||
## 外部排序 | ||
|
||
## MapReduce 和 分治算法 | ||
|
||
## Raft | ||
|
||
## UUID | ||
|
||
## 一致性哈希 | ||
|
||
## B+ Tree | ||
|
||
## LSM Tree | ||
|
||
## LRU | ||
|
||
## 位图 | ||
|
||
## 布隆过滤器 | ||
|
||
## 哈夫曼树 | ||
|
||
|
||
## 前缀树 | ||
|
||
## 时间轮 | ||
|
||
## 限流算法 |
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,34 @@ | ||
--- | ||
title: "深入C语言" | ||
page: true | ||
aside: true | ||
--- | ||
|
||
## C程序的入口不一定是 main 函数 | ||
|
||
## C程序完整的一生 | ||
|
||
## 函数调用 | ||
|
||
## 断言和对齐 | ||
|
||
## ABI 和 API | ||
|
||
|
||
## 运行时进行链接 | ||
|
||
## 编译器链接程序做了什么 | ||
|
||
## 二进制文件 | ||
|
||
|
||
## 高性能C程序 | ||
|
||
|
||
## C语言并发编程 | ||
|
||
|
||
## C语言和Unix | ||
|
||
|
||
## JIT |
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 @@ | ||
--- | ||
title: "编译原理" | ||
page: true | ||
aside: true | ||
--- |
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,23 @@ | ||
--- | ||
title: "数据结构和算法" | ||
page: true | ||
aside: true | ||
--- | ||
|
||
## 红黑树 | ||
|
||
## 递归树 | ||
|
||
## 图 | ||
|
||
## Trie树 | ||
|
||
## AC自动机 | ||
|
||
## MapReduce 和 分治算法 | ||
|
||
## 动态规划 | ||
|
||
## A*搜索 | ||
|
||
## 概率统计:朴素贝叶斯算法和垃圾短信 |
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 @@ | ||
--- | ||
title: "前端可视化" | ||
page: true | ||
aside: true | ||
--- |
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,120 @@ | ||
--- | ||
title: "Rust" | ||
page: true | ||
aside: true | ||
--- | ||
|
||
## Future async await | ||
|
||
|
||
## FnOnce FnMut Fn | ||
|
||
|
||
## How to use Trait | ||
|
||
|
||
## Trait Object | ||
```rust | ||
trait Drawable { | ||
fn draw(&self); | ||
} | ||
|
||
struct Circle; | ||
impl Drawable for Circle { | ||
fn draw(&self) { | ||
println!("Drawing a circle"); | ||
} | ||
} | ||
|
||
struct Square; | ||
impl Drawable for Square { | ||
fn draw(&self) { | ||
println!("Drawing a square"); | ||
} | ||
} | ||
|
||
fn main() { | ||
let shapes: Vec<Box<dyn Drawable>> = vec![ | ||
Box::new(Circle), | ||
Box::new(Square), | ||
]; | ||
|
||
for shape in &shapes { | ||
shape.draw(); | ||
} | ||
} | ||
``` | ||
|
||
`dyn Drawable` 表示的就是 Trait Object,`Box::new(Circle)`就会在运行时转化为如下的数据结构: | ||
```txt | ||
Box<dyn Drawable> { | ||
vtable: &VTable<Drawable>, | ||
data: Circle { /* 数据 */ } | ||
} | ||
VTable<Drawable> { | ||
draw: &Circle::draw, | ||
// 其他方法(如果有的话) | ||
} | ||
``` | ||
|
||
当调用 shape.draw() 时,Rust 会执行以下步骤: | ||
1. 获取虚拟表:从 `Box<dyn Drawable>` 中获取虚拟表指针。 | ||
2. 查找方法:在虚拟表中查找对应的方法指针。 | ||
3. 调用方法:通过方法指针调用实际的方法实现。 | ||
|
||
使用 Trait Object 要千万留意泛型: | ||
:::code-group | ||
```rust [example1.rs] | ||
trait Drawable<T> { | ||
fn draw(&self); | ||
fn say(&self, v: T); | ||
} | ||
|
||
struct Circle; | ||
impl Drawable<String> for Circle { | ||
fn draw(&self) { | ||
println!("Drawing a circle"); | ||
} | ||
fn say(&self, v: String) { | ||
println!("{}", v); | ||
} | ||
} | ||
|
||
fn main() { | ||
// works | ||
let t: Box<dyn Drawable<String>> = Box::new(Circle); | ||
t.draw(); | ||
t.say("hello".to_string()); | ||
} | ||
``` | ||
```rust [example2.rs] | ||
use std::fmt::Display; | ||
trait Drawable { | ||
fn draw(&self); | ||
fn say<T: Display>(&self, v: T); | ||
} | ||
|
||
struct Circle; | ||
impl Drawable for Circle { | ||
fn draw(&self) { | ||
println!("Drawing a circle"); | ||
} | ||
fn say<T: Display>(&self, v: T) { | ||
println!("{}", v); | ||
} | ||
} | ||
|
||
fn main() { | ||
// doesn't work! | ||
let t: Box<dyn Drawable> = Box::new(Circle); | ||
// doesn't work! | ||
t.draw(); | ||
// doesn't work! | ||
t.say("hello".to_string()); | ||
} | ||
``` | ||
::: | ||
|
||
|
||
## Lifetime |
Oops, something went wrong.