#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;
}
/*-------------------------------------------*/
#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;
}
/*-------------------------------------------*/
发表评论
-
crond需要重启么?
2011-06-11 12:20 1222今天一同事说把A机器的/var/spool/cron/admi ... -
GDB信号的处理和启动配置文件(转载)
2011-05-22 21:57 2203信号的处理 程序是和网络相关的,调试期间经常地收到SIGPIP ... -
信号量基础知识
2011-05-10 18:40 984linux 中信号相关的一个结构体 struct sigact ... -
asprintf
2011-05-08 21:49 2325sprintf() 的整个介面长的样子的是: int ... -
获取用户输入的问题(清除stdin)
2011-05-08 21:37 1906需求: 从终端获取用户输入的用户名和密码(有效 ... -
Linux下的UDP/TCP端口映射(netcat and socat)
2011-05-07 20:42 9664说起来有点土,事到如今 ... -
linux任务管理
2011-05-07 20:32 679disown是bash内部命令,nohup是外部命令 diso ... -
boost multi_index_container
2011-04-27 21:18 1524本章介绍的主题是multi_i ... -
变量相关命令(env,export,set,read, array, declare
2011-04-26 21:38 1001系统的预设参数文件:/ ... -
stl priority_queue
2011-04-26 21:20 601简单的使用示例。 view plaincopy to cli ... -
linux backlog
2011-04-25 15:13 1491在linux中,/proc/sys/net/core/so ... -
linux backlog
2011-04-25 15:13 730在linux中,/proc/sys/net/core/so ... -
linux串口登陆
2011-04-23 09:31 1478在这个互连网高速发展的时代, 企业内网络设备的安全和运行稳定也 ... -
linux rename
2011-04-21 09:38 707Linux中rename命令的用法 刚学习linux的时候, ... -
stl heap
2011-04-17 10:01 767make_heap 原型: #include <a ... -
expand and upexpand
2011-04-09 13:33 707expand: NAME expand - co ... -
内核模块相关命令:lsmod,depmod,modprobe
2011-03-28 13:24 1108lsmod 功能:列出内核已载入模块的状态 用法:lsmod ... -
通过先unlink()后close()创建安全的临时文件
2011-03-15 14:26 883使用POSIX(Portable Operating Syst ... -
parted操作磁盘
2011-03-12 16:15 807除了fdisk命令,在linux下还有一个功能也非常强大的磁盘 ... -
linux写缓存调优
2011-03-11 09:34 2002我们在磁盘写操作持续 ...
相关推荐
关于hash_map的用法与解释: #include <hash_map> #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,可以实际项目所使用。 希望能帮助大家学习。
源码之前了无秘密,你将看到vector的实现、list的实现、heap的实现、deque的实现、Red Black tree的实现、hash table的实现、set/map的实现;你将看到各种算法(排序、查找、排列组合、数据移动与复制技术)的实现;你...
STL hash_map: 链式散列 版权所有 (c) 2014,龙 (Ryan) 南宫。 保留所有权利。 邮箱: 创建时间:2014 年 7 月 15 日 这是无序的哈希映射,它具有恒定的插入、删除、搜索时间,并支持向前/向后迭代。 hash_map 的...
很久以来,STL中都只提供<map>作为存放对应关系的容器,内部通常用红黑树实现,据说原因是二叉平衡树(如红黑树)的各种操作,插入、删除、查找等,都是稳定的时间复杂度,即O(log n);但是对于hash表来说,由于无法...
C++ Perimer 双语版.chm EffectiveC++.chm 中文版 EffectiveSTL.chm 第3版 中文版 Effective C++ & More Effective C++ 英文版.chm STL hash_map 用STL快速编写ini配置文件识别类
linked_hash测试结果
其中m1就是⼀个关联数组,为了模拟普通哈希表 (这⾥的所有的都是⽤红⿊树实现的,如果你想⽤哈希表实现,请直接把map替换成hash_map,在空间⾜够的情况下) 另外,如果有C++11⽤,⼀定要⽤unordered_map,别⽤hash_...
c++ std stl各容器的应用场合及性能 map hash_map unordered_map multimap list forward_list vector set hash_set multiset unsorted_set queue deque priority_queue
hash_map(STL) 解决了这个问题,它只请求 O(n) ,但 leetcode 总是说 Compile Error 。 也许他们不支持 STL hash_map。然后我猛烈地尝试了 O(n2) 。 令我惊讶的是,AC.........它们没有显示时间和内存限制以及数据...
【内容简介】 C++ STL标准模板库在数据结构和算法的实践领域发挥着重要的作用。本书共分5篇26章,以“C++编程技术→C++ STL泛化技术基础→C++ STL容器技术→C++ STL算法技术→C++ STL...第16章 hash_map哈希映照容器
第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的实现、Red Black tree的实现、hash table的实现、set/map的实现;看到各种算法(排序、查找、排列组合、数据移动与复制...
第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 ...
源码之前了无秘密,你将看到vector的实现、list的实现、heap的实现、deque的实现、RB-tree的实现、hash-table的实现、set/map 的实现;你将看到各种算法(排序、搜寻、排列组合、数据移动与复制…)的实现;你甚至将...
第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::unordered_map和robin_hood::unordered_set是std::unordered_map / std::unordered_set独立于平台的替代品,对于实际的用例而言,它既更快,更高效。 安装及使用 直接纳入 将添加到您的C ++项目。 ...
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 ...
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...