aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDenis Evsyukov <[email protected]>2020-02-22 21:03:52 +0300
committerDenis Evsyukov <[email protected]>2020-02-22 21:03:52 +0300
commit5e18c8eccf4ba05c9cce5672d8495c3904b66cd0 (patch)
treec7d4aa2484a769b3285af24bddbb3af6281e9d9e /src
parent[~] hash to function (diff)
downloadt-5e18c8eccf4ba05c9cce5672d8495c3904b66cd0.tar.xz
t-5e18c8eccf4ba05c9cce5672d8495c3904b66cd0.zip
[+] prefix function
Diffstat (limited to 'src')
-rw-r--r--src/functions.hpp13
-rw-r--r--src/main.cpp14
2 files changed, 25 insertions, 2 deletions
diff --git a/src/functions.hpp b/src/functions.hpp
index 123f4ab..89e3b01 100644
--- a/src/functions.hpp
+++ b/src/functions.hpp
@@ -6,6 +6,7 @@
#define T_FUNCTIONS_HPP
#include "sha256/picosha2.h"
+#include <string>
std::string &ltrim(std::string &str, const std::string &chars = "\t\n\v\f\r ") {
str.erase(0, str.find_first_not_of(chars));
@@ -28,4 +29,16 @@ std::string sha256_hash(std::string text) {
std::string hex_str = picosha2::bytes_to_hex_string(hash.begin(), hash.end());
return hex_str;
}
+
+std::string prefix(std::string hash,
+ std::unordered_map<std::string, std::string> tasks) {
+ std::string prefix;
+ for (size_t i = 1; i <= hash.length(); i++) {
+ prefix = hash.substr(0, i);
+ if (tasks.find(prefix) == tasks.end())
+ return prefix;
+ }
+ return hash;
+}
+
#endif // T_FUNCTIONS_HPP
diff --git a/src/main.cpp b/src/main.cpp
index cc1144f..343b9d8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,9 +1,10 @@
#include <filesystem>
+#include <unordered_map>
#include "functions.hpp"
#include "opts/cxxopts.hpp"
-using namespace std;
+std::unordered_map<std::string, std::string> tasks = {};
int main(int argc, char *argv[]) {
cxxopts::Options options("MyProgram", "One line description of MyProgram");
@@ -37,7 +38,16 @@ int main(int argc, char *argv[]) {
str += s + " ";
}
auto src_str = trim(str);
- cout << "sha256('" << str << "'): " << sha256_hash(str) << endl;
+ // tasks[sha256_hash(str)] = str;
+ std::string hash = sha256_hash(str);
+ std::cout << "sha256('" << str << "'): " << hash << std::endl;
+
+ // for (const auto &n : tasks) {
+ // std::cout << "Key:[" << n.first << "] Value:[" << n.second << "]\n";
+ // }
+
+ std::string p = prefix(hash, tasks);
+ std::cout << "prefix: " << p << std::endl;
}
std::string taskdir;
if (result.count("taskdir")) {