今天想查一下c++ hashmap的使用方法,搜出来的一些文章实在辣眼睛,竟然很多都混淆了c++中map和hashmap的区别。
首先,c++ 标准库的
O(logN)。
而c++ 标准库的hashmap其实叫作
O(1)。它提供了类似map的方法。在c++11下直接使用头文件
当然有人可能会说其实c++有个叫作hash_map的库,但那不是标准库,引用一个stackoverflow的评论来告诉你如何取舍:
@ShameelMohamed, 2017, i.e. 6 years after C++11 it should be hard to find an STL that doesn’t provide unordered_map. Thus, there is no reason to consider the non-standard hash_map. – maxschlepzig Feb 13 '17 at 10:42
参考:What is the best way to use a HashMap in C++?