rippled
Loading...
Searching...
No Matches
SHAMapHash.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/partitioned_unordered_map.h>
5
6#include <ostream>
7
8namespace xrpl {
9
10// A SHAMapHash is the hash of a node in a SHAMap, and also the
11// type of the hash of the entire SHAMap.
12
14{
16
17public:
18 SHAMapHash() = default;
19 explicit SHAMapHash(uint256 const& hash) : hash_(hash)
20 {
21 }
22
23 uint256 const&
24 as_uint256() const
25 {
26 return hash_;
27 }
28 uint256&
30 {
31 return hash_;
32 }
33 bool
34 isZero() const
35 {
36 return hash_.isZero();
37 }
38 bool
39 isNonZero() const
40 {
41 return hash_.isNonZero();
42 }
43 int
44 signum() const
45 {
46 return hash_.signum();
47 }
48 void
50 {
51 hash_.zero();
52 }
53
54 friend bool
55 operator==(SHAMapHash const& x, SHAMapHash const& y)
56 {
57 return x.hash_ == y.hash_;
58 }
59
60 friend bool
61 operator<(SHAMapHash const& x, SHAMapHash const& y)
62 {
63 return x.hash_ < y.hash_;
64 }
65
68 {
69 return os << x.hash_;
70 }
71
72 friend std::string
74 {
75 return to_string(x.hash_);
76 }
77
78 template <class H>
79 friend void
80 hash_append(H& h, SHAMapHash const& x)
81 {
82 hash_append(h, x.hash_);
83 }
84};
85
86inline bool
87operator!=(SHAMapHash const& x, SHAMapHash const& y)
88{
89 return !(x == y);
90}
91
92template <>
93inline std::size_t
95{
96 return *reinterpret_cast<std::size_t const*>(key.as_uint256().data());
97}
98
99} // namespace xrpl
int signum() const
Definition SHAMapHash.h:44
friend std::string to_string(SHAMapHash const &x)
Definition SHAMapHash.h:73
SHAMapHash()=default
friend bool operator==(SHAMapHash const &x, SHAMapHash const &y)
Definition SHAMapHash.h:55
friend bool operator<(SHAMapHash const &x, SHAMapHash const &y)
Definition SHAMapHash.h:61
uint256 & as_uint256()
Definition SHAMapHash.h:29
bool isNonZero() const
Definition SHAMapHash.h:39
friend void hash_append(H &h, SHAMapHash const &x)
Definition SHAMapHash.h:80
friend std::ostream & operator<<(std::ostream &os, SHAMapHash const &x)
Definition SHAMapHash.h:67
SHAMapHash(uint256 const &hash)
Definition SHAMapHash.h:19
uint256 const & as_uint256() const
Definition SHAMapHash.h:24
bool isZero() const
Definition SHAMapHash.h:34
bool isZero() const
Definition base_uint.h:508
constexpr int signum() const
Definition base_uint.h:306
pointer data()
Definition base_uint.h:101
bool isNonZero() const
Definition base_uint.h:513
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::size_t extract(uint256 const &key)
Definition base_uint.h:619
bool operator!=(Buffer const &lhs, Buffer const &rhs) noexcept
Definition Buffer.h:209