diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2c0b237 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "*.inja": "jinja-html", + "iosfwd": "cpp", + "fstream": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 626e5d5..dcc1776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(CMAKE_EXE_LINKER_FLAGS "-static") file(GLOB SOURCES "src/*.cpp") add_executable(dehydrate ${SOURCES}) -target_include_directories(dehydrate PRIVATE include) +target_include_directories(dehydrate PRIVATE include contrib) # Optionally, include headers include_directories(include) \ No newline at end of file diff --git a/src/generator.cpp b/src/generator.cpp index 9668140..a472e92 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "../../contrib/xxhash.hpp" +#include "xxhash.hpp" namespace fs = std::filesystem; @@ -37,7 +37,15 @@ void generate_file_code(const std::string& source, const std::string& destfolder #include #include #include -#include \"../../contrib/xxhash.hpp\" + +// Tiny dependency-free FNV-1a 64-bit hash +static uint64_t fnv1a_64(const void* data, size_t len) { + const uint8_t* p = static_cast(data); + uint64_t h = 0xcbf29ce484222325ULL; + for (size_t i = 0; i < len; ++i) + h = (h ^ p[i]) * 0x100000001b3ULL; + return h; +} )cpp"; cpp << "#include \"" << hppname << "\"\n"; cpp << "namespace " << ns << " {\n"; @@ -61,10 +69,9 @@ bool recreate_file(std::string destination_folder) { std::ostringstream oss; oss << in.rdbuf(); std::string data = oss.str(); - auto h = XXH3_128bits(data.data(), data.size()); + uint64_t h = fnv1a_64(data.data(), data.size()); std::ostringstream hex; - for (size_t i = 0; i < sizeof(h); ++i) - hex << std::hex << std::setw(2) << std::setfill('0') << ((const unsigned char*)&h)[i]; + hex << std::hex << std::setw(16) << std::setfill('0') << h; existing_hash = hex.str(); } bool needs_write = !fs::exists(outpath) || existing_hash != file_hash; @@ -117,7 +124,7 @@ void generate_folder_code(const std::string& source, const std::string& destfold #include #include #include -#include \"../../contrib/xxhash.hpp\" +#include "xxhash.hpp" )cpp"; cpp << "#include \"" << hppname << "\"\n"; cpp << "namespace " << ns << " {\n"; @@ -158,10 +165,9 @@ bool recreate_tree(std::string destination_folder) { std::ifstream in(outpath, std::ios::binary); std::ostringstream oss; oss << in.rdbuf(); std::string data = oss.str(); - auto h = XXH3_128bits(data.data(), data.size()); + uint64_t h = XXH3_64bits(data.data(), data.size()); std::ostringstream hex; - for (size_t i = 0; i < sizeof(h); ++i) - hex << std::hex << std::setw(2) << std::setfill('0') << ((const unsigned char*)&h)[i]; + hex << std::hex << std::setw(16) << std::setfill('0') << h; existing_hash = hex.str(); } bool needs_write = !fs::exists(outpath) || existing_hash != )cpp" << "hash_" << var << R"cpp(; diff --git a/src/hash.cpp b/src/hash.cpp index 0eb6511..564b9dd 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -1,20 +1,18 @@ #include "hash.hpp" -#include "../contrib/xxhash.hpp" +#include "xxhash.hpp" #include #include #include -static std::string to_hex(const void* data, size_t len) { - const unsigned char* p = static_cast(data); +static std::string to_hex64(uint64_t value) { std::ostringstream oss; - for (size_t i = 0; i < len; ++i) - oss << std::hex << std::setw(2) << std::setfill('0') << (int)p[i]; + oss << std::hex << std::setw(16) << std::setfill('0') << value; return oss.str(); } std::string hash_data(const std::string& data) { - auto h = XXH3_128bits(data.data(), data.size()); - return to_hex(&h, sizeof(h)); + uint64_t h = XXH3_64bits(data.data(), data.size()); + return to_hex64(h); } std::string hash_file(const std::string& path) {