登录 用户中心() [退出] 后台管理 注册
   
您的位置: 首页 >> CLQ工作室开源代码 >> 主题: c++11 中的 unordered_map 早期替代品 [hash_map]     [回主站]     [分站链接]
标题
c++11 中的 unordered_map 早期替代品 [hash_map]
clq
浏览(262) + 2021-10-02 14:14:05 发表 编辑

关键字:

[2021-10-02 14:42:27 最后更新]
c++11 中的 unordered_map 早期替代品

我很喜欢的 cfree 5 不支持。不过它支持稍早点的 hash_map ,不过写法上也是要注意的。

--------------------------------------------------------
//#include <hash_map>  //不直接支持
//c++11 统一了 hash map 的要求,为了避免与以前冲突,现行标准的 hash map 叫 std::unordered_map
//#include <unordered_map>  //cfree 5 不支持
//#include <hash_map>    //cfree 5 支持的版本
#include <ext/hash_map>    //cfree 5 支持的版本

//c++ 的 hashmap 实现

//老版本的 hash_map
//参考 http://www.voidcn.com/article/p-hvhikujd-px.html
using namespace __gnu_cxx;

//两个整数的 map
void * create_hashmap()
{
    //std::unordered_map<int, int> * map= new std::unordered_map<int , int>();
    hash_map<_int64, _int64> * map = new hash_map<_int64 , _int64>();

    return map;
}//


clq
2021-10-02 14:42:27 发表 编辑

//--------------------------------------------------------
//参考 https://blog.csdn.net/tianwei0822/article/details/82082234
//如果 key 为 string 和 long long 的话,还要自己扩展 hash 函数
//否则 (*map)[key] = v; 这样的操作是会报错的
namespace __gnu_cxx
{
    template<> struct hash< std::string >
    {
        size_t operator()( const std::string& x ) const
        {
            return hash< const char* >()( x.c_str() );
        }
    };
    
    template<> struct hash<long long>
    {
        size_t operator()(long long x) const
        {
            return x;
        }
    };
};

//--------------------------------------------------------


总数:1 页次:1/1 首页 尾页  
总数:1 页次:1/1 首页 尾页  


所在合集/目录



发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:



NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.

Copyright © 2005-2020 clq, All Rights Reserved
版权所有
桂ICP备15002303号-1