Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data structures equivalents of STL containers

I study data structures and I want to ask what are the equivalents of STL containers.

for example

  • vector = dynamic array
  • queue = queue
  • stack = stack
  • priority_queue = heap
  • list = linked list
  • set = tree
  • slist = single linked list
  • bit_vector = vector bool
  • map = pair
  • deque = ?
  • multiset = ?
  • multimap = ?
  • hash_set = ?
  • hash_map = ?
  • hash_multiset = ?
  • hash_multimap = ?
  • hash = ?
  • bit_set = ?
like image 406
demosthenes Avatar asked Jun 16 '12 15:06

demosthenes


People also ask

Which data structure is used for STL?

The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms, and iterators.

Is array an STL container?

The STL SequenceContainer types are: array represents a static contiguous array. vector represents a dynamic contiguous array. forward_list represents a singly-linked list.


2 Answers

Concering the C++ standard library containers, the standard itself tries not to say too much about implementation. However, the very specific constraints on complexity of insertion, removal, look-up, range insertion and so on, mean that most implementations use the same types of data structures for the containers. Concerning some of your examples:

  • std::list : doubly linked list
  • std::set, std::multiset, std::map, std::multimap: self-balancing binary trees, typically red-blacktrees.
  • hash_*: C++11 provides unordered_set, unordered_map and multi siblings. These are hash tables.
  • bitset: fixed-size array

I believe the STL follows these implementations.

like image 79
juanchopanza Avatar answered Sep 30 '22 15:09

juanchopanza


I don't think qualifying std::map<> as just a "pair" would be correct. Actually, there is a utility named std::pair<> which is really only just a pair. std::map<> stores unique keys and non-unique values in a way that makes it possible to use a syntax similar to that of an array with indices being of types that can be numerical or not.

Edit: Corrected "container" to "utility" thanks to juanchopanza.

like image 20
ApplePie Avatar answered Sep 30 '22 13:09

ApplePie