logic: sort custom indexer commands by indexed file size and name

This commit is contained in:
mlangkabel
2019-05-21 17:23:03 +02:00
parent 0fb7fe719a
commit 4d6cb464c4
4 changed files with 52 additions and 43 deletions
+39
View File
@@ -1,9 +1,48 @@
#include "utilityFile.h"
#include "FilePath.h"
#include "FileSystem.h"
#include "utility.h"
std::vector<FilePath> utility::partitionFilePathsBySize(std::vector<FilePath> filePaths, int partitionCount)
{
typedef std::pair<unsigned long long int, FilePath> PairType;
std::vector<PairType> sourceFileSizesToCommands;
for (const FilePath& path : filePaths)
{
if (path.exists())
{
sourceFileSizesToCommands.push_back(std::make_pair(FileSystem::getFileByteSize(path), path));
}
else
{
sourceFileSizesToCommands.push_back(std::make_pair(1, path));
}
}
std::sort(sourceFileSizesToCommands.begin(), sourceFileSizesToCommands.end(), [](const PairType& p, const PairType& q) { return p.first > q.first; });
if (0 < partitionCount && partitionCount < sourceFileSizesToCommands.size())
{
for (int i = 0; i < partitionCount; i++)
{
std::sort(
sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() * i / partitionCount,
sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() * (i + 1) / partitionCount,
[](const PairType& p, const PairType& q) { return p.second.wstr() < q.second.wstr(); }
);
}
}
std::vector<FilePath> sortedFilePaths;
for (const PairType &pair : sourceFileSizesToCommands)
{
sortedFilePaths.push_back(pair.second);
}
return sortedFilePaths;
}
std::vector<FilePath> utility::getTopLevelPaths(const std::vector<FilePath>& paths)
{
return utility::getTopLevelPaths(utility::toSet(paths));
+2
View File
@@ -8,6 +8,8 @@ class FilePath;
namespace utility
{
std::vector<FilePath> partitionFilePathsBySize(std::vector<FilePath> filePaths, int partitionCount = 0);
std::vector<FilePath> getTopLevelPaths(const std::vector<FilePath>& paths);
std::vector<FilePath> getTopLevelPaths(const std::set<FilePath>& paths);