diff --git a/include/bank.h b/include/bank.h index f078c73..e87430c 100644 --- a/include/bank.h +++ b/include/bank.h @@ -14,14 +14,6 @@ using BankResponse = std::pair; class Bank { - struct xxHashStringGen - { - inline uint64_t operator()(const std::string &str) const - { - return XXH3_64bits(str.data(), str.size()); - } - }; - phmap::parallel_flat_hash_map< std::string, User, xxHashStringGen, diff --git a/include/user.h b/include/user.h index e03bc24..60beeb6 100644 --- a/include/user.h +++ b/include/user.h @@ -1,7 +1,6 @@ #pragma once #include //to be removed later -#include -#include +#include "xxhash_str.h" #include "log.h" struct User diff --git a/include/xxhash_str.h b/include/xxhash_str.h new file mode 100644 index 0000000..ee28675 --- /dev/null +++ b/include/xxhash_str.h @@ -0,0 +1,8 @@ +#pragma once +#include +#include + +struct xxHashStringGen +{ + uint64_t operator()(const std::string &str) const noexcept; +}; diff --git a/src/bank.cpp b/src/bank.cpp index 748f3e6..c1cb885 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -106,7 +106,7 @@ bool Bank::VerifyPassword(const std::string &name, const std::string &attempt) c { bool res = false; users.if_contains(name, [&res, &attempt](const User &u) { - res = (u.password == XXH3_64bits(attempt.data(), attempt.size())); + res = (u.password == xxHashStringGen{}(attempt)); }); return res; } @@ -114,7 +114,7 @@ bool Bank::VerifyPassword(const std::string &name, const std::string &attempt) c void Bank::ChangePassword(const std::string &name, std::string &&new_pass) noexcept { users.modify_if(name, [&new_pass](User &u) { - u.password = XXH3_64bits(new_pass.data(), new_pass.size()); + u.password = xxHashStringGen{}(new_pass); }); #if CONSERVATIVE_DISK_SAVE save_flag.SetChangesOn(); diff --git a/src/user.cpp b/src/user.cpp index d697687..0d0db1e 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -5,7 +5,7 @@ * * @param init_pass initial password */ -User::User(std::string &&init_pass) noexcept : password(XXH3_64bits(init_pass.data(), init_pass.size())) {} +User::User(std::string &&init_pass) noexcept : password(xxHashStringGen{}(init_pass)) {} /** * @brief User Constructor for admins @@ -13,7 +13,7 @@ User::User(std::string &&init_pass) noexcept : password(XXH3_64bits(init_pass.da * @param init_bal initial balance * @param init_pass initial password */ -User::User(uint32_t init_bal, std::string &&init_pass) noexcept : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())) {} +User::User(uint32_t init_bal, std::string &&init_pass) noexcept : balance(init_bal), password(xxHashStringGen{}(init_pass)) {} /** * @brief User Constructor for loading diff --git a/src/xxhash_str.cpp b/src/xxhash_str.cpp new file mode 100644 index 0000000..5122082 --- /dev/null +++ b/src/xxhash_str.cpp @@ -0,0 +1,6 @@ +#include "xxhash_str.h" + +uint64_t xxHashStringGen::operator()(const std::string &str) const noexcept +{ + return XXH3_64bits(str.data(), str.size()); +}