MAP--复杂map结构的构造
我的关键结构比如
struct{
int a;
int b;
int c;
}s;
因为这三个数据是基本信息,可以唯一区别一个设备。拿这样一个数据结构作为索引就能找到每个设备。
我现在想这么用
map<s, string>
因为map是二叉树,好像没法拿结构体比较大小,去索引,所以把结构体s改成类,重载小于号,让他能比较大小。
class s
{
public:
int a;
int b;
int c;
s(int m, int d, int u){a=m;b=d;c=u;}
bool operator < (const s &other)
{
if ((a<other.a) ||
((a==other.a)&&(b<other.b)) ||
((a==other.a)&&(b==other.b)&&(c<other.c)))
{
return true;
}
return false;
}
};
然后,
map<s, string> w;
s s1;
string s2;
一旦执行w.insert(make_pair(s1, s2));只要有这行就立刻报错。
要想使用一个类似结构体的数据结构作为KEY到底要怎么做呀?
是不是光重载一个小于号不够呀?
我现在好糊涂。有没有简单办法?
1.1
struct s {
int a;
int b;
int c;
bool operator<(const s&) const {
return true; }
};
map<s,string> m;
m.insert( make_pair(s(),"") );
1.2
struct s {
int a;
int b;
int c;
};
bool operator<(const s&,const s&) { return true; }
map<s,string> m;
m.insert( make_pair(s(),"") );
2.
struct s {
int a;
int b;
int c;
};
struct cmp {
bool operator()(const s&,const s&) const { return true; }
};
map<s,string,cmp> m;
m.insert(make_pair(s(),"" ) );
转载自:http://bbs.chinaunix.net/thread-1538318-1-1.html
MAP--复杂map结构的构造的更多相关文章
- STL——容器(Map & multimap)的拷贝构造与赋值
1. Map & multimap 的拷贝构造与赋值 map(const map &mp); //拷贝构造函数 map& operator=(con ...
- Map接口----Map中嵌套Map
package cn.good.com; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...
- 加锁的位置 (eq:map<key,map<>> 双集合 怎么 只加锁 在用到的对象位置,而不是把整个集合锁住)
比如上边的map里套map 定义变量为data,例如组队副本 npc 为1 下有众多房间 即Map<1,<roomId,room>> ,处于多线程下,一个线程在 npc为1的下 ...
- 2019/2/20训练日记+map/multi map浅谈
Most crossword puzzle fans are used to anagrams - groups of words with the same letters in different ...
- LinkedHashSet、Map、Map接口HashMap、Hashtable,TreeSet、TreeMap、如何选择使用集合实现类,Collections工具类
一.Set接口实现类LinkedHashSet 实现继承图: 1.LinkedHashSet的全面说明 1) LinkedHashSet是 HashSet的子类 2) LinkedHashSet底层是 ...
- Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象
Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象 package org.rui.collection2.map; /** * ...
- java中遍历MAP,嵌套map的几种方法
java中遍历MAP的几种方法 Map<String,String> map=new HashMap<String,String>(); map.put("us ...
- arm-none-eabi-g++ -Xlinker -T "../LF3Kmonitor.ld" -Xlinker -Map="Bogota_ICT_V.map"-ram-hosted.ld -mc
1.arm-none-eabi-g++:是编译ARM裸板用的编译器,不依赖于操作系统. 2.-Xlinker -T "../LF3Kmonitor.ld" -Xlinker -Ma ...
- 03-封装BeanUtil工具类(javabean转map和map转javabean对象)
package com.oa.test; import java.beans.BeanInfo; import java.beans.IntrospectionException; import ja ...
- map泛型 map不指定泛型 与 Map<Object,Object>的区别
map泛型 map不指定泛型 与 Map<Object,Object>的区别 private void viewDetail(){ Map map1 = new HashMap(); Ma ...
随机推荐
- wpf CollectionViewSource与ListBox的折叠、分组显示,及输入关键字 Filter的筛选
在wpf中虽然ObservableCollection<T>作为ListBox的Itemsource,很好,很强大!但是CollectionViewSource与ListBox才是天作之合 ...
- git 使用系列(二)---- 分支和合并
Branching and Merging The Git feature that really makes it stand apart from nearly every other SCM o ...
- Haproxy的安装和配置示例
1.ha proxy简介ha proxy是一个开源的,高性能的,基于tcp第四层和http第七层应用的负载均衡软件优点:可靠性和稳定性非常好 最高可以同时维护40000-50000个 ...
- OpenGL ES之glUniform函数
函数名: glUniform 功能: 为当前程序对象指定Uniform变量的值.(译者注:注意,由于OpenGL ES由C语言编写,但是C语言不支持函数的重载,所以会有很多名字相同后缀不同的函数版本存 ...
- HDU 5455 Fang Fang 水题,但题意描述有问题
题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路: ...
- UVA 571 Jugs ADD18 小白书10 数学Part1 专题
只能往一个方向倒,如c1=3,c2=5,a b从0 0->0 5->3 2->0 2->2 0->2 5->3 4->0 4->3 1->0 1- ...
- Python 3.5.1 Syntax & APIs(Continue Updating..
print(x, end=' ') instead of print(x) to escape the default line-changing-output. print(str.ljust(si ...
- 判断Android应用是否安装、运行
本文介绍3个方法,判断手机上是否安装了某应用.该应用是否正在运行.获取手机某个APK文件的安装Intent.启动该Intent就可以直接安装该APK. /** * 判断应用是否已安装 * * @par ...
- Theos tweak MSHookFunction
#import "substrate.h" static FILE * (*s_orig_fopen) ( const char * filename, const char * ...
- elasticsearch 使用事项
template的使用 刚开始的时候,每次实验都去改/etc/elasticsearch/elasticsearch.yml配置文件.事实上在template里修改settings更方便而且灵活!当 ...