From d083ede78cf57e33e065dd66e3a02ac48ea8b594 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 20 Aug 2021 18:44:30 +0200 Subject: [PATCH] abacus: bignum: factorize lexicographical compare I want to make use of it for substraction. --- src/bignum/bignum.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 33bf9df..5d6ccb2 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -9,6 +9,17 @@ namespace abacus::bignum { +using digits_type = std::vector; + +namespace { + +bool do_less_than(digits_type const& lhs, digits_type const& rhs) { + return std::lexicographical_compare(lhs.rbegin(), lhs.rend(), rhs.rbegin(), + rhs.rend()); +} + +} // namespace + BigNum::BigNum(std::int64_t number) { if (number == 0) { return; @@ -68,9 +79,7 @@ bool BigNum::less_than(BigNum const& rhs) const { return sign_ < rhs.sign_; } - return std::lexicographical_compare(digits_.rbegin(), digits_.rend(), - rhs.digits_.rbegin(), - rhs.digits_.rend()); + return do_less_than(digits_, rhs.digits_); } void BigNum::canonicalize() {