Skip to content

Commit

Permalink
Merge pull request #44 from zhangzhuang15/dev
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
zhangzhuang15 authored Sep 30, 2024
2 parents 647b76f + 2108a0b commit 2c6d316
Show file tree
Hide file tree
Showing 45 changed files with 2,076 additions and 42 deletions.
47 changes: 46 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export default defineConfig({
],
"/go": [
{ text: "how to learn", link: "/go/how-to-learn" },
{ text: "FAQ", link: '/go/FAQ'}
{ text: "FAQ", link: '/go/FAQ'},
{ text: "Module recommend", link: "/go/recommend-module"}
],
"/rust": [
{ text: "how to learn", link: "/rust/how-to-learn" },
Expand Down Expand Up @@ -223,6 +224,14 @@ export default defineConfig({
text: "进程——问题清单",
link: "/blog/process_question",
},
{
text: "并发编程的一些零碎概念",
link: "/blog/concurrent-concept"
},
{
text: "百万并发?并发连接数上限怎么估计?",
link: "/blog/concurrent-links"
},
{
text: 'Promise Resolve 的秘密',
link: '/blog/promise-resolve'
Expand Down Expand Up @@ -275,10 +284,42 @@ export default defineConfig({
text: "用circle svg绘制圆环",
link: "/blog/circle-svg"
},
{
text: "flex布局小结",
link: "/blog/flex-intro",
},
{
text: "jest学习笔记",
link: "/blog/jest-learn"
},
{
text: '什么是"monad"',
link: "/blog/monad-intro"
},
{
text: "axios和content-type请求头",
link: '/blog/axios-content-type'
},
{
text: "下载html遇到的gzip问题",
link: '/blog/gzip-when-download-html'
},
{
text: "浏览器加载资源小结",
link: "/blog/browser-download-resource"
},
{
text: "coreutils解读",
link: '/blog/core-utils'
},
{
text: "fucking webpack concept",
link: "/blog/fucking-webpack-concept"
},
{
text: "从 ElementUI 源码学到的小知识",
link: '/blog/learn-from-element-ui'
},
{
text: "博客文章阅读系列",
collapsed: true,
Expand All @@ -290,6 +331,10 @@ export default defineConfig({
{
text: '浩叔篇',
link: "/blog/blog-reading/hao-shu"
},
{
text: "Rust",
link: "/blog/blog-reading/rust-program"
}
]
}
Expand Down
42 changes: 42 additions & 0 deletions docs/blog/blog-reading/business-alg.md
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

## 位图

## 布隆过滤器

## 哈夫曼树


## 前缀树

## 时间轮

## 限流算法
34 changes: 34 additions & 0 deletions docs/blog/blog-reading/c-program.md
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
5 changes: 5 additions & 0 deletions docs/blog/blog-reading/compiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "编译原理"
page: true
aside: true
---
23 changes: 23 additions & 0 deletions docs/blog/blog-reading/data-structure-and-alg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: "数据结构和算法"
page: true
aside: true
---

## 红黑树

## 递归树

##

## Trie树

## AC自动机

## MapReduce 和 分治算法

## 动态规划

## A*搜索

## 概率统计:朴素贝叶斯算法和垃圾短信
5 changes: 5 additions & 0 deletions docs/blog/blog-reading/js-graph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "前端可视化"
page: true
aside: true
---
120 changes: 120 additions & 0 deletions docs/blog/blog-reading/rust-program.md
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
Loading

0 comments on commit 2c6d316

Please sign in to comment.