"Analysis of STL Source Code" (1) - General Outline

1. Six major components of STL

Containers

Allocators

Algorithms

Iterators

Adapters

Functors

insert image description here

2. The container is an interval that is closed before and after opening

[ ) c.begin() points to the 0th element c.end() points to the one after the last element

3. Classification of container structure

(1) Serial container

Array(c++ 11)
Vector
Deque
List
Forward_List(C++ 11)

(2) Associative container

Set
Multiset
Map
Multimap

(3) Unordered container (C++11)

Unordered Set
Unordered Multiset
Unordered Map
Unordered Mulitmap
insert image description here

4. Use containers

(1) array() fixed container size
(2) vecotr() applies twice the memory size
each time (3) list() applies for one storage unit of memory
each time (4) forward_list() applies for one storage unit each time (5) slist
() #include<ext/slist> = forward_list()
(6) deque() expands one buffer at a time insert image description here
(5) stack() internal implementation is deque() insert image description here
(7) queue() internal implementation is deuque() insert image description here
(8) multiset() value repeatable red-black tree implementation
(9) multimap() key value repeatable, red-black tree implementation
multimap<long, string> c;
(10) unordered_multiset() hash table implementation insert image description here
(11) unordered_multismap() hash table implementation
(12) map() red-black tree
(13) set() red-black tree
(14) unordered_map() hash table
(15) unordered_set() hash table

5. Object-oriented OOP and generic programming thinking GP

OOP binds data and methods together
GP separates data and methods, and calls them through iterators to be as general as possible
All algorithms are internally operated by the elements themselves, which is the ratio of size

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325265162&siteId=291194637