README.md 3.7 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 54 55 56

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

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

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

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

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

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

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

邹晓航 已提交
136