本文整理汇总了C++中unordered_multimap::rehash方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_multimap::rehash方法的具体用法?C++ unordered_multimap::rehash怎么用?C++ unordered_multimap::rehash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_multimap
的用法示例。
在下文中一共展示了unordered_multimap::rehash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode
/*
Encode to diff
*/
int encode( _TCHAR* noldfile, _TCHAR* nnewfile, _TCHAR* ndifffile){
ifstream oldfile(noldfile,ios::binary);
ifstream newfile(nnewfile,ios::binary);
ofstream difffile(ndifffile,ios::binary);
if(!oldfile || !newfile || !difffile)return -1;
oldfile.seekg(0,oldfile.end);
int64_t oldlen=oldfile.tellg().seekpos();
oldfile.seekg(0,oldfile.beg);
cerr<<"Original file length:"<<oldlen<<endl;
//Index the old file
{
//if(oldlen>20*1024*1024)oldlen=20*1024*1024;
int bs=max_bs;
int bsb=1<<bs;
size_t reserve=(size_t)(oldlen/bsb)*4;
//cout<<"reserve for "<<reserve<<endl;
hashes.rehash(reserve);
const int blocksize=5*1024*1024;
byte* oldbuf=new byte[blocksize];
int64_t read=0;
while(read<oldlen){
int64_t left=oldlen-read;
int toread=(int)min(blocksize,left);
oldfile.read((char*)oldbuf,toread);
/*if(read==0){
memcpy(back,&oldbuf[0xa92000],0x1000);
}*/
int toread_aligned=(toread+(1<<max_bs)-1)/(1<<max_bs)*(1<<max_bs);
//padding 0
for(int i=toread;i<toread_aligned;++i){
oldbuf[i]=0;
}
MakeAdler32Index(oldbuf,toread_aligned,read);
read+=toread;
double per=read*100.0/oldlen;
char buf[1024];
sprintf_s(buf,"\rIndexing ... %2.4lf%% [%.0lf/%.0lf]",per,(double)read,(double)oldlen);
cerr<<buf;
}
delete[] oldbuf;
cerr<<'\n';
}
//Scan the new file,
newfile.seekg(0,newfile.end);
int64_t newlen=newfile.tellg().seekpos();
newfile.seekg(0,newfile.beg);
int64_t newlen_aligned=(newlen+(int64_t)(1<<max_bs)-(int64_t)1)/(1<<max_bs)*(1<<max_bs);
if(!Coder::writeinit(newlen)){
cerr<<"Failed to write init!"<<endl;
return -1;
}
function<void()> threadf=[&](){
CompressInc(Coder::pipe,&difffile);
};
thread compresst(threadf);
//newlen=newlen_aligned=3u*1024u*1024u*1024u;
//will roll back, but will aligned to 4 bytes, so it's OK
Scan([&](byte* data,int64_t start,offset_t len,offset_t bufsize)->offset_t{
char buf[1024];
sprintf_s(buf,"\nScanning ... P: %2.4lf%%[%.0lfK/%.0lfK] C:%2.4lf%% O:%.0lfK"
,(double)start*100.0/(double)newlen,(double)start/1024.0,(double)newlen/1024.0
,(double)size_uncompressed*100.0/((double)start+1),(double)size_compressed/1024.0
);
cerr<<buf;
size_t toread=(int32_t)min(len,(newlen-start));
{
int s0=start%bufsize;
int e0=(s0+toread)%bufsize;
if(e0>s0){
newfile.read((char*)data+s0,e0-s0);
}else{
newfile.read((char*)data+s0,bufsize-s0);
newfile.read((char*)data,e0);
}
}
//padding 0
if(toread<len){
int s1=(start+toread)%bufsize;
int e1=(start+len)%bufsize;
if(e1>s1){
memset((char*)data+s1,0,e1-s1);
//.........这里部分代码省略.........