mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
reverted xxhash changes
This commit is contained in:
parent
a025954b74
commit
503462508f
3 changed files with 5377 additions and 32 deletions
5325
include/xxhash.h
Normal file
5325
include/xxhash.h
Normal file
File diff suppressed because it is too large
Load diff
42
src/bank.cpp
42
src/bank.cpp
|
|
@ -8,15 +8,8 @@ int_fast8_t Bank::AddUser(const std::string &name, std::string &&init_pass)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
if (!users.try_emplace_l(
|
return ErrorResponse::UserNotFound + (2 * users.try_emplace_l(
|
||||||
name, [](User &) {}, std::move(init_pass)))
|
name, [](User &) {}, std::move(init_pass))); //branchless if 1 else -1
|
||||||
{
|
|
||||||
return ErrorResponse::UserAlreadyExists;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass)
|
int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass)
|
||||||
|
|
@ -31,18 +24,11 @@ int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, u
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
if (!users.try_emplace_l(
|
return ErrorResponse::UserAlreadyExists + (7 * (!users.try_emplace_l(
|
||||||
name, [](User &) {}, init_bal, std::move(init_pass)))
|
name, [](User &) {}, init_bal, std::move(init_pass))));
|
||||||
{
|
|
||||||
return ErrorResponse::UserAlreadyExists;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//not branchless yet
|
||||||
int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt)
|
int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt)
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
|
|
@ -56,6 +42,7 @@ int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt)
|
||||||
return state * ErrorResponse::WrongPassword;
|
return state * ErrorResponse::WrongPassword;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//not branchless yet
|
||||||
int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attempt)
|
int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attempt)
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
|
|
@ -70,6 +57,7 @@ int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//not branchless yet
|
||||||
int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, const std::string &attempt)
|
int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, const std::string &attempt)
|
||||||
{
|
{
|
||||||
//cant send money to self, from self or amount is 0
|
//cant send money to self, from self or amount is 0
|
||||||
|
|
@ -157,19 +145,9 @@ int_fast8_t Bank::SetBal(const std::string &name, const std::string &attempt, ui
|
||||||
{
|
{
|
||||||
return ErrorResponse::WrongAdminPassword;
|
return ErrorResponse::WrongAdminPassword;
|
||||||
}
|
}
|
||||||
else
|
return ErrorResponse::UserNotFound + (2 * !users.modify_if(name, [amount](User &u) {
|
||||||
{
|
u.balance = amount;
|
||||||
if (!users.modify_if(name, [amount](User &u) {
|
}));
|
||||||
u.balance = amount;
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
return ErrorResponse::UserNotFound;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int_fast64_t Bank::GetBal(const std::string &name) const
|
int_fast64_t Bank::GetBal(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
42
src/xxhash.c
Normal file
42
src/xxhash.c
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* xxHash - Extremely Fast Hash algorithm
|
||||||
|
* Copyright (C) 2012-2020 Yann Collet
|
||||||
|
*
|
||||||
|
* BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - xxHash homepage: https://www.xxhash.com
|
||||||
|
* - xxHash source repository: https://github.com/Cyan4973/xxHash
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* xxhash.c instantiates functions defined in xxhash.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
|
||||||
|
#define XXH_IMPLEMENTATION /* access definitions */
|
||||||
|
|
||||||
|
#include "xxhash.h"
|
||||||
Loading…
Reference in a new issue