Added custom hash for filesystem path strings

This commit is contained in:
David
2024-04-10 17:04:49 -04:00
parent 1bf313bae5
commit 61141c09e8
3 changed files with 11 additions and 4 deletions
@@ -373,7 +373,7 @@ std::string FileHelper::get_last_modified_timestamp(const fs::path &path) {
return out;
}
void FileHelper::insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map<fs::path, std::string> &timestamps) {
void FileHelper::insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map<fs::path, std::string, PathHash> &timestamps) {
// TODO: Make this multithreaded?
for (const auto &filepath : fs::recursive_directory_iterator(dirPath)) {
timestamps[filepath] = get_last_modified_timestamp(filepath);
@@ -12,6 +12,13 @@
#include <filesystem>
namespace fs = std::filesystem;
// Using path as a key doesn't seem to work on raspberry pi OS?
struct PathHash {
std::size_t operator()(const std::filesystem::__cxx11::path& p) const {
return std::filesystem::hash_value(p);
}
};
class FileHelper {
public:
static std::vector<uint8_t> read_binary_file(const fs::path &filename);
@@ -60,7 +67,7 @@ public:
static void endianswap(std::vector<uint8_t> &bytes);
static std::string get_last_modified_timestamp(const fs::path &path);
static void insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map<fs::path, std::string> &timestamps);
static void insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map<fs::path, std::string, PathHash> &timestamps);
private:
};
@@ -20,8 +20,8 @@ private:
JsonFile *_modOrderFile;
size_t _modOrderCount;
std::unordered_map<fs::path, std::string> _lastModifiedDates;
std::unordered_map<fs::path, std::vector<fs::path>> _modFiles;
std::unordered_map<fs::path, std::string, PathHash> _lastModifiedDates;
std::unordered_map<fs::path, std::vector<fs::path>, PathHash> _modFiles;
std::vector<fs::path> _modFilesModified;
void _check_mod_path(fs::path &modPath);