`
boisterous
  • 浏览: 62648 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类

stl hash_map

阅读更多
#include  <cstdlib>
#include  <iostream>
#include  <string>
#include  <hash_map.h>/*因为hash_map暂不为CPP标准所以没办法写为<hash_map>*/
/*-------------------------------------------*/
using  std::cout;
using  std::endl;
using  std::string;
/*-------------------------------------------*/
/*函数类
*作为hash_map的hash函数
*string没有默认的hash函数
*/
class str_hash{
      public:
       size_t operator()(const string& str) const
        {
                unsigned long __h = 0;
                for (size_t i = 0 ; i < str.size() ; i ++)
                __h = 5*__h + str[i];
                return size_t(__h);
        }
};
/*-------------------------------------------*/
/*函数类
*作为hash_map的比较函数 )
*(查找的时候不同的key往往可能对用到相同的hash值
*/
class str_compare
{
      public:
             bool operator()(const string& str1,const string& str2)const
             {return   str1==str2;}
};
/*-------------------------------------------*/
int
main(int argc, char *argv[])

    hash_map<string,string,str_hash,str_compare>  myhash;
   
    myhash["google"]="newplan";
  
    myhash["baidu"]="zhaoziming";
  
    if(myhash.find("google")!=myhash.end())
      cout<<myhash["google"]<<endl;
   
    system("PAUSE");
   
    return EXIT_SUCCESS;
}
/*-------------------------------------------*/
分享到:
评论

相关推荐

    hash_map的详解

    关于hash_map的用法与解释: #include &lt;hash_map&gt; #include #include using namespace std; //define the class class ClassA{ public: ClassA(int a):c_a(a){} int getvalue()const { return c_a;} void ...

    hash_map的简单应用

    hash_map

    Hash_map 实现源码

    一个用Hash算法实现的map,可以实际项目所使用。 希望能帮助大家学习。

    STL.zip_Map 排序_STL_Table_stl map实现

    源码之前了无秘密,你将看到vector的实现、list的实现、heap的实现、deque的实现、Red Black tree的实现、hash table的实现、set/map的实现;你将看到各种算法(排序、查找、排列组合、数据移动与复制技术)的实现;你...

    hash_map:C++ STL 哈希映射容器

    STL hash_map: 链式散列 版权所有 (c) 2014,龙 (Ryan) 南宫。 保留所有权利。 邮箱: 创建时间:2014 年 7 月 15 日 这是无序的哈希映射,它具有恒定的插入、删除、搜索时间,并支持向前/向后迭代。 hash_map 的...

    C++中的哈希容器unordered_map使用示例

    很久以来,STL中都只提供&lt;map&gt;作为存放对应关系的容器,内部通常用红黑树实现,据说原因是二叉平衡树(如红黑树)的各种操作,插入、删除、查找等,都是稳定的时间复杂度,即O(log n);但是对于hash表来说,由于无法...

    C++ Perimer Effective

    C++ Perimer 双语版.chm EffectiveC++.chm 中文版 EffectiveSTL.chm 第3版 中文版 Effective C++ & More Effective C++ 英文版.chm STL hash_map 用STL快速编写ini配置文件识别类

    linked_hash:L链式哈希[LRU]用于C ++的快速,仅标头,跨平台和类似STL的linked_hash_map和linked_hash_set。 (在leetcode上击败100%的提交)

    linked_hash测试结果

    数据结构:映射.pdf

    其中m1就是⼀个关联数组,为了模拟普通哈希表 (这⾥的所有的都是⽤红⿊树实现的,如果你想⽤哈希表实现,请直接把map替换成hash_map,在空间⾜够的情况下) 另外,如果有C++11⽤,⼀定要⽤unordered_map,别⽤hash_...

    细讲c++ 各种STL容器的应用场合及性能

    c++ std stl各容器的应用场合及性能 map hash_map unordered_map multimap list forward_list vector set hash_set multiset unsorted_set queue deque priority_queue

    leetcode和oj-leetcode-1-Two-Sum:解决方案

    hash_map(STL) 解决了这个问题,它只请求 O(n) ,但 leetcode 总是说 Compile Error 。 也许他们不支持 STL hash_map。然后我猛烈地尝试了 O(n2) 。 令我惊讶的是,AC.........它们没有显示时间和内存限制以及数据...

    C++ STL 开发技术导引(随书源码)

    【内容简介】 C++ STL标准模板库在数据结构和算法的实践领域发挥着重要的作用。本书共分5篇26章,以“C++编程技术→C++ STL泛化技术基础→C++ STL容器技术→C++ STL算法技术→C++ STL...第16章 hash_map哈希映照容器

    C++ STL开发技术导引(第5章)

    第16章 hash_map哈希映照容器 235 16.1 hash_map技术原理 235 16.2 hash_map应用基础 237 16.3 本章小结 242 第17章 string基本字符序列容器 243 17.1 string技术原理 243 17.2 string应用基础 258 ...

    STL源码剖析_Table_stlmemory_c++prim_vector_

    STL源码剖析,这本书所呈现的源码,使读者看到vector的实现、list的实现、heap的实现、deque的实现、Red Black tree的实现、hash table的实现、set/map的实现;看到各种算法(排序、查找、排列组合、数据移动与复制...

    C++ STL 开发技术导引(第6章)

    第16章 hash_map哈希映照容器 235 16.1 hash_map技术原理 235 16.2 hash_map应用基础 237 16.3 本章小结 242 第17章 string基本字符序列容器 243 17.1 string技术原理 243 17.2 string应用基础 258 ...

    STL.源码剖析_____________

    源码之前了无秘密,你将看到vector的实现、list的实现、heap的实现、deque的实现、RB-tree的实现、hash-table的实现、set/map 的实现;你将看到各种算法(排序、搜寻、排列组合、数据移动与复制…)的实现;你甚至将...

    C++ STL开发技术导引(第3章)

    第16章 hash_map哈希映照容器 235 16.1 hash_map技术原理 235 16.2 hash_map应用基础 237 16.3 本章小结 242 第17章 string基本字符序列容器 243 17.1 string技术原理 243 17.2 string应用基础 258 ...

    robin-hood-hashing:基于C ++ 11141720的基于robin hood哈希的快速且内存高效的哈希表

    robin_hood::unordered_map和robin_hood::unordered_set是std::unordered_map / std::unordered_set独立于平台的替代品,对于实际的用例而言,它既更快,更高效。 安装及使用 直接纳入 将添加到您的C ++项目。 ...

    STL源码剖析.pdg

    5.9 hash_map 275 5.10 hash_multiset 279 5.11 hash_multimap 282 第6章 算法(algorithms) 285 6.1 算法概观 285 6.1.1 算法分析与复杂度表示 o( ) 286 6.1.2 stl算法总览 288 6.1.3 mutating algorithms ...

    LightSTL:STL的子集和超集

    iterator(100%)空间配置器(100%)functor(70%)vector(100%)list(100%)queue(100%)priority_queue(100%)stack(100%)pair(100%)string(100%)hash_table(100%)hash_map(100%)算法库fill(100%)fill_n(100%)copy(100%)copy...

Global site tag (gtag.js) - Google Analytics