散列容器(has container)是一种非常重要的容器类型,他内部使用hash 散列表代替二叉树提供更高的访问效率,散列容器是无序的
Boost unordered 库提供两个散列集合类 unordered_set 和 unordered_multiset、unordered_map、unordered_multimap 他们的使用方法接口和用法与STL的关联容器 set/map 相同,但查找的平均复杂度却由O(logN) 变成O(1),查找性更好
#include<boost/unordered_set.hpp>
unordered_set<string> us;
us.inert("aa");
us.inert("aa"); 重复元素无法插入
set、unordered_set 比较 unordered_set 查找性能更好
#include<boost/unordered_set.hpp>
unordered_multiset<string> us;
bimap
#include<boost/bimap.hpp>
map 和multimap都是但映射,只能通过key查找到value,但是实际项目开发中,有时也需要从value找到对应的key,boost的bimap便是这样一种双向映射容器,他要求key,value 都必须唯一
bimap<int,string> bm;
bm.left.insert(make_pair(1,"aaa"));
bm.left.insrt(make_pair(1,"aaaaa)); 无效
bm.right.insert(make_pair("ccc",2))
bm.right.insert(make_pair("ccc",3)) 无效
circluar_buffer
#include<boost/circular_buffer.hpp>
boost 库中的circular_buffer 顾名思义是一个循环缓冲器,其capcity 是固定的,当容器满了以后,插入一个元素时,会在容器的开头后结尾出删除一个元素。
multi_array
#include<boost/multi_array.hpp>
boost库中的multi_array 是一个动态多维数组库,它实现了一个通用,与标准库的容器一直的接口,并且具有与c++ 中内建的多维数组一样的接口和行为
int a = 2;
int b = 3;
int c = 4;
multi_array<int 3> arr(extents[a][b][c])
arr.shape()[0] arr.shape()[1] 获取对应维度的长度
arr.num_elements() 获取元素总个数
arr.resize(extents[4][5][6]) 改变各维度长度
arr.reshape() 改变形状