Ring Daemon 16.0.0
Loading...
Searching...
No Matches
dev::FixedHash< N > Class Template Reference

Fixed-size raw-byte array container type, with an API optimised for storing hashes. More...

#include <FixedHash.h>

Inheritance diagram for dev::FixedHash< N >:
Inheritance graph
Collaboration diagram for dev::FixedHash< N >:
Collaboration graph

Public Types

enum  { size = N }
 The size of the container. More...
 
enum  ConstructFromHashType { AlignLeft , AlignRight , FailIfDifferent }
 Method to convert from a string. More...
 
enum  ConstructFromPointerType { ConstructFromPointer }
 A dummy flag to avoid accidental construction from pointer. More...
 
enum  ConstructFromStringType { FromHex , FromBinary }
 Method to convert from a string. More...
 

Public Member Functions

std::string abridged () const
 
std::string abridgedMiddle () const
 
std::array< uint8_t, N > & asArray ()
 
std::array< uint8_t, N > const & asArray () const
 
bytes asBytes () const
 
auto begin () const -> typename std::array< uint8_t, N >::const_iterator
 
template<unsigned P, unsigned M>
FixedHash< M > bloomPart () const
 
void clear ()
 
bool contains (FixedHash const &_c) const
 
template<unsigned P, unsigned M>
bool containsBloom (FixedHash< M > const &_h)
 
uint8_t * data ()
 
uint8_t const * data () const
 
auto end () const -> typename std::array< uint8_t, N >::const_iterator
 
unsigned firstBitSet () const
 Returns the index of the first bit set to one, or size() * 8 if no bits are set.
 
 FixedHash ()
 Construct an empty hash.
 
 FixedHash (bytes const &_b, ConstructFromHashType _t=FailIfDifferent)
 Explicitly construct, copying from a byte array.
 
 FixedHash (bytesConstRef _b, ConstructFromHashType _t=FailIfDifferent)
 Explicitly construct, copying from a byte array.
 
template<unsigned M>
 FixedHash (FixedHash< M > const &_h, ConstructFromHashType _t=AlignLeft)
 Construct from another hash, filling with zeroes or cropping as necessary.
 
 FixedHash (std::string const &_s, ConstructFromStringType _t=FromHex, ConstructFromHashType _ht=FailIfDifferent)
 Explicitly construct, copying from a string.
 
 FixedHash (uint8_t const *_bs, ConstructFromPointerType)
 Explicitly construct, copying from a bytes in memory with given pointer.
 
 FixedHash (unsigned _u)
 Convert from unsigned.
 
std::string hex () const
 
 operator bool () const
 
bool operator!= (FixedHash const &_c) const
 
FixedHash operator& (FixedHash const &_c) const
 
FixedHashoperator&= (FixedHash const &_c)
 
FixedHashoperator++ ()
 
bool operator< (FixedHash const &_c) const
 
bool operator<= (FixedHash const &_c) const
 
bool operator== (FixedHash const &_c) const
 
bool operator== (FixedHash< 32 > const &_other) const
 Fast equality operator for h256.
 
bool operator> (FixedHash const &_c) const
 
bool operator>= (FixedHash const &_c) const
 
uint8_t & operator[] (unsigned _i)
 
uint8_t operator[] (unsigned _i) const
 
FixedHash operator^ (FixedHash const &_c) const
 
FixedHashoperator^= (FixedHash const &_c)
 
FixedHash operator| (FixedHash const &_c) const
 
FixedHashoperator|= (FixedHash const &_c)
 
FixedHash operator~ () const
 
template<class Engine >
void randomize (Engine &_eng)
 Populate with random data.
 
bytesRef ref ()
 
bytesConstRef ref () const
 
template<unsigned P, unsigned M>
FixedHashshiftBloom (FixedHash< M > const &_h)
 

Static Public Member Functions

static FixedHash random ()
 

Detailed Description

template<unsigned N>
class dev::FixedHash< N >

Fixed-size raw-byte array container type, with an API optimised for storing hashes.

Transparently converts to/from the corresponding arithmetic type; this will assume the data contained in the hash is big-endian.

Definition at line 52 of file FixedHash.h.

Member Enumeration Documentation

◆ anonymous enum

template<unsigned N>
anonymous enum

The size of the container.

Enumerator
size 

Definition at line 56 of file FixedHash.h.

◆ ConstructFromHashType

template<unsigned N>
enum dev::FixedHash::ConstructFromHashType

Method to convert from a string.

Enumerator
AlignLeft 
AlignRight 
FailIfDifferent 

Definition at line 65 of file FixedHash.h.

◆ ConstructFromPointerType

template<unsigned N>
enum dev::FixedHash::ConstructFromPointerType

A dummy flag to avoid accidental construction from pointer.

Enumerator
ConstructFromPointer 

Definition at line 59 of file FixedHash.h.

◆ ConstructFromStringType

template<unsigned N>
enum dev::FixedHash::ConstructFromStringType

Method to convert from a string.

Enumerator
FromHex 
FromBinary 

Definition at line 62 of file FixedHash.h.

Constructor & Destructor Documentation

◆ FixedHash() [1/7]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( )
inline

Construct an empty hash.

Definition at line 68 of file FixedHash.h.

Referenced by dev::FixedHash< N >::operator&(), dev::FixedHash< N >::operator^(), and dev::FixedHash< N >::operator|().

◆ FixedHash() [2/7]

template<unsigned N>
template<unsigned M>
dev::FixedHash< N >::FixedHash ( FixedHash< M > const &  _h,
ConstructFromHashType  _t = AlignLeft 
)
inlineexplicit

Construct from another hash, filling with zeroes or cropping as necessary.

Definition at line 72 of file FixedHash.h.

References dev::FixedHash< N >::AlignRight.

◆ FixedHash() [3/7]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( unsigned  _u)
inlineexplicit

Convert from unsigned.

Definition at line 81 of file FixedHash.h.

◆ FixedHash() [4/7]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( bytes const &  _b,
ConstructFromHashType  _t = FailIfDifferent 
)
inlineexplicit

Explicitly construct, copying from a byte array.

Definition at line 84 of file FixedHash.h.

References dev::FixedHash< N >::AlignRight, and dev::FixedHash< N >::FailIfDifferent.

◆ FixedHash() [5/7]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( bytesConstRef  _b,
ConstructFromHashType  _t = FailIfDifferent 
)
inlineexplicit

Explicitly construct, copying from a byte array.

Definition at line 100 of file FixedHash.h.

References dev::FixedHash< N >::AlignRight, dev::vector_ref< _T >::data(), dev::FixedHash< N >::FailIfDifferent, and dev::vector_ref< _T >::size().

Here is the call graph for this function:

◆ FixedHash() [6/7]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( uint8_t const *  _bs,
ConstructFromPointerType   
)
inlineexplicit

Explicitly construct, copying from a bytes in memory with given pointer.

Definition at line 116 of file FixedHash.h.

◆ FixedHash() [7/7]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( std::string const &  _s,
ConstructFromStringType  _t = FromHex,
ConstructFromHashType  _ht = FailIfDifferent 
)
inlineexplicit

Explicitly construct, copying from a string.

Definition at line 122 of file FixedHash.h.

Member Function Documentation

◆ abridged()

template<unsigned N>
std::string dev::FixedHash< N >::abridged ( ) const
inline
Returns
an abridged version of the hash as a user-readable hex string.

Definition at line 197 of file FixedHash.h.

References dev::FixedHash< N >::ref(), and dev::toHex().

Here is the call graph for this function:

◆ abridgedMiddle()

template<unsigned N>
std::string dev::FixedHash< N >::abridgedMiddle ( ) const
inline
Returns
a version of the hash as a user-readable hex string that leaves out the middle part.

Definition at line 200 of file FixedHash.h.

References dev::FixedHash< N >::ref(), and dev::toHex().

Here is the call graph for this function:

◆ asArray() [1/2]

template<unsigned N>
std::array< uint8_t, N > & dev::FixedHash< N >::asArray ( )
inline
Returns
a mutable reference to the object's data as an STL array.

Definition at line 230 of file FixedHash.h.

◆ asArray() [2/2]

template<unsigned N>
std::array< uint8_t, N > const & dev::FixedHash< N >::asArray ( ) const
inline
Returns
a constant reference to the object's data as an STL array.

Definition at line 233 of file FixedHash.h.

◆ asBytes()

template<unsigned N>
bytes dev::FixedHash< N >::asBytes ( ) const
inline
Returns
a copy of the object's data as a byte vector.

Definition at line 227 of file FixedHash.h.

References dev::FixedHash< N >::data().

Here is the call graph for this function:

◆ begin()

template<unsigned N>
auto dev::FixedHash< N >::begin ( ) const -> typename std::array<uint8_t, N>::const_iterator
inline
Returns
begin iterator.

Definition at line 221 of file FixedHash.h.

◆ bloomPart()

template<unsigned N>
template<unsigned P, unsigned M>
FixedHash< M > dev::FixedHash< N >::bloomPart ( ) const
inline

Definition at line 265 of file FixedHash.h.

References dev::FixedHash< N >::data(), and P.

Here is the call graph for this function:

◆ clear()

template<unsigned N>
void dev::FixedHash< N >::clear ( )
inline

Definition at line 302 of file FixedHash.h.

◆ contains()

template<unsigned N>
bool dev::FixedHash< N >::contains ( FixedHash< N > const &  _c) const
inline
Returns
true if all one-bits in _c are set in this object.

Definition at line 189 of file FixedHash.h.

Referenced by dev::FixedHash< N >::containsBloom().

◆ containsBloom()

template<unsigned N>
template<unsigned P, unsigned M>
bool dev::FixedHash< N >::containsBloom ( FixedHash< M > const &  _h)
inline

Definition at line 259 of file FixedHash.h.

References dev::FixedHash< N >::contains().

Here is the call graph for this function:

◆ data() [1/2]

template<unsigned N>
uint8_t * dev::FixedHash< N >::data ( )
inline
Returns
a mutable byte pointer to the object's data.

Definition at line 215 of file FixedHash.h.

Referenced by dev::FixedHash< N >::asBytes(), dev::FixedHash< N >::bloomPart(), dev::SecureFixedHash< T >::data(), dev::FixedHash< N >::operator==(), and dev::right160().

◆ data() [2/2]

template<unsigned N>
uint8_t const * dev::FixedHash< N >::data ( ) const
inline
Returns
a constant byte pointer to the object's data.

Definition at line 218 of file FixedHash.h.

◆ end()

template<unsigned N>
auto dev::FixedHash< N >::end ( ) const -> typename std::array<uint8_t, N>::const_iterator
inline
Returns
end iterator.

Definition at line 224 of file FixedHash.h.

◆ firstBitSet()

template<unsigned N>
unsigned dev::FixedHash< N >::firstBitSet ( ) const
inline

Returns the index of the first bit set to one, or size() * 8 if no bits are set.

Definition at line 287 of file FixedHash.h.

◆ hex()

template<unsigned N>
std::string dev::FixedHash< N >::hex ( ) const
inline
Returns
the hash as a user-readable hex string.

Definition at line 206 of file FixedHash.h.

References dev::FixedHash< N >::ref(), and dev::toHex().

Here is the call graph for this function:

◆ operator bool()

template<unsigned N>
dev::FixedHash< N >::operator bool ( ) const
inlineexplicit
Returns
true iff this is the empty hash.

Definition at line 129 of file FixedHash.h.

◆ operator!=()

template<unsigned N>
bool dev::FixedHash< N >::operator!= ( FixedHash< N > const &  _c) const
inline

Definition at line 136 of file FixedHash.h.

◆ operator&()

template<unsigned N>
FixedHash dev::FixedHash< N >::operator& ( FixedHash< N > const &  _c) const
inline

Definition at line 171 of file FixedHash.h.

References dev::FixedHash< N >::FixedHash().

Here is the call graph for this function:

◆ operator&=()

template<unsigned N>
FixedHash & dev::FixedHash< N >::operator&= ( FixedHash< N > const &  _c)
inline

Definition at line 165 of file FixedHash.h.

◆ operator++()

template<unsigned N>
FixedHash & dev::FixedHash< N >::operator++ ( )
inline

Definition at line 181 of file FixedHash.h.

References dev::FixedHash< N >::size.

◆ operator<()

template<unsigned N>
bool dev::FixedHash< N >::operator< ( FixedHash< N > const &  _c) const
inline

◆ operator<=()

template<unsigned N>
bool dev::FixedHash< N >::operator<= ( FixedHash< N > const &  _c) const
inline

Definition at line 147 of file FixedHash.h.

References dev::FixedHash< N >::operator<(), and dev::FixedHash< N >::operator==().

Referenced by dev::FixedHash< N >::operator>().

Here is the call graph for this function:

◆ operator==() [1/2]

template<unsigned N>
bool dev::FixedHash< N >::operator== ( FixedHash< N > const &  _c) const
inline

Definition at line 135 of file FixedHash.h.

Referenced by dev::FixedHash< N >::operator<=().

◆ operator==() [2/2]

bool dev::FixedHash< 32 >::operator== ( FixedHash< 32 > const &  _other) const
inline

Fast equality operator for h256.

Definition at line 480 of file FixedHash.h.

References dev::FixedHash< N >::data().

Here is the call graph for this function:

◆ operator>()

template<unsigned N>
bool dev::FixedHash< N >::operator> ( FixedHash< N > const &  _c) const
inline

Definition at line 148 of file FixedHash.h.

References dev::FixedHash< N >::operator<=().

Here is the call graph for this function:

◆ operator>=()

template<unsigned N>
bool dev::FixedHash< N >::operator>= ( FixedHash< N > const &  _c) const
inline

Definition at line 146 of file FixedHash.h.

References dev::FixedHash< N >::operator<().

Here is the call graph for this function:

◆ operator[]() [1/2]

template<unsigned N>
uint8_t & dev::FixedHash< N >::operator[] ( unsigned  _i)
inline
Returns
a particular byte from the hash.

Definition at line 192 of file FixedHash.h.

◆ operator[]() [2/2]

template<unsigned N>
uint8_t dev::FixedHash< N >::operator[] ( unsigned  _i) const
inline
Returns
a particular byte from the hash.

Definition at line 194 of file FixedHash.h.

◆ operator^()

template<unsigned N>
FixedHash dev::FixedHash< N >::operator^ ( FixedHash< N > const &  _c) const
inline

Definition at line 157 of file FixedHash.h.

References dev::FixedHash< N >::FixedHash().

Here is the call graph for this function:

◆ operator^=()

template<unsigned N>
FixedHash & dev::FixedHash< N >::operator^= ( FixedHash< N > const &  _c)
inline

Definition at line 151 of file FixedHash.h.

◆ operator|()

template<unsigned N>
FixedHash dev::FixedHash< N >::operator| ( FixedHash< N > const &  _c) const
inline

Definition at line 164 of file FixedHash.h.

References dev::FixedHash< N >::FixedHash().

Here is the call graph for this function:

◆ operator|=()

template<unsigned N>
FixedHash & dev::FixedHash< N >::operator|= ( FixedHash< N > const &  _c)
inline

Definition at line 158 of file FixedHash.h.

◆ operator~()

template<unsigned N>
FixedHash dev::FixedHash< N >::operator~ ( ) const
inline

Definition at line 172 of file FixedHash.h.

◆ random()

template<unsigned N>
static FixedHash dev::FixedHash< N >::random ( )
inlinestatic
Returns
a random valued object.

Definition at line 244 of file FixedHash.h.

References dev::FixedHash< N >::randomize().

Here is the call graph for this function:

◆ randomize()

template<unsigned N>
template<class Engine >
void dev::FixedHash< N >::randomize ( Engine &  _eng)
inline

Populate with random data.

Definition at line 237 of file FixedHash.h.

Referenced by dev::FixedHash< N >::random().

◆ ref() [1/2]

template<unsigned N>
bytesRef dev::FixedHash< N >::ref ( )
inline

◆ ref() [2/2]

template<unsigned N>
bytesConstRef dev::FixedHash< N >::ref ( ) const
inline
Returns
a constant byte vector_ref to the object's data.

Definition at line 212 of file FixedHash.h.

◆ shiftBloom()

template<unsigned N>
template<unsigned P, unsigned M>
FixedHash & dev::FixedHash< N >::shiftBloom ( FixedHash< M > const &  _h)
inline

Definition at line 253 of file FixedHash.h.


The documentation for this class was generated from the following file: