OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
NativeHashGenerator.h
Go to the documentation of this file.
1 //
2 // Class NativeHashGenerator
3 // Generates a hash name.
4 // Concatenates and hashes a vector of strings.
5 //
6 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
7 // All rights reserved
8 //
9 // Implemented as part of the PhD thesis
10 // "Toward massively parallel multi-objective optimization with application to
11 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
12 //
13 // This file is part of OPAL.
14 //
15 // OPAL is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
22 //
23 #include <vector>
24 #include <string>
25 #include <sstream>
26 #include <functional>
27 #include <algorithm>
28 
30 
31 public:
32 
33  static std::string generate(std::vector<std::string> arguments,
34  size_t world_pid = 0) {
35 
36  std::string hash_input = "";
37 
38  for (const std::string &arg: arguments ) {
39  hash_input += arg;
40  }
41 
42  hash_input += "_" + std::to_string(world_pid);
43 
44  std::hash<std::string> hashFunction;
45  size_t hash_value = hashFunction(hash_input);
46 
47  std::ostringstream hash_str;
48  hash_str << std::hex << hash_value;
49 
50  reverse(hash_input.begin(), hash_input.end());
51  hash_value = hashFunction(hash_input);
52  hash_str << hash_value;
53 
54  return hash_str.str();
55  }
56 
57 private:
58 
61 
62 };
arg(a))
static std::string generate(std::vector< std::string > arguments, size_t world_pid=0)