README.md 3.6 KB
Newer Older
邹晓航 已提交
1 2 3 4
TinySTL
=======
采用C++11实现一款简易的STL标准库

邹晓航 已提交
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 30
  * Graph

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

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

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

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

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

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

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

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

邹晓航 已提交
135