rippled
SHAMapHash.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2021 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_BASICS_SHAMAP_HASH_H_INCLUDED
21 #define RIPPLE_BASICS_SHAMAP_HASH_H_INCLUDED
22 
23 #include <ripple/basics/base_uint.h>
24 
25 #include <ostream>
26 
27 namespace ripple {
28 
29 // A SHAMapHash is the hash of a node in a SHAMap, and also the
30 // type of the hash of the entire SHAMap.
31 
33 {
35 
36 public:
37  SHAMapHash() = default;
38  explicit SHAMapHash(uint256 const& hash) : hash_(hash)
39  {
40  }
41 
42  uint256 const&
43  as_uint256() const
44  {
45  return hash_;
46  }
47  uint256&
49  {
50  return hash_;
51  }
52  bool
53  isZero() const
54  {
55  return hash_.isZero();
56  }
57  bool
58  isNonZero() const
59  {
60  return hash_.isNonZero();
61  }
62  int
63  signum() const
64  {
65  return hash_.signum();
66  }
67  void
68  zero()
69  {
70  hash_.zero();
71  }
72 
73  friend bool
74  operator==(SHAMapHash const& x, SHAMapHash const& y)
75  {
76  return x.hash_ == y.hash_;
77  }
78 
79  friend bool
80  operator<(SHAMapHash const& x, SHAMapHash const& y)
81  {
82  return x.hash_ < y.hash_;
83  }
84 
85  friend std::ostream&
87  {
88  return os << x.hash_;
89  }
90 
91  friend std::string
93  {
94  return to_string(x.hash_);
95  }
96 
97  template <class H>
98  friend void
99  hash_append(H& h, SHAMapHash const& x)
100  {
101  hash_append(h, x.hash_);
102  }
103 };
104 
105 inline bool
106 operator!=(SHAMapHash const& x, SHAMapHash const& y)
107 {
108  return !(x == y);
109 }
110 
111 } // namespace ripple
112 
113 #endif // RIPPLE_BASICS_SHAMAP_HASH_H_INCLUDED
std::string
STL class.
ripple::base_uint::isNonZero
bool isNonZero() const
Definition: base_uint.h:537
ripple::SHAMapHash::operator<
friend bool operator<(SHAMapHash const &x, SHAMapHash const &y)
Definition: SHAMapHash.h:80
ripple::SHAMapHash::as_uint256
uint256 & as_uint256()
Definition: SHAMapHash.h:48
ripple::SHAMapHash::isZero
bool isZero() const
Definition: SHAMapHash.h:53
ripple::SHAMapHash::isNonZero
bool isNonZero() const
Definition: SHAMapHash.h:58
ripple::SHAMapHash::SHAMapHash
SHAMapHash()=default
ripple::SHAMapHash
Definition: SHAMapHash.h:32
ripple::SHAMapHash::to_string
friend std::string to_string(SHAMapHash const &x)
Definition: SHAMapHash.h:92
ripple::base_uint< 256 >
ripple::base_uint::isZero
bool isZero() const
Definition: base_uint.h:532
std::ostream
STL class.
ripple::SHAMapHash::hash_
uint256 hash_
Definition: SHAMapHash.h:34
ripple::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:175
ripple::SHAMapHash::operator<<
friend std::ostream & operator<<(std::ostream &os, SHAMapHash const &x)
Definition: SHAMapHash.h:86
ripple::base_uint::signum
constexpr int signum() const
Definition: base_uint.h:327
ripple::SHAMapHash::operator==
friend bool operator==(SHAMapHash const &x, SHAMapHash const &y)
Definition: SHAMapHash.h:74
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SHAMapHash::SHAMapHash
SHAMapHash(uint256 const &hash)
Definition: SHAMapHash.h:38
ripple::base_uint::zero
void zero()
Definition: base_uint.h:542
ripple::SHAMapHash::zero
void zero()
Definition: SHAMapHash.h:68
ripple::SHAMapHash::as_uint256
uint256 const & as_uint256() const
Definition: SHAMapHash.h:43
ostream
ripple::SHAMapHash::signum
int signum() const
Definition: SHAMapHash.h:63
ripple::SHAMapHash::hash_append
friend void hash_append(H &h, SHAMapHash const &x)
Definition: SHAMapHash.h:99