-1
我想知道如何寫一個bimap
這實際上是一個二進制文件(1.8億到三千萬條目),然後讀取做一些操作。要創建一個bimap
我有以下代碼,我創建了兩個流來寫入和讀取二進制數據。我也將這些元素插入bimap
。寫一個bimap到二進制文件,然後讀取它
#include <string>
#include <iostream>
#include <utility>
#include <fstream>
#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 long int>,
bimaps::unordered_multiset_of<unsigned long long int > > bimap_reference;
typedef bimap_reference::value_type position;
bimap_reference numbers;
int main()
{
std::ofstream outfile ("bmap",std::ofstream::binary);
std::ifstream infile ("bmap",std::ifstream::binary);
numbers.insert(position(123456, 100000));
numbers.insert(position(234567, 80000));
numbers.insert(position(345678, 100000));
numbers.insert(position(456789, 80000));
//want to write the file
//want to read the file
// So that I can perform the following operation
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;
}
我想寫bimap
,然後再讀一遍執行一些操作。怎麼做。
請看['boost :: archive'](http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/archives.html)。 –
使用適當的DBMS創建適當的數據庫。 –
@πάνταῥεῖ謝謝,看看 – AwaitedOne