25 #ifndef RIPPLE_BASICS_BASE_UINT_H_INCLUDED
26 #define RIPPLE_BASICS_BASE_UINT_H_INCLUDED
28 #include <ripple/basics/hardened_hash.h>
29 #include <ripple/basics/strHex.h>
30 #include <ripple/beast/utility/Zero.h>
31 #include <boost/endian/conversion.hpp>
32 #include <boost/functional/hash.hpp>
42 template <
class Container,
class = std::
void_t<>>
47 template <
class Container>
51 decltype(std::declval<Container const>().size()),
52 decltype(std::declval<Container const>().data()),
72 template <std::
size_t Bits,
class Tag =
void>
77 "The length of a base_uint in bits must be a multiple of 32.");
81 "The length of a base_uint in bits must be at least 64.");
203 assert(c.size() *
sizeof(
typename Container::value_type) ==
size());
207 template <
class Container>
214 assert(c.size() *
sizeof(
typename Container::value_type) ==
size());
231 for (
int i = 0; i <
WIDTH; i++)
241 return *
this == beast::zero;
249 for (
int i = 0; i <
WIDTH; i++)
265 ul = boost::endian::native_to_big(uHost);
274 for (
int i = 0; i <
WIDTH; i++)
283 for (
int i = 0; i <
WIDTH; i++)
292 for (
int i = 0; i <
WIDTH; i++)
302 for (
int i =
WIDTH - 1; i >= 0; --i)
304 data_[i] = boost::endian::native_to_big(
305 boost::endian::big_to_native(
data_[i]) + 1);
326 for (
int i =
WIDTH - 1; i >= 0; --i)
328 auto prev =
data_[i];
329 data_[i] = boost::endian::native_to_big(
330 boost::endian::big_to_native(
data_[i]) - 1);
354 for (
int i =
WIDTH; i--;)
357 boost::endian::big_to_native(b.
data_[i]);
367 template <
class Hasher>
372 h(a.data_.data(),
sizeof(a.data_));
399 while (
in != sv.
end())
404 if (hi == -1 || lo == -1)
441 return *
this == beast::zero;
446 return *
this != beast::zero;
459 template <std::
size_t Bits,
class Tag>
465 if (ret.first == a.
cend())
469 if (*ret.first > *ret.second)
476 template <std::
size_t Bits,
class Tag>
483 template <std::
size_t Bits,
class Tag>
490 template <std::
size_t Bits,
class Tag>
497 template <std::
size_t Bits,
class Tag>
504 template <std::
size_t Bits,
class Tag>
511 template <std::
size_t Bits,
class Tag>
519 template <std::
size_t Bits,
class Tag>
526 template <std::
size_t Bits,
class Tag>
534 template <std::
size_t Bits,
class Tag>
535 inline const base_uint<Bits, Tag>
541 template <std::
size_t Bits,
class Tag>
542 inline const base_uint<Bits, Tag>
548 template <std::
size_t Bits,
class Tag>
549 inline const base_uint<Bits, Tag>
555 template <std::
size_t Bits,
class Tag>
556 inline const base_uint<Bits, Tag>
563 template <std::
size_t Bits,
class Tag>
570 template <std::
size_t Bits,
class Tag>
577 #ifndef __INTELLISENSE__
578 static_assert(
sizeof(
uint128) == 128 / 8,
"There should be no padding bytes");
579 static_assert(
sizeof(
uint160) == 160 / 8,
"There should be no padding bytes");
580 static_assert(
sizeof(
uint256) == 256 / 8,
"There should be no padding bytes");
587 template <std::
size_t Bits,
class Tag>
bool operator>(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
const base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
const base_uint operator--(int)
friend void hash_append(Hasher &h, base_uint const &a) noexcept
int charUnHex(unsigned char c)
Converts a hex digit to the corresponding integer.
Construct from a raw pointer.
bool operator>=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
base_uint(Container const &c)
const_pointer data() const
std::enable_if_t< detail::is_contiguous_container< Container >::value &&std::is_trivially_copyable< typename Container::value_type >::value, base_uint & > operator=(Container const &c)
const_iterator cbegin() const
static constexpr std::size_t WIDTH
std::string to_string(ListDisposition disposition)
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
bool operator==(Manifest const &lhs, Manifest const &rhs)
constexpr static std::size_t size()
const_pointer const_iterator
const base_uint operator~() const
bool parseHex(std::string const &str)
is_uniquely_represented()=default
Integers of any length that is a multiple of 32-bits.
value_type const & const_reference
bool operator<=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
base_uint & operator|=(const base_uint &b)
const base_uint< Bits, Tag > operator+(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
static constexpr std::size_t bytes
std::array< std::uint32_t, WIDTH > data_
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
int compare(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
base_uint & operator&=(const base_uint &b)
const_iterator begin() const
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Zero allows classes to offer efficient comparisons to zero.
Seed functor once per construction.
const base_uint< Bits, Tag > operator^(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
const base_uint< Bits, Tag > operator&(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool parseHex(const char *str)
bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
base_uint(void const *data, VoidHelper)
base_uint< Bits, Tag > & operator=(beast::Zero)
base_uint(std::uint64_t b)
static base_uint fromVoid(void const *data)
const_iterator end() const
base_uint & operator^=(const base_uint &b)
const base_uint operator++(int)
const_iterator cend() const
std::string strHex(FwdIt begin, FwdIt end)
base_uint & operator=(std::uint64_t uHost)
base_uint & operator+=(const base_uint &b)
value_type const * const_pointer