Compartir a través de


CRBMultiMap Class

This class represents a mapping structure that allows each key can be associated with more than one value, using a Red-Black binary tree.

template< 
   typename K, 
   typename V, 
   class KTraits = CElementTraits< K >, 
   class VTraits = CElementTraits< V > 
> class CRBMultiMap : public CRBTree< K, V, KTraits, VTraits >

Parameters

  • K
    The key element type.

  • V
    The value element type.

  • KTraits
    The code used to copy or move key elements. See CElementTraits Class for more details.

  • VTraits
    The code used to copy or move value elements.

Members

Public Constructors

Name

Description

CRBMultiMap::CRBMultiMap

The constructor.

CRBMultiMap::~CRBMultiMap

The destructor.

Public Methods

Name

Description

CRBMultiMap::FindFirstWithKey

Call this method to find the position of the first element with a given key.

CRBMultiMap::GetNextValueWithKey

Call this method to get the value associated with a given key, and update the position value.

CRBMultiMap::GetNextWithKey

Call this method to get the element associated with a given key, and update the position value.

CRBMultiMap::Insert

Call this method to insert an element pair into the map.

CRBMultiMap::RemoveKey

Call this method to remove all of the key/value elements for a given key.

Remarks

CRBMultiMap provides support for a mapping array of any given type, managing an ordered array of key elements and values. Unlike the CRBMap class, each key can be associated with more than one value.

Elements (consisting of a key and a value) are stored in a binary tree structure, using the CRBMultiMap::Insert method. Elements can be removed using the CRBMultiMap::RemoveKey method, which deletes all elements which match the given key.

Traversing the tree is made possible with methods such as CRBTree::GetHeadPosition, CRBTree::GetNext, and CRBTree::GetNextValue. Accessing the potentially multiple values per key is possible using the CRBMultiMap::FindFirstWithKey, CRBMultiMap::GetNextValueWithKey, and CRBMultiMap::GetNextWithKey methods. See the example for CRBMultiMap::CRBMultiMap for an illustration of this in practice.

The KTraits and VTraits parameters are traits classes that contain any supplemental code needed to copy or move elements.

CRBMultiMap is derived from CRBTree, which implements a binary tree using the Red-Black algorithm. An alternative to CRBMultiMap and CRBMap is offered by the CAtlMap class. When only a small number of elements needs to be stored, consider using the CSimpleMap class instead.

For a more complete discussion of the various collection classes and their features and performance characteristics, see ATL Collection Classes.

Inheritance Hierarchy

CRBTree

CRBMultiMap

Requirements

Header: atlcoll.h

See Also

Reference

CRBTree Class

CAtlMap Class

CRBMap Class

Other Resources

ATL Class Overview