STL中的哈希表 hash table

哈希表在STL的map库中,用到的两个主要函数为map.count()和map.insert(),分别是查找和插入操作。代码样例如下:

1 include <map>
2 
3 map<int, int> hashtable;
4 if(!hashtable.count(key)) {
5     hashtable.insert(pair<int, int>(key, value));
6 }

插入的时间复杂度为O(1),查找的时间复杂度为O(1)。

posted @ 2015-11-28 13:35  cleverc  阅读(503)  评论(0编辑  收藏  举报