description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CRBMultiMap Class |
CRBMultiMap Class |
11/04/2016 |
|
|
94d3ec0c-3e30-4ab7-a101-d8da4fb8add3 |
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>
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.
Name | Description |
---|---|
CRBMultiMap::CRBMultiMap | The constructor. |
CRBMultiMap::~CRBMultiMap | The destructor. |
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. |
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.
CRBMultiMap
Header: atlcoll.h
The constructor.
explicit CRBMultiMap(size_t nBlockSize = 10) throw();
nBlockSize
The block size.
The nBlockSize parameter is a measure of the amount of memory allocated when a new element is required. Larger block sizes reduce calls to memory allocation routines, but use more resources. The default will allocate space for 10 elements at a time.
See the documentation for the base class CRBTree for information on the other methods available.
[!code-cppNVC_ATL_Utilities#85]
The destructor.
~CRBMultiMap() throw();
Frees any allocated resources.
See the documentation for the base class CRBTree for information on the other methods available.
Call this method to find the position of the first element with a given key.
POSITION FindFirstWithKey(KINARGTYPE key) const throw();
key
Specifies the key that identifies the element to be found.
Returns the POSITION of the first key/value element if the key is found, NULL otherwise.
A key in the CRBMultiMap
can have one or more associated values. This method will provide the position value of the first value (which may, in fact, be the only value) associated with that particular key. The position value returned can then be used with CRBMultiMap::GetNextValueWithKey or CRBMultiMap::GetNextWithKey to obtain the value and update the position.
See the documentation for the base class CRBTree for information on the other methods available.
See the example for CRBMultiMap::CRBMultiMap.
Call this method to get the value associated with a given key and update the position value.
const V& GetNextValueWithKey(
POSITION& pos,
KINARGTYPE key) const throw();
V& GetNextValueWithKey(
POSITION& pos,
KINARGTYPE key) throw();
pos
The position value, obtained with either a call to CRBMultiMap::FindFirstWithKey or CRBMultiMap::GetNextWithKey, or a previous call to GetNextValueWithKey
.
key
Specifies the key that identifies the element to be found.
Returns the element pair associated with the given key.
The position value is updated to point to the next value associated with the key. If no more values exist, the position value is set to NULL.
See the documentation for the base class CRBTree for information on the other methods available.
See the example for CRBMultiMap::CRBMultiMap.
Call this method to get the element associated with a given key and update the position value.
const CPair* GetNextWithKey(
POSITION& pos,
KINARGTYPE key) const throw();
CPair* GetNextWithKey(
POSITION& pos,
KINARGTYPE key) throw();
pos
The position value, obtained with either a call to CRBMultiMap::FindFirstWithKey or CRBMultiMap::GetNextValueWithKey, or a previous call to GetNextWithKey
.
key
Specifies the key that identifies the element to be found.
Returns the next CRBTree::CPair Class element associated with the given key.
The position value is updated to point to the next value associated with the key. If no more values exist, the position value is set to NULL.
See the documentation for the base class CRBTree for information on the other methods available.
Call this method to insert an element pair into the map.
POSITION Insert(KINARGTYPE key, VINARGTYPE value) throw(...);
key
The key value to add to the CRBMultiMap
object.
value
The value to add to the CRBMultiMap
object, associated with key.
Returns the position of the key/value element pair in the CRBMultiMap
object.
See the documentation for the base class CRBTree for information on the other methods available.
See the example for CRBMultiMap::CRBMultiMap.
Call this method to remove all of the key/value elements for a given key.
size_t RemoveKey(KINARGTYPE key) throw();
key
Specifies the key that identifies the element(s) to be deleted.
Returns the number of values associated with the given key.
RemoveKey
deletes all of the key/value elements that have a key that matches key.
See the documentation for the base class CRBTree for information on the other methods available.
See the example for CRBMultiMap::CRBMultiMap.