.
This commit is contained in:
parent
7049fa0a80
commit
d26ff959f8
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.inja": "jinja-html",
|
||||
"iosfwd": "cpp",
|
||||
"fstream": "cpp"
|
||||
}
|
||||
}
|
@ -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)
|
@ -5,7 +5,7 @@
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#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 <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#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<const uint8_t*>(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 <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#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(;
|
||||
|
12
src/hash.cpp
12
src/hash.cpp
@ -1,20 +1,18 @@
|
||||
#include "hash.hpp"
|
||||
#include "../contrib/xxhash.hpp"
|
||||
#include "xxhash.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
static std::string to_hex(const void* data, size_t len) {
|
||||
const unsigned char* p = static_cast<const unsigned char*>(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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user