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
  * 线段树
邹晓航 已提交
18 19 20 21 22 23 24 25 26 27
  * splay tree
  * rope
  * Van Emde Boas tree
  * treap
  * B-tree
  * trie
  * suffix array/tree
  * Disjoint-set data structure
  * k-d tree
  * R-tree
邹晓航 已提交
28
  * Matrix
邹晓航 已提交
29
  * Graph
邹晓航 已提交
30
  * ThreadPool
邹晓航 已提交
31

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

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

邹晓航 已提交
60 61
    //std::vector<int> vec;
    TinySTL::vector<int> vec;
邹晓航 已提交
62 63 64 65 66 67 68
	ProfilerInstance::start();
	int i = 0;
	for (; i != 10000; ++i){
		vec.push_back(i);
	}
	ProfilerInstance::finish();
	ProfilerInstance::dumpDuringTime();
邹晓航 已提交
69
    
邹晓航 已提交
70 71 72
######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)  
邹晓航 已提交
73
####(2):vector&lt;string>
邹晓航 已提交
74

邹晓航 已提交
75 76 77 78 79 80 81 82 83 84
    //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();
    
邹晓航 已提交
85 86 87
######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)
邹晓航 已提交
88
####(3):circular_buffer&lt;int, N>
邹晓航 已提交
89

邹晓航 已提交
90 91 92 93 94 95 96 97 98 99 100 101
    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)
邹晓航 已提交
102
####(4):题目:利用bitmap找出str中未出现的字母  
邹晓航 已提交
103

邹晓航 已提交
104 105 106 107 108 109 110 111 112 113 114 115
    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;
	}
输出结果:  
邹晓航 已提交
116

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

    //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)
邹晓航 已提交
136

邹晓航 已提交
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
####(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)
邹晓航 已提交
170