mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
clang-format and clang-tidy fixes for 276fde9d
This commit is contained in:
parent
276fde9d3f
commit
397059cea4
@ -75,8 +75,9 @@ uint256_t exp(uint256_t number, uint256_t power, const uint256_t &mod) {
|
||||
ans = (ans * number) % mod;
|
||||
}
|
||||
power >>= 1;
|
||||
if (power)
|
||||
if (power) {
|
||||
number = (number * number) % mod;
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
@ -90,7 +91,8 @@ uint256_t exp(uint256_t number, uint256_t power, const uint256_t &mod) {
|
||||
* @param mod Given field
|
||||
* @return the resultant point
|
||||
*/
|
||||
Point addition(Point a, Point b, uint256_t curve_a_coeff, uint256_t mod) {
|
||||
Point addition(Point a, Point b, const uint256_t &curve_a_coeff,
|
||||
uint256_t mod) {
|
||||
uint256_t lambda(0); /// Slope
|
||||
uint256_t zero(0); /// value zero
|
||||
lambda = zero = 0;
|
||||
@ -138,11 +140,11 @@ Point addition(Point a, Point b, uint256_t curve_a_coeff, uint256_t mod) {
|
||||
* @returns the resultant point
|
||||
*/
|
||||
Point multiply(const Point &a, const uint256_t &curve_a_coeff, uint256_t p,
|
||||
uint256_t mod) {
|
||||
const uint256_t &mod) {
|
||||
Point N = a;
|
||||
N.x %= mod;
|
||||
N.y %= mod;
|
||||
uint256_t inf;
|
||||
uint256_t inf{};
|
||||
inf = ~uint256_t(0);
|
||||
Point Q = {inf, inf};
|
||||
while (p) {
|
||||
@ -155,8 +157,9 @@ Point multiply(const Point &a, const uint256_t &curve_a_coeff, uint256_t p,
|
||||
}
|
||||
}
|
||||
p >>= 1;
|
||||
if (p)
|
||||
if (p) {
|
||||
N = addition(N, N, curve_a_coeff, mod);
|
||||
}
|
||||
}
|
||||
return Q;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ std::string add(const std::string &first, const std::string &second) {
|
||||
* @details 128-bit numbers.
|
||||
*/
|
||||
class uint128_t {
|
||||
uint64_t f, s; /// First and second half of 128 bit number.
|
||||
uint64_t f{}, s{}; /// First and second half of 128 bit number.
|
||||
|
||||
/**
|
||||
* @brief Get integer from given string.
|
||||
@ -118,13 +118,13 @@ class uint128_t {
|
||||
* @brief Copy constructor
|
||||
* @param num 128-bit unsigned integer
|
||||
*/
|
||||
uint128_t(const uint128_t &num) : f(num.f), s(num.s) {}
|
||||
uint128_t(const uint128_t &num) = default;
|
||||
|
||||
/**
|
||||
* @brief Move constructor
|
||||
* @param num 128-bit unsigned integer
|
||||
*/
|
||||
uint128_t(uint128_t &&num) : f(std::move(num.f)), s(std::move(num.s)) {}
|
||||
uint128_t(uint128_t &&num) noexcept : f(num.f), s(num.s) {}
|
||||
|
||||
/**
|
||||
* @brief Destructor for uint128_t
|
||||
@ -138,8 +138,9 @@ class uint128_t {
|
||||
*/
|
||||
inline uint32_t _lez() {
|
||||
#ifndef _MSC_VER
|
||||
if (f)
|
||||
if (f) {
|
||||
return __builtin_clzll(f);
|
||||
}
|
||||
return 64 + __builtin_clzll(s);
|
||||
#else
|
||||
unsigned long r = 0;
|
||||
@ -160,8 +161,9 @@ class uint128_t {
|
||||
*/
|
||||
inline uint32_t _trz() {
|
||||
#ifndef _MSC_VER
|
||||
if (f)
|
||||
if (f) {
|
||||
return __builtin_ctzll(f);
|
||||
}
|
||||
return 64 + __builtin_ctzll(s);
|
||||
#else
|
||||
unsigned long r = 0;
|
||||
@ -178,11 +180,11 @@ class uint128_t {
|
||||
inline uint32_t _len() { return _lez(); }
|
||||
|
||||
// Casting operators
|
||||
inline operator bool() const { return f || s; }
|
||||
inline explicit operator bool() const { return f || s; }
|
||||
|
||||
template <typename T, typename = typename std::enable_if<
|
||||
std::is_integral<T>::value, T>::type>
|
||||
inline operator T() const {
|
||||
inline explicit operator T() const {
|
||||
return static_cast<T>(s);
|
||||
}
|
||||
|
||||
@ -210,11 +212,7 @@ class uint128_t {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline uint128_t &operator=(const uint128_t &p) {
|
||||
this->f = p.f;
|
||||
this->s = p.s;
|
||||
return *this;
|
||||
}
|
||||
inline uint128_t &operator=(const uint128_t &p) = default;
|
||||
|
||||
inline uint128_t &operator=(uint128_t &&p) = default;
|
||||
|
||||
|
@ -31,7 +31,7 @@ struct std::is_unsigned<uint256_t> : std::true_type {};
|
||||
* @details 256-bit number class.
|
||||
*/
|
||||
class uint256_t {
|
||||
uint128_t f, s; /// First and second half of 256 bit number.
|
||||
uint128_t f{}, s{}; /// First and second half of 256 bit number.
|
||||
|
||||
/**
|
||||
* @brief Get integer from given string.
|
||||
@ -81,20 +81,22 @@ class uint256_t {
|
||||
* @brief Copy constructor
|
||||
* @param num 256-bit unsigned integer
|
||||
*/
|
||||
uint256_t(const uint256_t &num) : f(num.f), s(num.s) {}
|
||||
uint256_t(const uint256_t &num) = default;
|
||||
|
||||
/**
|
||||
* @brief Move constructor
|
||||
* @param num 256-bit unsigned integer
|
||||
*/
|
||||
uint256_t(uint256_t &&num) : f(std::move(num.f)), s(std::move(num.s)) {}
|
||||
uint256_t(uint256_t &&num) noexcept
|
||||
: f(std::move(num.f)), s(std::move(num.s)) {}
|
||||
|
||||
/**
|
||||
* @brief Parameterized constructor
|
||||
* @param high higher part 128-bit unsigned integer
|
||||
* @param low lower part 128-bit unsigned integer
|
||||
*/
|
||||
uint256_t(const uint128_t &high, const uint128_t &low) : f(high), s(low) {}
|
||||
uint256_t(uint128_t high, uint128_t low)
|
||||
: f(std::move(high)), s(std::move(low)) {}
|
||||
|
||||
/**
|
||||
* @brief Parameterized constructor
|
||||
@ -114,8 +116,9 @@ class uint256_t {
|
||||
* @returns Integer denoting leading zeroes
|
||||
*/
|
||||
inline uint32_t _lez() {
|
||||
if (f)
|
||||
if (f) {
|
||||
return f._lez();
|
||||
}
|
||||
return 128 + s._lez();
|
||||
}
|
||||
|
||||
@ -125,25 +128,26 @@ class uint256_t {
|
||||
* @returns Integer denoting Trailing zeroes
|
||||
*/
|
||||
inline uint32_t _trz() {
|
||||
if (s)
|
||||
if (s) {
|
||||
return s._trz();
|
||||
}
|
||||
return 128 + f._trz();
|
||||
}
|
||||
|
||||
inline uint32_t _len() { return _lez(); }
|
||||
|
||||
inline operator bool() const { return f || s; }
|
||||
inline explicit operator bool() const { return f || s; }
|
||||
|
||||
/**
|
||||
* @brief casting operator
|
||||
*/
|
||||
template <typename T, typename = typename std::enable_if<
|
||||
std::is_integral<T>::value, T>::type>
|
||||
inline operator T() const {
|
||||
inline explicit operator T() const {
|
||||
return static_cast<T>(s);
|
||||
}
|
||||
|
||||
inline operator uint128_t() const { return s; }
|
||||
inline explicit operator uint128_t() const { return s; }
|
||||
|
||||
/**
|
||||
* @brief returns lower 128-bit integer part
|
||||
@ -158,11 +162,7 @@ class uint256_t {
|
||||
inline uint128_t upper() const { return f; }
|
||||
|
||||
// Assign
|
||||
inline uint256_t &operator=(const uint256_t &p) {
|
||||
this->f = p.f;
|
||||
this->s = p.s;
|
||||
return *this;
|
||||
}
|
||||
inline uint256_t &operator=(const uint256_t &p) = default;
|
||||
|
||||
template <typename T, typename = typename std::enable_if<
|
||||
std::is_integral<T>::value, T>::type>
|
||||
|
Loading…
Reference in New Issue
Block a user