Introduction and classification of containers in STL

Introduction and classification of containers in STL

  C++ STL (Standard Template Library) is a collection of general class templates and algorithms. It provides programmers with the implementation of some standard data structures, called containers, such as queues, lists, and stacks ( Stack) etc.

1. Container introduction

  STL containers are implemented by some of the most widely used data structures. Commonly used data structures are array (array), vector (vector), list (list), tree (tree), stack (stack), queue (queue), hash table (hash table), set (collection), map (mapping) Table) and so on. According to the structure, these data structures can be divided into two types: sequence and associative.
Container classification
  The above figure shows the derivation relationship of various containers (the so-called derivation here is not a derivation relationship, but an implicit relationship). For example, heap contains a vector, priority-queue contains a heap, stack and queue contain a deque, set /map/multiset/multimap all contain an RB-tree, and hash_ contains a hashtbale.

Two, sequential container

Concept: The
  so-called sequential container, the elements in it are all in order, but not necessarily all in order.
Classification:
  sequential structure: vector, list, deque;
  container adapter: stack, queue, priority-queue; it is
  called container adapter because, for example, stack and queue are just redesigned deque, so they are a kind of adapter (Adapter);
  Remarks: The C++ language itself provides a sequential array (not in the STL category).

Three, associative container

Concept:
  Associative container, each data (each data) has a key and a real value.
Features:
  When the element is inserted into the associative container, the internal data structure of the container (RB-tree (Or hash-table, etc.) according to its key size, place this element in the appropriate position according to a certain rule;
  associative container has no head and tail (only the largest element and the smallest element), so there will be no push_back(), push_front( ), pop_back(), pop_front(), begin(), end() and other operations.
Classification:
  Divided into two categories: set (collection) and map (mapping table), as well as the derivatives of the two categories, multiset (multi-key set) and multimap (multi-key mapping table).
  SGI STL also provides an associative container that is not included in the standard specification: hash table (hash table) and hash_set (hash set), hash_map (hash map table), hash_multiset ( Hash multi-key collection), hash_multimap (hash multi-key mapping table).
Low-level implementation:
  The internal structure of the associative container is a balanced binary tree (balanced binary tree) in order to obtain good search efficiency. There are many types of balanced binary trees, including AVL-tree, RB-tree, and AA-tree. Among them, the most widely used STL is RB-tree (red-black tree).
  The bottom layers of set, map, multiset, and multimap are all completed with RB-tree (red-black tree). RB-tree (red-black tree) is also an independent container, but it is not open to outsiders.

Guess you like

Origin blog.csdn.net/hyl1181/article/details/108572531