官术网_书友最值得收藏!

Associative containers

Associative containers store data in a sorted fashion, unlike the sequence containers. Hence, the order in which the data is inserted will not be retained by the associative containers. Associative containers are highly efficient in searching a value with O( log n ) runtime complexity. Every time a new value gets added to the container, the container will reorder the values stored internally if required.

The STL supports the following types of associative containers:

  • Set
  • Map
  • Multiset 
  • Multimap
  • Unordered set
  • Unordered multiset
  • Unordered map
  • Unordered multimap

Associative containers organize the data as key-value pairs. The data will be sorted based on the key for random and faster access. Associative containers come in two flavors:

  • Ordered 
  • Unordered

The following associative containers come under ordered containers, as they are ordered/sorted in a particular fashion. Ordered associative containers generally use some form of Binary Search Tree (BST); usually, a red-black tree is used to store the data:

  • Set
  • Map
  • Multiset
  • Multimap

The following associative containers come under unordered containers, as they are not ordered in any particular fashion and they use hash tables:

  • Unordered Set
  • Unordered Map
  • Unordered Multiset
  • Unordered Multimap

Let's understand the previously mentioned containers with examples in the following subsections.

主站蜘蛛池模板: 大庆市| 荆门市| 庄河市| 东安县| 临沂市| 永丰县| 铜川市| 博白县| 唐河县| 永济市| 甘谷县| 思南县| 长岭县| 兴义市| 清徐县| 乌兰浩特市| 阿克| 香格里拉县| 宣化县| 嘉禾县| 东海县| 阿鲁科尔沁旗| 望城县| 武隆县| 塔城市| 安图县| 余姚市| 东乡县| 泽州县| 富阳市| 唐海县| 承德县| 彰化县| 改则县| 册亨县| 商河县| 临泽县| 临澧县| 阳谷县| 汕尾市| 凤山县|