Boost组件multi_index_container组合查询实例(续3)
来源:互联网 发布:foxtable 连接数据库 编辑:程序博客网 时间:2024/06/06 10:47
本博客http://blog.csdn.net/livelylittlefish 贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
1. 引子
在"组合查询实例(续2)"的基础上,将query_container模板化。这要用到Boost的另一个组件tuple。关于tuple的讨论,可以参考后续的文章。
2. query_container函数模板
typedef boost::tuples::tuple MyTuple_X_T;
typedef boost::tuples::tuple MyTuple_XY_T;
typedef boost::tuples::tuple MyTuple_XYZ_T;
template<typename MultiIndexContainerIterator, typename MultiIndexContainer, typename Tuple>
int query_container(const MultiIndexContainer& container, const Tuple& tuple)
{
MultiIndexContainerIterator it0, it1;
boost::tie(it0, it1) = container.equal_range(tuple);
if (*it0 == *it1)
return -1;
while (it0 != it1)
{
(*it0)->print(", found");
++it0;
}
return 0;
}
3. 代码及运行结果
multiindexcontainer13.cpp
运行结果如下:
(1, 1, 1) - (10, 100)
(1, 1, 2) - (20, 200)
(1, 1, 3) - (30, 300)
(1, 2, 1) - (40, 400)
(1, 2, 2) - (50, 500)
(1, 2, 3) - (60, 600)
(1, 3, 1) - (70, 700)
(1, 3, 2) - (80, 800)
(1, 3, 3) - (90, 900)
(2, 1, 1) - (110, 1000)
(2, 1, 2) - (220, 2000)
(2, 1, 3) - (330, 3000)
(2, 2, 1) - (440, 4000)
(2, 2, 2) - (550, 5000)
(2, 2, 3) - (660, 6000)
(2, 3, 1) - (770, 7000)
(2, 3, 2) - (880, 8000)
(2, 3, 3) - (990, 9000)
//查询索引x=1的所有数据
(1, 2, 1) - (40, 400), found
(1, 2, 2) - (50, 500), found
(1, 2, 3) - (60, 600), found
(1, 1, 1) - (10, 100), found
(1, 1, 2) - (20, 200), found
(1, 1, 3) - (30, 300), found
(1, 3, 1) - (70, 700), found
(1, 3, 2) - (80, 800), found
(1, 3, 3) - (90, 900), found
//查询索引x=2的所有数据
(2, 1, 1) - (110, 1000), found
(2, 1, 2) - (220, 2000), found
(2, 1, 3) - (330, 3000), found
(2, 3, 1) - (770, 7000), found
(2, 3, 2) - (880, 8000), found
(2, 3, 3) - (990, 9000), found
(2, 2, 1) - (440, 4000), found
(2, 2, 2) - (550, 5000), found
(2, 2, 3) - (660, 6000), found
//查询索引x=3的所有数据
(3) - not found
//查询索引的所有数据
(1, 1, 1) - (10, 100), found
(1, 1, 2) - (20, 200), found
(1, 1, 3) - (30, 300), found
//查询索引的所有数据
(1, 2, 1) - (40, 400), found
(1, 2, 2) - (50, 500), found
(1, 2, 3) - (60, 600), found
//查询索引的所有数据
(1, 3, 1) - (70, 700), found
(1, 3, 2) - (80, 800), found
(1, 3, 3) - (90, 900), found
//查询索引的所有数据
(1, 4) - not found
//查询索引的所有数据
(2, 1, 1) - (110, 1000), found
(2, 1, 2) - (220, 2000), found
(2, 1, 3) - (330, 3000), found
//查询索引的所有数据
(2, 2, 1) - (440, 4000), found
(2, 2, 2) - (550, 5000), found
(2, 2, 3) - (660, 6000), found
//查询索引的所有数据
(2, 3, 1) - (770, 7000), found
(2, 3, 2) - (880, 8000), found
(2, 3, 3) - (990, 9000), found
//查询索引的所有数据
(2, 4) - not found
//查询索引~的所有数据
(1, 1, 1) - (10, 100), found
(1, 1, 2) - (20, 200), found
(1, 1, 3) - (30, 300), found
(1, 2, 1) - (40, 400), found
(1, 2, 2) - (50, 500), found
(1, 2, 3) - (60, 600), found
(1, 3, 1) - (70, 700), found
(1, 3, 2) - (80, 800), found
(1, 3, 3) - (90, 900), found
(2, 1, 1) - (110, 1000), found
(2, 1, 2) - (220, 2000), found
(2, 1, 3) - (330, 3000), found
(2, 2, 1) - (440, 4000), found
(2, 2, 2) - (550, 5000), found
(2, 2, 3) - (660, 6000), found
(2, 3, 1) - (770, 7000), found
(2, 3, 2) - (880, 8000), found
(2, 3, 3) - (990, 9000), found
//查询索引等的所有数据
(2, 3, 4) - not found
(3, 3, 3) - not found
//释放container
(1, 2, 1) - (40, 400), destructed
(1, 2, 2) - (50, 500), destructed
(1, 2, 3) - (60, 600), destructed
(1, 1, 1) - (10, 100), destructed
(1, 1, 2) - (20, 200), destructed
(1, 1, 3) - (30, 300), destructed
(1, 3, 1) - (70, 700), destructed
(1, 3, 2) - (80, 800), destructed
(1, 3, 3) - (90, 900), destructed
(2, 1, 1) - (110, 1000), destructed
(2, 1, 2) - (220, 2000), destructed
(2, 1, 3) - (330, 3000), destructed
(2, 3, 1) - (770, 7000), destructed
(2, 3, 2) - (880, 8000), destructed
(2, 3, 3) - (990, 9000), destructed
(2, 2, 1) - (440, 4000), destructed
(2, 2, 2) - (550, 5000), destructed
(2, 2, 3) - (660, 6000), destructed
与"组合查询实例(1)"的结果完全一样。
Technorati 标签: Boost, multi_index, multi_index_container
- Boost组件multi_index_container组合查询实例(续3)
- Boost组件multi_index_container组合查询实例(1)
- Boost组件multi_index_container组合查询实例(续2)
- Boost组件multi_index_container实例(续3)
- Boost组件multi_index_container实例(续2)
- Boost组件multi_index_container实例(续4)
- Boost组件multi_index_container实例(续5)
- Boost组件multi_index_container实例(1)
- Boost组件multi_index_container实例(后续)
- Boost multi_index_container
- 关于boost multi_index_container
- boost multi_index_container 基本介绍
- boost多个关键字索引multi_index_container
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- SKU组合查询算法代码-实例二
- DOS命令说明
- 理解 Linux 配置文件
- Boost组件multi_index_container组合查询实例(续2)
- windows下安装subversion服务并结合apache
- 域环境下的渗透
- Boost组件multi_index_container组合查询实例(续3)
- 关于PHP代码安全性问题的建议
- 建立arm-linux-gcc 4.1.1交叉编译环境
- 为什么大型矩阵乘法要用分块
- MySQL Workbench Connection Failed resolving
- 第一篇博客
- mysql limit 扫描行数 & order by 与索引关系
- myeclipse spket 问题求解
- HASH注入式攻击