unorder_map 自定义KEY
1. boost::unorder_map 实现自定义KEY
// boostLibTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h" #include <boost/functional/hash.hpp>
#include <boost/unordered_map.hpp>
#include <iostream>
#include <set>
#include <map>
#include <unordered_map> using namespace std; struct Test
{
int _id;
string _name;
set<int> _nums; Test(int id, string name, set<int> nums = set<int>()) :
_id(id), _name(name), _nums(nums)
{
}
}; bool operator==(const Test& ts1, const Test& ts2)
{
return ts1._id == ts2._id && ts1._name == ts2._name && ts1._nums == ts2._nums;
} size_t hash_value(const Test& test)
{
std::size_t seed = ;
boost::hash_combine(seed, std::hash_value(test._id));
boost::hash_combine(seed, std::hash_value(test._name));
for (auto& iter : test._nums){
boost::hash_combine(seed, std::hash_value(iter));
}
return seed;
} int _tmain(int argc, _TCHAR* argv[])
{
set<int> sets = {,,,,};
boost::unordered_map<Test, string> map;
map.insert(make_pair(Test(, "abc", sets), ""));
map.insert(make_pair(Test(, "def", sets), ""));
map.insert(make_pair(Test(, "egh", sets), ""));
map.insert(make_pair(Test(, "ijk", sets), ""));
map.insert(make_pair(Test(, "lmn", sets), "")); auto iter = map.find(Test(, "egh", sets));
if (iter != map.end()){
cout << "Find !" << endl;
}
else{
cout << "Not Find !" << endl;
} getchar();
return ;
}
输出结果为: Find !
===============================================================
2. std::unorder_map 实现自定义KEY
// boostLibTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h" #include <boost/functional/hash.hpp>
#include <boost/unordered_map.hpp>
#include <iostream>
#include <set>
#include <map>
#include <unordered_map> using namespace std; struct Test
{
int _id;
string _name;
set<int> _nums; Test(int id, string name, set<int> nums = set<int>()) :
_id(id), _name(name), _nums(nums)
{
}
}; namespace std
{
template<>
struct hash<Test>
: public _Bitwise_hash < Test >
{ // hash functor for RECT
}; inline bool operator == (const Test &ts1, const Test &ts2) _NOEXCEPT
{
return ts1._id == ts2._id && ts1._name == ts2._name && ts1._nums == ts2._nums;
}
} int _tmain(int argc, _TCHAR* argv[])
{
set<int> sets = {,,,,};
std::unordered_map<Test, string> map;
map.insert(make_pair(Test(, "abc", sets), ""));
map.insert(make_pair(Test(, "def", sets), ""));
map.insert(make_pair(Test(, "egh", sets), ""));
map.insert(make_pair(Test(, "ijk", sets), ""));
map.insert(make_pair(Test(, "lmn", sets), "")); auto iter = map.find(Test(, "egh", sets));
if (iter != map.end()){
cout << "Find !" << endl;
}
else{
cout << "Not Find !" << endl;
} getchar();
return ;
}
奇怪的地方来了,std的结果有时候是 Find ! 有时候是 Not Find !
没弄明白这个std::unorder_map怎么回事,我自己直接用了boost::unorder_map
unorder_map 自定义KEY的更多相关文章
- zabbix自定义key
zabbix自定义key 1.修改客户端配置文件 #vi /opt/zabbix/etc/zabbix_agentd.conf Include=/opt/zabbix/etc/zabbix_agent ...
- 自学Zabbix3.5.5-监控项item-User parameters(自定义key)
为什么要自定义KEY,即User parameters功能 有时候我们想让被监控端执行一个zabbix没有预定义的检测,zabbix的用户自定义参数功能提供了这个方法.我们可以在客户端配置文件zabb ...
- Zabbix常用key和自定义key的讲解
zabbix中常用到的几个key: 1.监控端口的:net.tcp.port[,3306],可以在服务器端对被监控端测试. /usr/local/zabbix/bin/ -s192.168.8.120 ...
- zabbix使用自定义key进行监控
我的zabbix-server是安装在另一台虚拟机上的,用来监控下图中的这台虚拟机 先修改zabbix的客户端配置文件,增加UserParameter那行,这里我只是用来测试,所以就随便起了一个名为p ...
- zabbix 通过自定义key完成网卡监控
创建执行脚本: # cat /etc/zabbix/monitor_scripts/network.sh #!/bin/bash #set -x usage() { echo "Useage ...
- zabbix 自定义 key (转)
转自:http://www.cnblogs.com/miclesvic/p/6164303.html 1.在zabbix_agent端zabbix_agentd.conf配置文件中增加自定义Key(/ ...
- 监控服务器cpu、磁盘、模板以及自定义key
一.检测主机存活 net.tcp.service.perf[tcp,,] Float型 返回0代表端口挂了 zabbix fping要开启sudo权限之类比较不方便 二.监控CPU负载 监控load ...
- Zabbix 自定义Key
系统:Linux Centos 7.4 x64.Windos 2008 x64 服务:Zabbix 3.0.16 说明1:自定义Key 主要通过自定义 脚本 或者 命令 来实现自定义监控类型,需要在a ...
- zabbix主动模式,自定义Key监控 zabbix采集器
主动模式不是只能用模板提供的标准检测器方式 zabbix-agent两种运行方式即主动模式和被动模式.默认被动模式. 两种模式是相对 客户端 角度来说的. 被动模式:等待server来取数据,可以使用 ...
随机推荐
- nginx环境搭建
nginx安装步骤 安装nginx[root@insure opt]# yum install nginx启动nginx [root@insure opt]# service nginx start ...
- Robust Real-time Object Detection学习
健壮实时对象检测(robust real-time object detection) 高检测率(high detection rates), 一种新的图像表示方法,叫做积分图(integral im ...
- ESP32 I2S
I2S支持DMA; I2S可以直接利用DAC来输出模拟信号 (GPIO 25 & GPIO 26): 高精度时钟使能参数: .use_apll = true ESP32配置外设一般都是配置 ...
- python:python之禅
最近在学python,今晚看了一个名叫“python全栈之路系列”的关于python的相关博客,其中开篇就说到了python的设计哲学:优雅,简洁... 可以在编译器里面输入如下语句来查看python ...
- 简单的策略模式Strategy演示
策略模式,即规则在变化之中,结果终归为一. 公司给员工计算工资,如有加班费,差旅费,每个月的生活补帖等等其它费用需要计算.这个费的规则是不尽相同. 不管策略的规则怎样,终归需要计算出一个结果 工资: ...
- 使用IE浏览提示:该页面无法显示
问题描述: 我们有一个外部招聘的网站,DBA反馈新版上线过后首页集成的登录部分页面无法打开,一直显示“该页面无法显示”! 问题排查: 1.因为我本身也不是负责这一块的业务,刚开始以为是网站本身程序的问 ...
- SpringMVC环境搭建——HelloWorld
1.新建Maven Web 工程: 2.添加相关的依赖包(Spring MVC.tomcat插件等),具体的pom.xml文件如下 <project xmlns="http://mav ...
- git 配置别名
对于常用的git的命令,可以通过配置别名的方式,提高工作效率. $ git config --global alias.co checkout //执行git co 相当于git checkout $ ...
- 2-Twenty Fourth Scrum Meeting-20151230
前言 因为服务器关闭,我们的开发项目也遭遇停滞一个星期.与网站开发负责人员协商之后,29号开放服务器.我们的项目也能够继续下去.比规定的开发时间(截止为2015/12/29)推迟. 事项安排 1.开发 ...
- 探索guava(一)——前置条件Preconditions类
作用 可以简洁的完成参数检验,在进行业务逻辑代码前进行前置判断.并且避免了冗长的if语句.guava将所有检验的API都放置于Preconditions类中. API Preconditions类大致 ...