Skip to content

Latest commit

 

History

History
690 lines (319 loc) · 19.6 KB

STL(侯捷).md

File metadata and controls

690 lines (319 loc) · 19.6 KB

STL

1.C++ Standard Libraty和Standard Template Library的区别

image text

2.STL体系结构基础介绍

2.1六大部件

image text

2.2六大部件的关系

image text

一般不会写分配器,默认使用默认分配器

2.3复杂度,Complexity,Big-oh

image text

2.4前闭后开区间

image text

2.5range-based for statement

image text

2.6auto keyword

image text

3.容器之分类与各种测试

3.1容器 — 结构与分类

image text

​ 序列式容器 关联式容器 无序容器

**Array:**初始空间设多大就是多大,而不是根据元素的多少来分配空间。(前闭后闭)

**Vector:**根据插入多少元素来分配空间。(前闭后开)

**Deque:**前后都可以插入元素。(前开后开)

**List:**双向环状链表。(两个指针)

**Forward-list:**单向链表。(一个指针)

**Set/Multiset:**高度平衡二叉树,key和value无分别。

Map/Multimap:和Set的唯一区别就是,key和value区分开,可通过key来找元素,而Map不能有重复的元素,Multimap可以有重复的元素,Set也同理。

**Hash Table:**由不同篮子组成,每个篮子代表不同的链表。

3.2测试程序辅助函数

image text

3.3使用容器array

image text Array必须先设置一个确定的空间大小

clock():程序从运行开始到调用该函数的时间

3.4使用容器vector

image text

size():真正的元素个数

capacity():容量

image text

3.5使用容器list

image text

3.6使用容器forward_list

image text

3.6使用容器slist

image text

**slist:**单向链表

3.7使用容器deque

image text

image text

3.8使用容器stack

image-text

3.9使用容器queue

image-text

3.10使用容器multiset

image-text

3.11使用容器multimap

image-text

3.12使用容器unordered_multiset

image-text

3.13使用容器unordered_multimap

image-text

3.14使用容器set

image-text

3.15使用容器map

image-text

3.16使用容器unordered_set

image-text

image-text

3.17使用容器unordered_map

image-text

4.分配器之测试

4.1使用分配器allocater

image-text

image-text

image-text

5.源代码之分布(VC,GCC)

5.1标准库版本,Visual C++

image-text

image-text

5.2标准库版本,GNU C++

image-text

image-text

6.OOP(面向对象编程) vs. GP(泛式编程)

image-text

sort在类里

list的迭代器是连续的,而sort算法只有无需迭代器

image-text

sort在类外

image-text

image-text

7.技术基础:操作符重载and模板(泛化,全特化,偏特化)

7.1操作符重载

image-text

7.2Class Templates,类模板

image-text

7.3Function Templates,函数模板

image-text

7.4Member Templates,成员模板

image-text

7.5Specialization,特化

image-text

image-text

image-text

7.6Partial Specialization,偏特化

image-text

泛化:传入的是任意的type

偏特化:传入的是任意type的指针

8.分配器

image-text

image-text

image-text

allocate调用operator new,然后operator new调用malloc

deallocate调用operator delete,然后operator delete调用free

image-text

image-text

image-text

image-text

image-text

额外开销:cookie(夹心饼干),红色,上下两块,各占4个字节,总共八个字节

image-text

image-text

image-text

image-text

image-text

9.容器之间的实现关系与分类

image-text

image-text

10.深度探索list

10.1G2.9容器list

image-text

除了array和vector,其他容器的iterator都要是类,因为需要智能指针

10.2list's iterator

image-text

image-text

image-text

image-text

10.3G4.9容器list

image-text

11.迭代器的设计原则和Iterator Traits的作用与设计

image-text

image-text

image-text

image-text

image-text

12.vector深度探索

image-text

image-text

image-text

image-text

image-text

image-text

image-text

13.array、forward_list深度探索

13.1array

image-text

array不可扩充

13.2forward_list

image-text

14.deque、queue和stack深度探索

14.1deque

image-text

本质:vector

image-text

image-text

image-text

image-text

image-text

image-text

image-text

image-text

image-text

image-text

image-text

扩充后,将旧容器的元素copy到新容器的中段

14.2queue

image-text

14.3stack

image-text

image-text

image-text

image-text

image-text

15.RB-tree深度探索

image-text

image-text

image-text

image-text

image-text

16.set、multiset深度探索

image-text

16.1set

根据key排序

image-text

16.2set,in VC6

image-text

16.3multiset

image-text

优先使用容器自身提供的算法,因为是特化的,更适合该容器

17.map、multimap深度探索

17.1容器map

image-text

image-text

image-text

17.2multimap

image-text

image-text

image-text

18.hashtable深度探索

image-text

image-text

55%53=2,2%53=2,于是这两个元素都放到2号位,串联起来

image-text

image-text

image-text

image-text

image-text

image-text

image-text

image-text

19.unordered容器概念

image-text

只是名字换了而已

20.算法的形式

image-text

21.迭代器的分类(category)

image-text

image-text

image-text

image-text

image-text

22.迭代器分类(category)对算法的影响

image-text

image-text

image-text

image-text

image-text

image-text

先用某个函数判断出迭代器种类,然后根据迭代器种类调用相对应的算法,提高了算法的效率

image-text

并非强制,只是暗示

23.算法源代码剖析(11个例子)

image-text

23.1accumulate

image-text

23.2for_each

image-text

23.3repalce,replace_if,replace_copy

image-text

23.4count,count_if

image-text

23.5find,find_if

image-text

23.6sort

image-text

23.7关于reverse iterator,rbegin(),rend()

image-text

23.8binary_search

image-text

24.仿函数和函数对象

24.1仿函数functors

image-text

image-text

image-text

小括号产生临时对象

24.2仿函数functors的可适配(adaptable)条件

image-text

条件:继承去回答问题

24.3函数对象

函数对象:仿函数临时创造的对象

25.存在多种Adapter

适配器:把东西记起来,以便后面使用

image-text

25.1容器适配器

image-text

25.2函数适配器

image-text

image-text

image-text

image-text

25.3迭代器适配器

image-text

image-text

25.3X适配器:ostream_iterator

image-text

image-text

image-20220724201957037

26.一个万用的hash function

image-text

image-text

image-text

image-text

image-text

27.Tuple

image-text

image-text

t.head()->第一个元素

t.tail()->第一个后面的所有元素

t.tail().head()->第二个元素

28.type traits

image-text

image-text

image-text

29.type traits实现

image-text

image-text

image-text

image-text

30.cout

image-text

image-text

movable元素对于容器速度效能的影响

image-text

image-text

image-text

image-text

image-text

image-text

image-text