From a98ecca3db2f0e6133a60b252ae33e2c43cecc53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 11 Feb 2015 11:02:21 +0800 Subject: [PATCH] --- README.md | 53 +++++++++++++++++++++++++++++++-- TinySTL/TinySTL.vcxproj | 8 +++++ TinySTL/TinySTL.vcxproj.filters | 24 +++++++++++++++ TinySTL/main.cpp | 4 +++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 88a5ca0..8ead48d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ TinySTL * binary_search_tree:100% * avl_tree:100% * suffix_array:100% + *directed_graph:100% ##TinySTL单元测试(原单元测试代码逐步): * pair:100% @@ -95,6 +96,7 @@ TinySTL * binary_search_tree:100% * avl_tree:100% * unordered_set:100% + *directed_graph:100% #TinySTL性能测试: ###测试环境:Windows 7 && VS2013 && release模式 @@ -420,7 +422,7 @@ TinySTL -####(4):sort +####(14):sort std::random_device rd; const int len = 10000000; @@ -439,4 +441,51 @@ TinySTL |TinySTL::sort|1000万|1547| |std::sort|10万|13| |std::sort|100万|147| -|std::sort|1000万|1730| \ No newline at end of file +|std::sort|1000万|1730| + + + + +####(15):directed_graph + + template + using dGraph = TinySTL::directed_graph < Index, Value > ; + dGraph g; + dGraph::nodes_set_type set1, set2, set3; + set1.push_back(g.make_node(1, 11)); + set1.push_back(g.make_node(2, 22)); + set1.push_back(g.make_node(3, 33)); + g.add_node(g.make_node(0, 0), set1); + + set2.push_back(g.make_node(5, 55)); + set2.push_back(g.make_node(6, 66)); + set2.push_back(g.make_node(7, 77)); + g.add_node(g.make_node(1, 11), set2); + + set3.push_back(g.make_node(12, 1212)); + set3.push_back(g.make_node(13, 1313)); + set3.push_back(g.make_node(14, 1414)); + g.add_node(7, set3); + + g.make_edge(12, 2); + g.make_edge(12, 3); + g.make_edge(12, 0); + std::cout << "graph after add nodes:" << std::endl; + std::cout << g.to_string(); + + auto func = [](const dGraph::node_type& node){ + std::cout << "[" << node.first << "," << node.second << "]" << std::endl; + }; + std::cout << "graph DFS from node(1, 11):" << std::endl; + g.DFS(1, func); + std::cout << "graph BFS from node(1, 11):" << std::endl; + g.BFS(1, func); + + std::cout << "graph after delete node(7, 77):" << std::endl; + g.delete_node(dGraph::node_type(7, 77)); + std::cout << g.to_string(); + +![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph1.png) +![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph_dfs.png) +![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph_bfs.png) +![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph2.png) \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index c001942..86b7fee 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -90,6 +90,7 @@ + @@ -115,10 +116,12 @@ + + @@ -133,6 +136,7 @@ + @@ -153,6 +157,10 @@ + + + + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index 0c8b459..788a71f 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -84,6 +84,9 @@ Test + + Test + @@ -227,6 +230,15 @@ Test + + 头文件 + + + Detail + + + Test + @@ -235,5 +247,17 @@ ScreenShots + + ScreenShots + + + ScreenShots + + + ScreenShots + + + ScreenShots + \ No newline at end of file diff --git a/TinySTL/main.cpp b/TinySTL/main.cpp index 7f9aeb6..0ad1d23 100644 --- a/TinySTL/main.cpp +++ b/TinySTL/main.cpp @@ -9,6 +9,7 @@ #include "Test\BinarySearchTreeTest.h" #include "Test\CircularBufferTest.h" #include "Test\DequeTest.h" +#include "Test\GraphTest.h" #include "Test\ListTest.h" #include "Test\PairTest.h" #include "Test\PriorityQueueTest.h" @@ -19,6 +20,8 @@ #include "Test\Unordered_setTest.h" #include "Test\VectorTest.h" +#include "Graph.h" + using namespace TinySTL::Profiler; int main(){ @@ -29,6 +32,7 @@ int main(){ TinySTL::CircularBufferTest::testAllCases(); TinySTL::DequeTest::testAllCases(); TinySTL::ListTest::testAllCases(); + TinySTL::GraphTest::testAllCases(); TinySTL::PairTest::testAllCases(); TinySTL::PriorityQueueTest::testAllCases(); TinySTL::QueueTest::testAllCases();