#include "mergefile.h" #include MergeFile::MergeFile(std::shared_ptr file, Hash&& h) : hash(std::move(h)) { files.emplace_back(file); } const Hash& MergeFile::getHash() const { return hash; } bool MergeFile::addFile(std::shared_ptr f, const Hash& h) { if(hash == h) { files.emplace_back(f); return true; } return false; } std::vector>& MergeFile::getFiles() { return files; } const std::vector>& MergeFile::getFiles() const { return files; } void MergeFile::updateMainFile() { // count the files with more than one link uint32_t complexFiles = std::count_if(files.begin(), files.end(), [](const std::shared_ptr& f) { return f->linkcount > 1; }); if(complexFiles > 1) { // move the file with the most hardlinks to the beginning uint32_t maxlinkcount = 0; uint32_t maxlinkcountoffset = 0; for(uint32_t i = 0; i < files.size(); ++i) { if(files.at(i)->linkcount > maxlinkcount) { maxlinkcount = files.at(i)->linkcount; maxlinkcountoffset = i; } } if(maxlinkcountoffset != 0) { std::swap(files.at(0), files.at(maxlinkcountoffset)); } } }