C++ Library –


C++ Library – <multimap>


”;


Introduction to multimap

Multimap is dictionary like data structure. It is a sequence of (key, value) pair, where multiple values can be associate with equivalent keys. It is often referred as associative array.

In multimap key values generally used to sort the elements. For multimap data type of key and value can differ and it is represented as

typedef pair<const Key, T> value_type;

Multimaps are typically implemented as Binary Search Tree.

Zero sized multimaps are also valid. In that case multimap.begin() and multimap.end() points to same location.

Definition

Below is definition of std::multimap from <multimap> header file

template < class Key,
           class T,
           class Compare = less<Key>,
           class Alloc = allocator<pair<const Key,T> >
           > class multimap;

Parameters

  • Key − Type of the key.

  • T − Type of the mapped values.

  • Compare − A binary predicate that takes two element keys as arguments and returns a bool.

  • Alloc − Type of the allocator object.

  • T may be substituted by any other data type including user-defined type.

Member types

Following member types can be used as parameters or return type by member functions.

Sr.No. Member types Definition
1 key_type Key (First parameter of the template)
2 mapped_type T (Second parameter of the template)
3 key_compare Compare (Third parameter of the template)
4 allocator_type Alloc (Fourth parameter of the template)
5 value_type pair<const key_type,mapped_type>
6 value_compare Nested function class to compare elements
7 reference allocator_type::reference
8 const_reference allocator_type::const_reference
9 pointer allocator_type::pointer
10 const_pointer allocator_type::const_pointer
11 iterator bi-directional iterator to value_type
12 const_iterator bi-directional iterator to const value_type
13 reverse_iterator reverse iterator
14 const_reverse_iterator constant reverse iterator
15 difference_type ptrdiff_t
16 size_type size_t

Functions from <multimap>

Below is list of all methods from <multimap> header.

Constructors

Sr.No. Method & Description
1 multimap::multimap default constructor

Constructs an empty multimap with zero elements.

2 multimap::multimap range constructor

Constructs a multimap with as many elements as in range of first to last.

3 multimap::multimap copy constructor

Constructs a multimap with copy of each elements present in existing multimap.

4 multimap::multimap move constructor

Constructs a multimap with the contents of other using move semantics.

5 multimap::multimap initializer list constructor

Constructs a multimap from initialize list.

Destructor

Sr.No. Method & Description
1 multimap::~multimap

Destroys multimap object by deallocating it”s memory.

Member functions

Sr.No. Method & Description
1 multimap::begin

Returns a iterator which refers to the first element of the multimap.

2 multimap::cbegin

Returns a constant iterator which refers to the first element of the multimap.

3 multimap::cend

Returns a constant iterator which points to past-the-end element of the multimap.

4 multimap::clear

Destroys the multimap by removing all elements and sets size of multimap to zero.

5 multimap::count

Returns number of multimapped values associated with key k.

6 multimap::crbegin

Returns a constant reverse iterator which points to the last element of the container.

7 multimap::crend

Returns a constant reverse iterator which points to the theoretical element preceding the first element in the container.

8 multimap::emplace

Extends container by inserting new element.

9 multimap::emplace_hint hint version

Inserts a new element in a multimap using hint as a position for element.

10 multimap::empty

Tests whether multimap is empty or not.

11 multimap::end

Returns an iterator which points to past-the-end element in the multimap.

12 multimap::equal_range

Returns range of elements that matches specific key.

13 multimap::erase

The erase() function is used to remove the elements from a container.

14 multimap::find

Finds an element associated with key k.

15 multimap::get_allocator

Returns an allocator associated with multimap.

16 multimap::insert

The C++ insert() function is used to add elements to a multimap container.

17 multimap::key_comp

Returns a function object that compares the keys, which is a copy of this container”s constructor argument comp.

18 multimap::lower_bound

Returns an iterator pointing to the first element which is not less than key k.

19 multimap::max_size

Returns the maximum number of elements can be held by multimap.

20 multimap::operator=

The operator=() function is used to assigns the contents of one multimap to another

21 multimap::rbegin

Returns a reverse iterator which points to the last element of the multimap.

22 multimap::rend

Returns a reverse iterator which points to the reverse end of the multimap.

23 multimap::size

Returns the number of elements present in the multimap.

24 multimap::swap

Exchanges the content of multimap with contents of multimap x.

25 multimap::upper_bound

Returns an iterator pointing to the first element which is greater than key k.

26 multimap::value_comp

Returns a function object that compares objects of type std::multimap::value_type.

Non-member overloaded functions

Sr.No. Method & Description
1 operator==

Tests whether two multimaps are equal or not.

2 operator!=

Tests whether two multimaps are equal or not.

3 operator<

Tests whether first multimap is less than other or not.

4 operator&lt=

Tests whether first multimap is less than or equal to other or not.

5 operator>

Tests whether first multimap is greater than other or not.

6 operator>=

Tests whether first multimap is greater than or equal to other or not.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *