高效的遍历cmap中的元素方法
2017-07-02 09:02
169 查看
我看师兄的代码 是直接从0 一直循环到m_nHashTableSize,cmap里面实现代码removeall也是这样循环的,但是如果m_nHashTableSize为几十万的数值,而里面存储的元素只有几十个的话,感觉效率不高。有没有其他的高效方法遍历cmap中的所有元素?
本文地址 :CodeGo.net/6122382/
-------------------------------------------------------------------------------------------------------------------------
1.MFC的CMap ?
GetStartPosition + GetNextAssoc 遍历
MSDN上的例子
本文标题 :有没有高效的遍历cmap中的元素方法?
本文地址 :CodeGo.net/6122382/
本文地址 :CodeGo.net/6122382/
-------------------------------------------------------------------------------------------------------------------------
1.MFC的CMap ?
GetStartPosition + GetNextAssoc 遍历
MSDN上的例子
CMap<int, int, CPoint, CPoint> myMap; // Add 10 elements to the map. for (int i = 0; i < 10; i++) myMap.SetAt(i, CPoint(i, i)); // Remove the elements with even key values. POSITION pos = myMap.GetStartPosition(); int nKey; CPoint pt; while (pos != NULL) { myMap.GetNextAssoc(pos, nKey, pt); if ((nKey % 2) == 0) myMap.RemoveKey(nKey); } // Print the element values. pos = myMap.GetStartPosition(); while (pos != NULL) { myMap.GetNextAssoc(pos, nKey, pt); _tprintf_s(_T("Current key value at %d: %d,%d\n"), nKey, pt.x, pt.y); }
本文标题 :有没有高效的遍历cmap中的元素方法?
本文地址 :CodeGo.net/6122382/
相关文章推荐
- 遍历map中的元素的几种方法
- STL中用erase()方法遍历删除元素
- 动态创建dom元素、获取dom元素的属性及遍历dom元素的方法
- Java如何遍历Map的所有的元素(各种方法)
- 遍历集合元素的两种方法
- AJAX 学习笔记(5) 处理XML文档的DOM元素属性和遍历DOM元素方法
- JAVASCRIPT的一些属性和方法的记录 基本都是适合IE的 遍历元素
- STL中用erase()方法遍历删除元素
- 遍历Linux kernel的链表时删除元素的方法
- C#不使用Split()方法,遍历数组,使用“|”分割元素并输出
- STL中用erase()方法遍历删除元素
- STL中用erase()方法遍历删除元素【容易出错】
- STL中用erase()方法遍历删除元素
- STL中用erase()方法遍历删除元素
- STL中用erase()方法遍历删除元素
- stl map高效遍历删除的方法
- STL中用erase()方法遍历删除元素
- STL中用erase()方法遍历删除元素
- STL中用erase()方法遍历删除元素
- C#不使用Split()方法,遍历数组,使用“|”分割元素并输出