boost::multi_index 多索引容器
#include "stdafx.h"
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/ordered_index.hpp>
using namespace std;
using namespace boost;
/*
定义一个MutiStruct
key : 1. objectID
2. strName value: 对象指针STNodePtr
*/
struct MutiStruct
{
int objectID;//唯一
string strName;//唯一 STNodePtr ptrNode;//设备对象指针
}; /*
定义容器,索引
*/
using MutiContainer = boost::multi_index::multi_index_container <
MutiStruct,
boost::multi_index::indexed_by <
boost::multi_index::ordered_unique<boost::multi_index::member<MutiStruct, int, &MutiStruct::objectID>>,
boost::multi_index::ordered_unique<boost::multi_index::member<MutiStruct, string, &MutiStruct::strName>>
>
>; /*
有多少个key,就定义多少个枚举,
0:表示以第一个索引作为key。
1:表示以第二个索引作为key。
*/
enum
{
KEY_1_VIEW = ,
KEY_2_VIEW =
};
using MI_OBJ_IDX = MutiContainer::nth_index<KEY_1_VIEW>::type;
using MI_NAME_IDX = MutiContainer::nth_index<KEY_2_VIEW>::type;
/*插入数据到容器*/
MutiContainer Conter; MutiStruct mi;
mi.objectID = ;
mi.strName = "nihao"; std::pair<MutiContainer::iterator, bool> p = Conter.insert(mi);
if (!p.second)
{
printf("insert fail \n");
}
boost::multi_index 多索引容器的更多相关文章
- boost multi_index
/** boost 多索引容器的一般使用 这里使用google 的gmock 库来验证对boost 多索引模板的使用,并验证. 这里是手敲的,可能会有一些字符敲错的情况,编译错误的放,修改一下,同时链 ...
- 用 boost::multi_index 管理玩家
用 boost::multi_index 管理玩家(金庆的专栏)网游服务器上的玩家集合需要多种索引:如用ID查找,角色名查找, 用登录时分配的会话ID查找.用boost::multi_index进行玩 ...
- multi_index_container 多索引容器
multi_index_container是c++ boost库中的一个多索引的容器.因工作中用到了,特来测试试用. #include "stdafx.h" #include &q ...
- 使用boost::multi_index高速构建排行榜
使用boost::multi_index高速构建排行榜 前几天在boost的maillist上看到boost::multi_index将要支持ranked_index(邮件内容见附件2),这实乃我等苦 ...
- boost::multi_index 提供一种千人在线即时排行榜的设计思路
原文地址: http://www.limerence2017.com/2019/06/23/cpp01/ 做游戏或金融后台开发,经常会遇到设计开发排行榜的需求.比如玩家的充值排行,战力排行等等.而这种 ...
- boost multi_index 插入返回值
boost multi_index 对象插入函数emplace() 的返回值,是一个std::pair<iterator, bool>该pair 的first 是一个插入成功的位置,第二个 ...
- boost multi_index简单了解
#include <string> #include <iostream> #include <boost/multi_index_container.hpp> # ...
- boost之数据结构和容器
1.静态数组array,boost对静态数组进行了封装,使用和普通数组一样的初始化式进行初始化. #include <iostream> #include <boost/array. ...
- BFS/DFS算法介绍与实现(转)
广度优先搜索(Breadth-First-Search)和深度优先搜索(Deep-First-Search)是搜索策略中最经常用到的两种方法,特别常用于图的搜索.其中有很多的算法都用到了这两种思想,比 ...
随机推荐
- Qt插件热加载-QPluginLoader实现
上一篇C++消息框架-基于sigslot文章中我们讲述了使用sigslot信号槽实现自己的消息框架,这是一个比较粗糙,而且小的框架.当我们的程序逐渐变大时,我们可能就会考虑功能插件化,或者支持某些模块 ...
- 使用spring拦截器实现日志管理
使用HandlerInterceptor拦截器,可以拦截请求,实现通用的日志管理操作 一.添加拦截器类 在"src/main/java"代码文件夹的"org.xs.dem ...
- Hadoop 之 HDFS基本概念
1.HDFS的基本概念 答:块(Block).NameNode.DataNode.HDFS的文件被分成块进行存储,默认块的大小为64M,所以说块是文件存储和处理的逻辑单元.NameNode是管理节点, ...
- [Leetcode] 第338题 比特位计数
一.题目描述 给定一个非负整数 num.对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回. 示例 1: 输入: 2 输出: [0,1,1] 示例 ...
- 转:LinkedHashMap和HashMap的比较使用
import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.uti ...
- Python 为什么要保留显式的 self ?
花下猫语:前两天,我偶然在一个知识星球(刘欣老师的"码农翻身")里看到一篇主题,刘老师表示 Python 的类方法非要带个 self,而不像其它语言那样隐藏起来,这让人很不爽.我对 ...
- java架构之路-(分布式zookeeper)zookeeper集群配置和选举机制详解
上次博客我们说了一下zookeeper的配置文件,以及命令的使用https://www.cnblogs.com/cxiaocai/p/11597465.html.我们这次来说一下我们的zookeepe ...
- 基于操作系统原理的Linux的内存管理
一.实验目的 1.理解虚拟内存.磁盘缓存的概念. 2.掌握基本的内存管理知识. 3.掌握查看实时查看内存.内存回收的方法 二.实验内容 1. 监控内存使用情况 2. 检查和回收内容 三.实验平台 1. ...
- C++——数组与字符串
目录 一.数组 1.1定义与初始化 1.1.1使用 1.1.2存储 1.1.3初始化 1.2作函数参数 1.3对象数组 1.3.1定义与访问 1.3.2初始化 1.3.3数组元素所属类的构造函数 二. ...
- NAT网络下tcp_tw_recycle参数引起的故障
记录一次阿里云服务器故障排查思路 公司网络是nat 环境 问题: 同一个服务有两台服务器 172.19.19.252 172.19.19.187 两台服务器 要连node5 发现172.19.19.2 ...