为什么80%的码农都做不了架构师?>>>
hash_map和map的选择,hash_map善于查找,map善于添加和删除,这个没问题,关键是数据:
http://blog.sina.com.cn/s/blog_5378b2830100c5a4.html
关键数据如下:10万级
hash_map(10万) map(10万) hash_map(20万) map(20万) hash_map(30万) map(30万)
添加 93 47 156 94 203 172
遍 历 16 15 16 16 16 15
查找 0 0 32 31 31 32
删除 8422 32 33765 63 76016 78
百万级:
hash_map(100万) map(100万) hash_map(200万) map(200万) hash_map(300万) map(300万)
遍历 94 31 203 32 297 47
查找 94 234 188 531 281 875
如果使用vector的第一个元素,使用front()比operator[0]要更好。
operator[]里面操作比front多太多了.
vector的swap函数也很不错,是把里面所有的东西进行交换,内部实现是:
if (this->_Alval == _Right._Alval){ // same allocator, swap control information#if _HAS_ITERATOR_DEBUGGINGthis->_Swap_all(_Right);#endif /* _HAS_ITERATOR_DEBUGGING */std::swap(_Myfirst, _Right._Myfirst);std::swap(_Mylast, _Right._Mylast);std::swap(_Myend, _Right._Myend);}else{ // different allocator, do multiple assigns_Myt _Ts = *this; *this = _Right, _Right = _Ts;}
原文链接: http://blog.csdn.net/ccanan/article/details/6075416