2

私は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;
}

bimap1800万回の検索には約7秒かかります。検索時間を改善する方法を知りたいです。もう 1 つは、 と が unordered_set_of<>あるため、とを使用する場合よりも高速unordered_multiset_of<>に作成でき、検索時間は約 1 秒です。どちらの場合も同じです。また、長さを1 億 7000 万まで延長したいと考えています。5億回。では、検索時間を改善するにはどうすればよいでしょうか。bimapset_of<>multiset_of<>bimap

unordered_map<>双方向アクセスが必要なため、解決策ではありません。

4

0 に答える 0