0% found this document useful (0 votes)
31 views

Maps in C++

Maps are associative containers that store elements in a mapped fashion, with each element having a key value and a mapped value such that no two elements can have the same key. Maps provide various functions for inserting, searching, updating and deleting elements by key in logarithmic time complexity, including insert(), count(), equal_range(), erase(), find(), emplace(), upper_bound(), lower_bound(), emplace_hint(), and more. Maps also provide information about size and ordering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Maps in C++

Maps are associative containers that store elements in a mapped fashion, with each element having a key value and a mapped value such that no two elements can have the same key. Maps provide various functions for inserting, searching, updating and deleting elements by key in logarithmic time complexity, including insert(), count(), equal_range(), erase(), find(), emplace(), upper_bound(), lower_bound(), emplace_hint(), and more. Maps also provide information about size and ordering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Maps in C++

Maps are associative containers that store elements in a


mapped fashion. Each element has a key value and a mapped
value. No two mapped values can have the same key values.

List of all Functions of Map


Function Definition
map::insert() Insert elements with a particular key in the
map container –> O(log n)
map:: count() Returns the number of matches to element
with key-value ‘g’ in the map. –> O(log n)
map equal_range() Returns an iterator of pairs. The pair
refers to the bounds of a range that includes all the elements
in the container which have a key equivalent to k.
map erase() Used to erase elements from the container –>
O(log n)
map rend() Returns a reverse iterator pointing to the
theoretical element right before the first key-value pair in the
map(which is considered its reverse end).
map rbegin() Returns a reverse iterator which points to the
last element of the map.
map find() Returns an iterator to the element with key-
value ‘g’ in the map if found, else returns the iterator to end.
map crbegin() and crend() crbegin() returns a constant
reverse iterator referring to the last element in the map
container. crend() returns a constant reverse iterator
pointing to the theoretical element before the first element
in the map.
map cbegin() and cend() cbegin() returns a constant iterator
referring to the first element in the map container. cend()
returns a constant iterator pointing to the theoretical
element that follows the last element in the multimap.
map emplace() Inserts the key and its element in the map
container.
map max_size() Returns the maximum number of elements a
map container can hold –> O(1)
map upper_bound() Returns an iterator to the first element
that is equivalent to mapped value with key-value ‘g’ or
definitely will go after the element with key-value ‘g’ in the
map
map operator= Assigns contents of a container to a different
container, replacing its current content.
map lower_bound() Returns an iterator to the first element
that is equivalent to the mapped value with key-value ‘g’ or
definitely will not go before the element with key-value ‘g’ in
the map –> O(log n)
map emplace_hint() Inserts the key and its element in the
map container with a given hint.
map value_comp() Returns the object that determines how
the elements in the map are ordered (‘<‘ by default).
map key_comp() Returns the object that determines how
the elements in the map are ordered (‘<‘ by default).
map::size() Returns the number of elements in the map.
map::empty() Returns whether the map is empty
map::begin() and end() begin() returns an iterator to the
first element in the map. end() returns an iterator to the
theoretical element that follows the last element in the map
map::operator[] This operator is used to reference the
element present at the position given inside the operator.
map::clear() Removes all the elements from the map.
map::at() and map::swap() at() function is used to return
the reference to the element associated with the key k.
swap() function is used to exchange the contents of two
maps but the maps must be of the same type, although sizes
may differ.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy