map和hash_map的区别

111 阅读1分钟

1、STL的map底层是用红黑树(RB Tree)实现的,查找时间复杂度是log(n),而hash_map底层是用hash表存储的,查询时间复杂度是O(1)

2、hash_map比map查找速度更快。

3、linux c的使用方法

#include <map> //map

using namespace std;//make_pair需要

#include <hash_map>

using namespace __gnu_cxx;//hash_map是声明在__gnu_cxx命名空间的\

\

typedef hash_map<int, CNet_TCPConn*> TCPConnMap_t;\

TCPConnMap_t m_map;\