Skip to content

Commit

Permalink
[tutorial] add trim tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Sep 28, 2024
1 parent a14f68f commit f279714
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ int main() {
* 优化`event`(事件)机制,异步事件可以等待结束
* 发布 [CGraph-lite](https://github.com/ChunelFeng/CGraph-lite) 项目,提供简单DAG构图和参数传递功能。接口完全兼容,可无缝切换至本项目

[2024.09.28 - v2.6.2 - Chunel]
* 更新`tutorial`内容

</details>

------------
Expand Down
1 change: 1 addition & 0 deletions tutorial/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CGRAPH_TUTORIAL_LIST = [
"T24-Fence",
"T25-Coordinator",
"T26-Mutable",
"T27-Trim",
]

[
Expand Down
1 change: 1 addition & 0 deletions tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(CGRAPH_TUTORIAL_LIST
T24-Fence
T25-Coordinator
T26-Mutable
T27-Trim
)


Expand Down
2 changes: 1 addition & 1 deletion tutorial/T26-Mutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@Contact: [email protected]
@File: T26-Mutable.cpp
@Time: 2023/11/15 21:18
@Desc:
@Desc: 本例主要演示,通过 GMutable 在pipeline执行的过程中,修改 GMutable 中的依赖关系逻辑
***************************/

#include "MyGMutable/MyMutable.h"
Expand Down
41 changes: 41 additions & 0 deletions tutorial/T27-Trim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/***************************
@Author: Chunel
@Contact: [email protected]
@File: T27-Trim.cpp
@Time: 2024/9/28 21:43
@Desc: 本例主要演示,通过 Trim() 方法,修剪pipeline中的冗余依赖逻辑
***************************/

#include "MyGNode/MyNode1.h"
#include "MyGNode/MyNode2.h"

using namespace CGraph;

void tutorial_trim() {
GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr a, b, c, d = nullptr;

pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");
pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");

/**
* 可以看出,d节点 对a 的依赖,是可有可无的
* 建议通过 trim() 接口删除冗余依赖
* 参考文档:http://www.chunel.cn/archives/cgraph-remove-redundancy-link
*/
pipeline->registerGElement<MyNode2>(&d, {a, b, c}, "nodeD");

auto trimSize = pipeline->trim();
CGRAPH_ECHO("trim size is: %u", trimSize);

// 查看 trim后的效果
pipeline->dump();
GPipelineFactory::remove(pipeline);
}


int main() {
tutorial_trim();
return 0;
}
3 changes: 2 additions & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ tutorial_list = {
"T23-Some",
"T24-Fence",
"T25-Coordinator",
"T26-Mutable"
"T26-Mutable",
"T27-Trim",
}

-- add tutorial target one by one
Expand Down

0 comments on commit f279714

Please sign in to comment.