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