我有一个bimap
长度约。280000,我正在搜索这个bimap
值至少 1800 万次。bimap
下面给出了我随身携带的最小示例;
#include <string>
#include <iostream>
#include <utility>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/unordered_multiset_of.hpp>
namespace bimaps = boost::bimaps;
typedef boost::bimap<bimaps::unordered_set_of<unsigned long int>,
bimaps::unordered_multiset_of<unsigned long int > > bimap_reference;
typedef bimap_reference::value_type position;
bimap_reference numbers;
int main()
{
numbers.insert(position(123456, 100000)); // inserting in the bimap
numbers.insert(position(234567, 80000));
numbers.insert(position(345678, 100000));
numbers.insert(position(456789, 80000));
using ritr = bimap_reference::right_const_iterator;
std::pair<ritr, ritr> range = numbers.right.equal_range(80000);
auto itr = range.first;
std::cout<<"first: "<<itr->first<<std::endl;
if(itr != numbers.right.end() && itr->second ==80000){
for (itr = range.first; itr != range.second; ++itr)
{
std::cout<<"numbers:"<<itr->second<<"<->"<<itr->first<<std::endl;
}
}
else {
std::cout<<"Not found:"<<std::endl;
}
return 0;
}
1800万次搜索bimap
大约需要7秒。我想知道如何提高搜索时间。另一个是,我有 unordered_set_of<>
and unordered_multiset_of<>
,这有助于我创建bimap
比使用set_of<>
and更快multiset_of<>
的搜索时间,搜索时间约为。两种情况都一样。我还想将长度扩展bimap
到 1.7 亿,搜索量约为。5亿次。那么,我怎样才能提高搜索时间呢?
unordered_map<>
不是解决方案,因为我想要双向访问。