CatapultServer  v0.5.0.1 (Elephant)
TimestampedHash.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "catapult/constants.h"
24 #include "catapult/types.h"
25 
26 namespace catapult { namespace state {
27 
28 #pragma pack(push, 1)
29 
31  struct TimestampedHash {
32  public:
34  using HashType = std::array<uint8_t, Cached_Hash_Size>;
35 
36  public:
39  {}
40 
42  constexpr explicit TimestampedHash(Timestamp timestamp) : Time(timestamp), Hash()
43  {}
44 
46  explicit TimestampedHash(Timestamp timestamp, const Hash256& hash) : Time(timestamp) {
47  std::memcpy(Hash.data(), hash.data(), Hash.size());
48  }
49 
50  public:
53 
57 
58  public:
60  constexpr bool operator<(const TimestampedHash& rhs) const {
61  return Time < rhs.Time || (Time == rhs.Time && Hash < rhs.Hash);
62  }
63 
65  constexpr bool operator==(const TimestampedHash& rhs) const {
66  return Time == rhs.Time && Hash == rhs.Hash;
67  }
68 
70  constexpr bool operator!=(const TimestampedHash& rhs) const {
71  return !(*this == rhs);
72  }
73  };
74 
75 #pragma pack(pop)
76 
78  RawBuffer SerializeKey(const TimestampedHash& timestampedHash);
79 
81  std::ostream& operator<<(std::ostream& out, const TimestampedHash& timestampedHash);
82 
85 }}
catapult::utils::HexFormat
constexpr void HexFormat(const ByteArray< N, TTag > &)
catapult::state::TimestampedHash::TimestampedHash
TimestampedHash(Timestamp timestamp, const Hash256 &hash)
Creates a timestamped hash from a timestamp and a hash.
Definition: TimestampedHash.h:46
catapult::state::TimestampedHash::Time
Timestamp Time
Timestamp.
Definition: TimestampedHash.h:52
catapult::state::TimestampedHash::TimestampedHash
constexpr TimestampedHash(Timestamp timestamp)
Creates a timestamped hash from a timestamp.
Definition: TimestampedHash.h:42
catapult::state::TimestampedHash::HashType
std::array< uint8_t, Cached_Hash_Size > HashType
Hash type.
Definition: TimestampedHash.h:34
catapult::state::TimestampedHash::TimestampedHash
constexpr TimestampedHash()
Creates a timestamped hash.
Definition: TimestampedHash.h:38
catapult::state::operator<<
std::ostream & operator<<(std::ostream &out, const TimestampedHash &timestampedHash)
Insertion operator for outputting timestampedHash to out.
Definition: TimestampedHash.cpp:30
catapult::model::EntityRange
Represents a range of entities.
Definition: EntityRange.h:31
catapult::utils::BaseValue< uint64_t, Timestamp_tag >
catapult::state::TimestampedHash::operator==
constexpr bool operator==(const TimestampedHash &rhs) const
Returns true if this timestamped hash is equal to rhs.
Definition: TimestampedHash.h:65
catapult::utils::ByteArray::data
constexpr const uint8_t * data() const noexcept
Returns a const pointer to the underlying array.
Definition: ByteArray.h:70
HexFormatter.h
constants.h
catapult::state::TimestampedHash
Represents a hash with attached timestamp.
Definition: TimestampedHash.h:31
EntityRange.h
catapult::state::TimestampedHash::operator!=
constexpr bool operator!=(const TimestampedHash &rhs) const
Returns true if this timestamped hash is not equal to rhs.
Definition: TimestampedHash.h:70
catapult::state::SerializeKey
RawBuffer SerializeKey(const TimestampedHash &timestampedHash)
Wraps timestampedHash in raw buffer.
Definition: TimestampedHash.cpp:26
catapult::state::TimestampedHash::operator<
constexpr bool operator<(const TimestampedHash &rhs) const
Returns true if this timestamped hash is less than rhs.
Definition: TimestampedHash.h:60
types.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::state::TimestampedHash::Hash
HashType Hash
Definition: TimestampedHash.h:56
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
TimestampedHash.h
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62