7

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 = ?
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
demosthenes
  • 1,151
  • 1
  • 13
  • 17
  • deque = Double ended queue. Most like a vector where you can push_front the elements too. multi_set = Multiple values ( need not have unique values ); multi_map = A key can have multiple values associated. map != pair but map's container elements are pair. – Mahesh Jun 16 '12 at 15:27
  • `std::hash` isn't a container, it's a functor. – Steve Jessop Jun 16 '12 at 17:58
  • Steve : could you be more specific when u say it's a functor ? – Jay D Jun 16 '12 at 20:35
  • @Jay: well, `std::hash` is a class template. Instantiations of `std::hash` are classes. Instances of those classes are callable. So all three of the template, the class, and the object, can reasonable be described as "a functor". – Steve Jessop Jun 17 '12 at 01:45

4 Answers4

7

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.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
2

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.

ApplePie
  • 8,814
  • 5
  • 39
  • 60
1

set and multiset- binary search tree

map and multimap - binary search tree

deque - deque

the hash* containers are hashed associative containers implemented as hash tables. eg. hash_map contains pair<key,value> which is looked up using hash table.

in bitset

the individual elements are accessed as special references which mimic bool elements

nims
  • 3,751
  • 1
  • 23
  • 27
0
vector = dynamic array  

queue = queue

stack = stack

priority_queue = priority queue based on binary heap 
                 priority_queue can be implemented using 
                 1. sorted array
                 2. sorted list ( unrolled list, skip list etc)
                 3. any other heap like Fibonacci heap, binomial heap

list = doubly linked list 

set = set based on AVL Tree ( usually ) 
      can implemented using any other binary balancing tree like 
      1. Binary Search Tree
      2. Red black Tree
      3. Splay Tree

slist = single linked list

map = map based on Red Black Tree ( usually ) 
      where every node is 'pair' structure
      can implemented using any other binary balancing tree like 
      1. Binary Search Tree
      2. AVL Tree
      3. Splay Tree

deque = deque

hash_set = set implemented using hash

hash_map = hash table

hash = 'Not Available', used as functor
Jai
  • 1,292
  • 4
  • 21
  • 41