Commit 2622522e authored by kraus's avatar kraus

replace UUID hash generator with native C++11 hash generator

parent 23a11c92
#include "Util/UUIDNameGenerator.h"
#include "Util/NativeHashGenerator.h"
#include "gtest/gtest.h"
#include <fstream>
......@@ -37,8 +37,8 @@ namespace {
params.push_back("sigmax=5.05");
params.push_back("sigmay=6.05");
std::string hash = UUIDNameGenerator::generate(params);
std::string expected = "ccee6325-cc2a-5773-b39a-dabfcbeb6a38";
std::string hash = NativeHashGenerator::generate(params);
std::string expected = "88a02dc533c53bc1";
ASSERT_STREQ(expected.c_str(), hash.c_str());
}
......
#include <vector>
#include <string>
#include <sstream>
#include "boost/uuid/uuid.hpp"
#include "boost/uuid/uuid_io.hpp"
#include "boost/uuid/name_generator.hpp"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include <functional>
/**
* \brief Generates a hash name.
*
* Concatenates and hashes a vector of strings.
*/
class UUIDNameGenerator {
class NativeHashGenerator {
public:
static std::string generate(std::vector<std::string> arguments,
size_t world_pid = 0) {
std::string hash_string = "";
std::string hash_input = "";
for (const std::string &arg: arguments ) {
hash_string += arg;
hash_input += arg;
}
// append PID
std::ostringstream pidStr;
pidStr << world_pid;
hash_string += "_" + pidStr.str();
// // append PID
// std::ostringstream pidStr;
// pidStr << world_pid;
hash_input += "_" + std::to_string(world_pid);//pidStr.str();
std::hash<std::string> hashFunction;
size_t hash_value = hashFunction(hash_input);
std::ostringstream hash_str;
hash_str << std::hex << hash_value;
boost::uuids::name_generator_sha1 hash(boost::uuids::ns::dns());
return boost::uuids::to_string(hash(hash_string));
return hash_str.str();
}
private:
UUIDNameGenerator() {}
~UUIDNameGenerator() {}
NativeHashGenerator() {}
~NativeHashGenerator() {}
};
\ No newline at end of file
......@@ -16,7 +16,7 @@
#include "Util/SDDSParser/SDDSParserException.h"
#include "Util/OptPilotException.h"
#include "Util/HashNameGenerator.h"
#include "Util/UUIDNameGenerator.h"
#include "Util/NativeHashGenerator.h"
#include "Expression/SumErrSq.h"
#include "Expression/FromFile.h"
......@@ -96,7 +96,7 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
// simulation data
std::string hash;
if (Options::useUUID) {
hash = UUIDNameGenerator::generate(dict);
hash = NativeHashGenerator::generate(dict);
} else {
hash = HashNameGenerator::generate(dict);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment