TARAXA
dev::FixedHash< N > Class Template Reference

#include <FixedHash.h>

Classes

struct  hash
 

Public Types

enum  { size = N }
 The size of the container. 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...
 
enum  ConstructFromHashType { AlignLeft , AlignRight , FailIfDifferent }
 Method to convert from a string. More...
 
using Arith = boost::multiprecision::number< boost::multiprecision::cpp_int_backend< N *8, N *8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > >
 The corresponding arithmetic type. More...
 

Public Member Functions

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

Static Public Member Functions

static FixedHash random ()
 

Private Attributes

std::array<::byte, N > m_data
 The binary data. More...
 

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.

Member Typedef Documentation

◆ Arith

template<unsigned N>
using dev::FixedHash< N >::Arith = boost::multiprecision::number<boost::multiprecision::cpp_int_backend< N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void> >

The corresponding arithmetic type.

Member Enumeration Documentation

◆ anonymous enum

template<unsigned N>
anonymous enum

The size of the container.

Enumerator
size 

◆ ConstructFromHashType

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

Method to convert from a string.

Enumerator
AlignLeft 
AlignRight 
FailIfDifferent 

◆ ConstructFromPointerType

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

A dummy flag to avoid accidental construction from pointer.

Enumerator
ConstructFromPointer 

◆ ConstructFromStringType

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

Method to convert from a string.

Enumerator
FromHex 
FromBinary 

Constructor & Destructor Documentation

◆ FixedHash() [1/8]

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

Construct an empty hash.

◆ FixedHash() [2/8]

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.

◆ FixedHash() [3/8]

template<unsigned N>
dev::FixedHash< N >::FixedHash ( Arith const &  _arith)
inline

Convert from the corresponding arithmetic type.

◆ FixedHash() [4/8]

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

Convert from unsigned.

◆ FixedHash() [5/8]

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

Explicitly construct, copying from a byte array.

◆ FixedHash() [6/8]

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

Explicitly construct, copying from a byte array.

◆ FixedHash() [7/8]

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

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

◆ FixedHash() [8/8]

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

Explicitly construct, copying from a string.

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.

◆ 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.

◆ asArray() [1/2]

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

◆ asArray() [2/2]

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

◆ asBytes()

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

◆ begin()

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

◆ bloomPart()

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

◆ clear()

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

◆ 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.

◆ containsBloom()

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

◆ data() [1/2]

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

◆ data() [2/2]

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

◆ end()

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

◆ 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.

◆ hex()

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

◆ isZero()

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

◆ operator Arith()

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

Convert to arithmetic type.

◆ operator bool()

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

◆ operator!=()

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

◆ operator&()

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

◆ operator&=()

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

◆ operator++()

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

◆ 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

◆ operator==() [1/2]

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

◆ operator==() [2/2]

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

Fast equality operator for h256.

◆ 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

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

◆ operator^()

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

◆ operator^=()

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

◆ operator|()

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

◆ operator|=()

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

◆ operator~()

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

◆ random()

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

◆ randomize()

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

Populate with random data.

◆ ref() [1/2]

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

◆ ref() [2/2]

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

◆ shiftBloom()

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

◆ toString()

template<unsigned N>
std::string dev::FixedHash< N >::toString ( ) const
inline

Member Data Documentation

◆ m_data

template<unsigned N>
std::array<::byte, N> dev::FixedHash< N >::m_data
private

The binary data.


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