xrpld
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 <cstddef>
7#include <ostream>
8#include <string>
9
10namespace xrpl {
11
12// A SHAMapHash is the hash of a node in a SHAMap, and also the
13// type of the hash of the entire SHAMap.
14
16{
18
19public:
20 SHAMapHash() = default;
21 explicit SHAMapHash(uint256 const& hash) : hash_(hash)
22 {
23 }
24
25 [[nodiscard]] uint256 const&
26 asUInt256() const
27 {
28 return hash_;
29 }
30 uint256&
32 {
33 return hash_;
34 }
35 [[nodiscard]] bool
36 isZero() const
37 {
38 return hash_.isZero();
39 }
40 [[nodiscard]] bool
41 isNonZero() const
42 {
43 return hash_.isNonZero();
44 }
45 [[nodiscard]] int
46 signum() const
47 {
48 return hash_.signum();
49 }
50 void
52 {
53 hash_.zero();
54 }
55
56 friend bool
57 operator==(SHAMapHash const& x, SHAMapHash const& y)
58 {
59 return x.hash_ == y.hash_;
60 }
61
62 friend bool
63 operator<(SHAMapHash const& x, SHAMapHash const& y)
64 {
65 return x.hash_ < y.hash_;
66 }
67
70 {
71 return os << x.hash_;
72 }
73
74 friend std::string
76 {
77 return to_string(x.hash_);
78 }
79
80 template <class H>
81 friend void
82 hash_append(H& h, SHAMapHash const& x)
83 {
84 hash_append(h, x.hash_);
85 }
86};
87
88template <>
89inline std::size_t
91{
92 return *reinterpret_cast<std::size_t const*>(key.asUInt256().data());
93}
94
95} // namespace xrpl
uint256 & asUInt256()
Definition SHAMapHash.h:31
int signum() const
Definition SHAMapHash.h:46
friend std::string to_string(SHAMapHash const &x)
Definition SHAMapHash.h:75
SHAMapHash()=default
friend bool operator==(SHAMapHash const &x, SHAMapHash const &y)
Definition SHAMapHash.h:57
friend bool operator<(SHAMapHash const &x, SHAMapHash const &y)
Definition SHAMapHash.h:63
bool isNonZero() const
Definition SHAMapHash.h:41
friend void hash_append(H &h, SHAMapHash const &x)
Definition SHAMapHash.h:82
friend std::ostream & operator<<(std::ostream &os, SHAMapHash const &x)
Definition SHAMapHash.h:69
SHAMapHash(uint256 const &hash)
Definition SHAMapHash.h:21
uint256 const & asUInt256() const
Definition SHAMapHash.h:26
bool isZero() const
Definition SHAMapHash.h:36
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:673
BaseUInt< 256 > uint256
Definition base_uint.h:580