//_private_searchBestParams.cpp // tool for HDiff // /* The MIT License (MIT) Copyright (c) 2012-2017 HouSisong Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "assert.h" #include #include //pow #include #include #include "../libHDiffPatch/HDiff/diff.h" #include "../libHDiffPatch/HPatch/patch.h" #include "../libHDiffPatch/HDiff/private_diff/suffix_string.h" typedef unsigned char TByte; typedef unsigned int TUInt32; typedef ptrdiff_t TInt; void readFile(std::vector& data,const char* fileName){ std::ifstream file(fileName, std::ios::in | std::ios::binary | std::ios::ate); std::streampos file_length=file.tellg(); file.seekg(0,std::ios::beg); size_t needRead=(size_t)file_length; if ((file_length<0)||((std::streamsize)needRead!=(std::streamsize)file_length)) { file.close(); std::cout<<"open read file \""<& data,const char* fileName){ std::ofstream file(fileName, std::ios::out | std::ios::binary | std::ios::trunc); file.write((const char*)data.data(), data.size()); file.close(); } #define IS_NOTICE_compress_canceled 0 //for test, close compress fail notice #define IS_REUSE_compress_handle 1 //for test, must in single thread //===== select compress plugin ===== #define _CompressPlugin_no #define _CompressPlugin_zlib #define _CompressPlugin_bz2 #define _CompressPlugin_lzma #include "../compress_plugin_demo.h" #include "../decompress_plugin_demo.h" struct THDiffPrivateParams{ int out0; int out1; std::string asString()const{ std::stringstream str; str< oldData; std::vector newData; std::string oldFileName; size_t oldFileSize; std::string newFileName; size_t newFileSize; THDiffPrivateParams kP; size_t diffSize; size_t zipSize; size_t bz2Size; size_t lzmaSize; std::string asString()const{ std::stringstream str; //str<& out_diff, const hdiff_TCompress* compressPlugin, int kMinSingleMatchScore, const hdiff_private::TSuffixString* sstring); std::vector diffData; const TByte* newData0=di.newData.data(); const TByte* oldData0=di.oldData.data(); __hdiff_private__create_compressed_diff(newData0,newData0+di.newData.size(), oldData0,oldData0+di.oldData.size(),diffData, compressPlugin,di.kP.out0,&di.sstring); /* if (!check_compressed_diff(newData0,newData0+di.newData.size(), oldData0,oldData0+di.oldData.size(), diffData.data(),diffData.data()+diffData.size(), decompressPlugin)){ std::cout<<"\ncheck hdiffz data error!!!\n"; exit(1); }//*/ return diffData.size(); } void doDiff(TDiffInfo& di){ if (di.sstring.SASize()==0){ readFile(di.oldData,di.oldFileName.c_str()); readFile(di.newData,di.newFileName.c_str()); di.oldFileSize=di.oldData.size(); di.newFileSize=di.newData.size(); const TByte* oldData0=di.oldData.data(); di.sstring.resetSuffixString(oldData0,oldData0+di.oldData.size(),8); } di.diffSize=_compress_diff(di,0,0); di.zipSize=_compress_diff(di,&zlibCompressPlugin.base,&zlibDecompressPlugin); di.bz2Size=_compress_diff(di,&bz2CompressPlugin.base,&bz2DecompressPlugin); di.lzmaSize=_compress_diff(di,&lzmaCompressPlugin.base,&lzmaDecompressPlugin); } static std::string rToStr(double R){ char buf[256]; sprintf(buf,"%0.6f",R); return buf; } static std::string rToTag(double cur,double& best){ if (cur& fileNames){ const int kDoCount=(int)fileNames.size()/2; std::vector DiList(kDoCount); for (int doi=0; doi=0; kMinSingleMatchScore--){{ THDiffPrivateParams kP={kMinSingleMatchScore,0}; double sumDiffR=1; double sumZipDiffR=1; double sumBz2DiffR=1; double sumLzmaDiffR=1; size_t sumOldSize=0; size_t sumNewSize=0; size_t sumDiffSize=0; size_t sumZipDiffSize=0; size_t sumBz2DiffSize=0; size_t sumLzmaDiffSize=0; for (size_t doi=0; doi fileNames; for (int i=1; i