CMap::Lookup
查找该值映射到特定键。
BOOL Lookup(
ARG_KEY key,
VALUE& rValue
) const;
参数
ARG_KEY
指定 key 值的类型模板参数。key
指定标识要查找的元素的键。值
指定要搜索的值的类型。rValue
接收所查找的值。
返回值
非零,如果找到该元素;否则为0。
备注
Lookup 使用一个哈希算法快速查找具有完全匹配特定键的键映射元素。
示例
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);
}
要求
Header: afxtempl.h