README.md 4.9 KB
Newer Older
邹晓航 已提交
1 2
TinySTL
=======
邹晓航 已提交
3
采用C++11实现一款简易的STL标准库,既是C++STL的一个子集又是一个超集
邹晓航 已提交
4

邹晓航 已提交
5 6 7
目的:练习数据结构与算法和C++ Template编程

编译环境:VS2013及以上版本
邹晓航 已提交
8

邹晓航 已提交
9
##开发计划:
邹晓航 已提交
10
  * STL的几大基本组件,如string、vector、list、deque、set、map、unordered_\*
邹晓航 已提交
11 12 13 14 15 16
  * STL算法库中的大部分算法
  * circular buffer
  * bitmap
  * skip list
  * binary search tree
  * AVL tree
邹晓航 已提交
17
  * rbtree
邹晓航 已提交
18
  * 线段树
邹晓航 已提交
19 20 21 22 23 24 25 26 27 28
  * splay tree
  * rope
  * Van Emde Boas tree
  * treap
  * B-tree
  * trie
  * suffix array/tree
  * Disjoint-set data structure
  * k-d tree
  * R-tree
邹晓航 已提交
29
  * Matrix
邹晓航 已提交
30
  * Graph
邹晓航 已提交
31
  * ThreadPool
邹晓航 已提交
32

邹晓航 已提交
33
##完成进度:
邹晓航 已提交
34 35 36
* STL的几大基本组件
    * type traits:100%  
    * 空间配置器:100%
邹晓航 已提交
37
    * iterator traits:100%
邹晓航 已提交
38
    * reverse_iterator:100%
邹晓航 已提交
39
    * vector:100%
邹晓航 已提交
40 41 42
* STL Algorithms:  
    * fill:100% 
    * fill_n:100% 
邹晓航 已提交
43
    * find:100%
邹晓航 已提交
44
    * is_heap:100%
邹晓航 已提交
45
    * min、max:100%
邹晓航 已提交
46 47 48 49
    * make_heap:100%
    * pop_heap:100%
    * push_heap:100%
    * sort_heap:100%
邹晓航 已提交
50
    * swap:100%
邹晓航 已提交
51
* circular_buffer:100%   
邹晓航 已提交
52
* bitmap:100%
邹晓航 已提交
53
* string:100%
邹晓航 已提交
54
* priority_queue:100%
邹晓航 已提交
55 56 57 58

#TinySTL测试:
###测试环境:Windows 7 && VS2013 && release模式
###测试结果:
邹晓航 已提交
59
####(1):vector<int>
邹晓航 已提交
60

邹晓航 已提交
61 62
    //std::vector<int> vec;
    TinySTL::vector<int> vec;
邹晓航 已提交
63 64 65 66 67 68 69
	ProfilerInstance::start();
	int i = 0;
	for (; i != 10000; ++i){
		vec.push_back(i);
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
邹晓航 已提交
70
    
邹晓航 已提交
71 72 73
######i = 100000 -> (TinySTL::vector&lt;int>:2ms \\ std::vector&lt;int>:6ms)
######i = 1000000 -> (TinySTL::vector&lt;int>:11ms \\ std::vector&lt;int>:16ms)
######i = 10000000 -> (TinySTL::vector&lt;int>:129ms \\ std::vector&lt;int>:210ms)  
邹晓航 已提交
74
####(2):vector&lt;string>
邹晓航 已提交
75

邹晓航 已提交
76 77 78 79 80 81 82 83 84 85
    //std::vector<std::string> vec;
    TinySTL::vector<std::string> vec;
	ProfilerInstance::start();
	int i = 0;
	for (; i != 10000; ++i){
		vec.push_back(std::string("zouxiaohang"));
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
    
邹晓航 已提交
86 87 88
######i = 100000 -> (TinySTL::vector&lt;string>:18ms \\ std::vector&lt;string>:29ms)
######i = 1000000 -> (TinySTL::vector&lt;string>:181ms \\ std::vector&lt;string>:232ms)
######i = 10000000 -> (TinySTL::vector&lt;string>:2372ms \\ std::vector&lt;string>:1972ms)
邹晓航 已提交
89
####(3):circular_buffer&lt;int, N>
邹晓航 已提交
90

邹晓航 已提交
91 92 93 94 95 96 97 98 99 100 101 102
    TinySTL::circular_buffer<int, 10000> cb(10000, 0);
    //boost::circular_buffer<int> cb(10000, 0);
	ProfilerInstance::start();
	for (int i = 0; i != 10000000; ++i){
		cb.push_back(i);
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
    
######i = 10000000 -> (TinySTL::circular_buffer:75ms \\ boost::circular_buffer:22ms)
######i = 100000000 -> (TinySTL::circular_buffer:604ms \\ boost::circular_buffer:252ms)
######i = 1000000000 -> (TinySTL::circular_buffer:5936ms \\ boost::circular_buffer:2241ms)
邹晓航 已提交
103
####(4):题目:利用bitmap找出str中未出现的字母  
邹晓航 已提交
104

邹晓航 已提交
105 106 107 108 109 110 111 112 113 114 115 116
    std::string str("abcdefghijklmnpqrstuvwxyz");
    TinySTL::bitmap<26> bm;
	for (auto it = str.cbegin(); it != str.cend(); ++it){
		bm.set(*it - 'a');
	}
	cout << bm << endl;
	cout << bm.size() << endl;
	for (int i = 0; i != 26; ++i){
		if (!bm.test(i))
			cout << "字母" << (char)('a' + i) << "没出现!!!" << endl;
	}
输出结果:  
邹晓航 已提交
117

邹晓航 已提交
118 119 120
    111111111111110111111111111000000
    32  
    字母o没出现!!!
邹晓航 已提交
121
    
邹晓航 已提交
122
####(5):string
邹晓航 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136

    //std::string str;
    TinySTL::string str;
	ProfilerInstance::start();
	int i = 0;
	for (; i != 1000000; ++i){
		str.push_back('x');
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
    
######i = 1000000 -> (TinySTL::string:7ms \\ std::string:37ms)
######i = 10000000 -> (TinySTL::string:39ms \\ std::string:229ms)
######i = 100000000 -> (TinySTL::string:484ms \\ std::string:1965ms)
邹晓航 已提交
137

邹晓航 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
####(6):priority_queue&lt;int>

    //std::priority_queue<int> pq;
    TinySTL::priority_queue<int> pq;
	ProfilerInstance::start();
	int i = 0;
	for (; i != 100000; ++i){
		pq.push(i);
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
    
######i = 100000 -> (TinySTL::priority_queue&lt;int>:13ms \\ std::priority_queue&lt;int>:12ms)
######i = 1000000 -> (TinySTL::priority_queue&lt;int>:97ms \\ std::priority_queue&lt;int>:67ms)
######i = 10000000 -> (TinySTL::priority_queue&lt;int>:1032ms \\ std::priority_queue&lt;int>:752ms)  

    TinySTL::vector<int> v;
    int i = 0;
	for (; i != 100000; ++i){
		v.push_back(i);
	}
	//std::priority_queue<int> pq(v.begin(), v.end());
	TinySTL::priority_queue<int> pq(v.begin(), v.end());
	ProfilerInstance::start();
	for (i = 0; i != 100000; ++i){
		pq.pop();
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
    
######i = 100000 -> (TinySTL::priority_queue&lt;int>:19ms \\ std::priority_queue&lt;int>:7ms)
######i = 1000000 -> (TinySTL::priority_queue&lt;int>:137ms \\ std::priority_queue&lt;int>:92ms)
######i = 10000000 -> (TinySTL::priority_queue&lt;int>:1532ms \\ std::priority_queue&lt;int>:1214ms)
邹晓航 已提交
171