I have a bimap
of length approx. 280000, and I am searching this bimap
for atleast 18 million times for a value. The minimal example of the bimap
that I have with me is given below;
#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;
}
The searching of bimap
18 million times takes about 7 seconds. I would like to know how to improve the searching time.
The other is, I have unordered_set_of<>
and unordered_multiset_of<>
, which helps me to create the bimap
faster than If I use set_of<>
and multiset_of<>
, the search time is approx. same with both the cases. I also want to extend the length of the bimap
to 170 million and searching will be be approx. 500 million times. So, how can I improve the search time?.
unordered_map<>
is not the solution because I want bidirectional access.