Condividi tramite


CMap::Lookup

Looks up the value mapped to a given key.

BOOL Lookup(
   ARG_KEY key,
   VALUE& rValue 
) const;

Parameters

  • ARG_KEY
    Template parameter specifying the type of the key value.

  • key
    Specifies the key that identifies the element to be looked up.

  • VALUE
    Specifies the type of the value to be looked up.

  • rValue
    Receives the looked-up value.

Return Value

Nonzero if the element was found; otherwise 0.

Remarks

Lookup uses a hashing algorithm to quickly find the map element with a key that exactly matches the given key.

Example

         CMap<int,int,CPoint,CPoint> myMap;

         myMap.InitHashTable(257);

         // Add 200 elements to the map.
         for (int i = 0; i < 200; i++)
            myMap[i] = CPoint(i, i);

         // Remove the elements with even key values.
         CPoint pt;
         for (int i = 0; myMap.Lookup(i, pt); i += 2)
         {
            myMap.RemoveKey(i);
         }

         ASSERT(myMap.GetSize() == 100);
         TRACE(_T("myMap with %d elements:\n"), myMap.GetCount());
           POSITION pos = myMap.GetStartPosition();
         int iKey;
         CPoint ptVal;
           while (pos != NULL)
           {
               myMap.GetNextAssoc(pos, iKey, ptVal);
               TRACE(_T("\t[%d] = (%d,%d)\n"), iKey, ptVal.x, ptVal.y);
         }

Requirements

Header: afxtempl.h

See Also

Reference

CMap Class

Hierarchy Chart

CMap::operator [ ]

Other Resources

CMap Members