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

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.

主站蜘蛛池模板: 万安县| 怀来县| 北京市| 嵩明县| 台江县| 德昌县| 泾阳县| 平塘县| 韶关市| 镶黄旗| 调兵山市| 积石山| 南岸区| 邵阳市| 阿拉善盟| 墨玉县| 南靖县| 青龙| 夹江县| 望江县| 彰化市| 偃师市| 商洛市| 理塘县| 凤山市| 德兴市| 沙洋县| 道孚县| 明星| 横峰县| 门头沟区| 利津县| 于都县| 汤原县| 安溪县| 南阳市| 大姚县| 陈巴尔虎旗| 桐梓县| 盐边县| 合川市|