C++中有hash_map吗?hash_map和unordered_map

关于hash_map

我们一般都熟悉map,map是C++提供的关联容器,可方便地存取键值对。map底层实现为红黑树,它是一种自平衡的二叉排序树。map中的元素会按照键的值进行“排序”。

更详细的解释:C++STL中map的底层实现和使用

这恰好能满足我们需要对数据进行排序的应用需求,而且足够高效,其查询操作的复杂度是 O(logN) 。但有时候我们可能不需要对数据进行排序,而仅仅是通过key能“快速”获取value,想用更快的hash算法【查询复杂度O(1)】来实现。这个时候就需要hash_map出场了。

 

C++中有hash_map吗?

我抱着试一试的态度,在头文件中包含了hash_map:

#include<hash_map>

编译没有错误,但是编译器弹出了一个警告,如下:

/** @file backward/backward_warning.h
 *  This is an internal header file, included by other library headers.
 *  Do not attempt to use it directly. @headername{iosfwd}
 */

#ifndef _BACKWARD_BACKWARD_WARNING_H
#define _BACKWARD_BACKWARD_WARNING_H 1

#ifdef __DEPRECATED
#warning \
  This file includes at least one deprecated or antiquated header which \
  may be removed without further notice at a future date. Please use a \
  non-deprecated interface with equivalent functionality instead. For a \
  listing of replacement headers and interfaces, consult the file \
  backward_warning.h. To disable this warning use -Wno-deprecated.

/*
  A list of valid replacements is as follows:

  Use:					Instead of:
  <sstream>, basic_stringbuf	   	<strstream>, strstreambuf
  <sstream>, basic_istringstream	<strstream>, istrstream
  <sstream>, basic_ostringstream	<strstream>, ostrstream
  <sstream>, basic_stringstream		<strstream>, strstream
  <unordered_set>, unordered_set     	<ext/hash_set>, hash_set
  <unordered_set>, unordered_multiset	<ext/hash_set>, hash_multiset
  <unordered_map>, unordered_map	<ext/hash_map>, hash_map
  <unordered_map>, unordered_multimap	<ext/hash_map>, hash_multimap
  <functional>, bind			<functional>, binder1st
  <functional>, bind			<functional>, binder2nd
  <functional>, bind			<functional>, bind1st
  <functional>, bind			<functional>, bind2nd
  <memory>, unique_ptr       		<memory>, auto_ptr
*/

#endif

#endif

翻译意思是说:
这是一个内部头文件,包含在其他库头文件中。不要试图直接使用它。
此文件至少包含一个已弃用或过时的头文件,该头文件可能在以后移除,恕不另行通知。请使用具有等效功能的非弃用接口。为了替换头和接口的列表,请参阅文件。

也就是说,在C++11新版本中,hash_map被重新封装,取而代之的是unordered_map。

从给出的列表中还可以看到,hash_set也被unordered_set替换了。还有等等。

 

所以,unordered_map就是之前的hash_map。

unordered_map的具体用法:C++11新特性:STL中的无序关联容器unordered_map的底层实现和用法

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值