My Project: dht::Hash< N > Class Template Reference

My Project 3.7.7 C++ Distributed Hash Table

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
dht::Hash< N > Class Template Reference

`#include <infohash.h>`

## Public Types
using | T = std::array<uint8_t, N>
typedef T::iterator | iterator
typedef T::const_iterator | const_iterator

## Public Member Functions
constexpr | Hash (const uint8_t *h, size_t data_len)
constexpr | Hash (std::string_view hex)
| Hash (const msgpack::object &o)
constexpr const uint8_t * | data () const
uint8_t * | data ()
iterator | begin ()
const_iterator | cbegin () const
iterator | end ()
const_iterator | cend () const
constexpr bool | operator== (const Hash &h) const
constexpr bool | operator!= (const Hash &h) const
constexpr bool | operator< (const Hash &o) const
constexpr Hash | operator^ (const Hash &o) const
constexpr | operator bool () const
uint8_t & | operator[] (size_t index)
constexpr const uint8_t & | operator[] (size_t index) const
constexpr int | lowbit () const
constexpr int | xorCmp (const Hash &id1, const Hash &id2) const
constexpr bool | getBit (unsigned nbit) const
void | setBit (unsigned nbit, bool b)
double | toFloat () const
std::string_view | to_view () const
const char * | to_c_str () const
std::string | toString () const
template<typename Packer>
void | msgpack_pack (Packer &pk) const
void | msgpack_unpack (msgpack::object o)
template<typename Rd>
Hash< N > | getRandom (Rd &rdev)

## Static Public Member Functions
static constexpr size_t | size () noexcept
static constexpr Hash | zero () noexcept
static int | cmp (const Hash &id1, const Hash &id2)
static constexpr unsigned | commonBits (const Hash &id1, const Hash &id2)
static Hash | get (std::string_view data)
static Hash | get (const std::vector< uint8_t > &data)
template<size_t H>
static Hash | get (const Hash< H > &o)
static Hash | get (const uint8_t *data, size_t data_len)
static Hash | getRandom ()
template<typename Rd>
static Hash | getRandom (Rd &)

## Friends
template<size_t M>
std::ostream & | operator<< (std::ostream &s, const Hash< M > &h)
template<size_t M>
std::istream & | operator>> (std::istream &s, Hash< M > &h)

## Detailed Description

template<size_t N>
class dht::Hash< N >

Represents an Hash, a byte array of N bytes. Hashes identify nodes and values in the Dht.

Definition at line 49 of file infohash.h.

## Member Typedef Documentation

## ◆ const_iterator

template<size_t N>

typedef T::const_iterator dht::Hash< N >::const_iterator

Definition at line 54 of file infohash.h.

## ◆ iterator

template<size_t N>

typedef T::iterator dht::Hash< N >::iterator

Definition at line 53 of file infohash.h.

## ◆ T

template<size_t N>

using dht::Hash< N >::T = std::array<uint8_t, N>

Definition at line 52 of file infohash.h.

## Constructor & Destructor Documentation

## ◆ Hash() [1/4]

template<size_t N>

dht::Hash< N >::Hash | ( |  | ) |
| inlineconstexprnoexcept

Definition at line 56 of file infohash.h.

## ◆ Hash() [2/4]

template<size_t N>

dht::Hash< N >::Hash | ( | const uint8_t * | h,
|  | size_t | data_len )
| inlineconstexpr

Definition at line 59 of file infohash.h.

## ◆ Hash() [3/4]

template<size_t N>

dht::Hash< N >::Hash | ( | std::string_view | hex | ) |
| inlineexplicitconstexpr

Constructor from an hexadecimal string (without "0x"). hex must be at least 2.N characters long. If too long, only the first 2.N characters are read.

Definition at line 67 of file infohash.h.

## ◆ Hash() [4/4]

template<size_t N>

dht::Hash< N >::Hash | ( | const msgpack::object & | o | ) |
| inline

Definition at line 71 of file infohash.h.

## Member Function Documentation

## ◆ begin()

template<size_t N>

iterator dht::Hash< N >::begin | ( |  | ) |
| inline

Definition at line 76 of file infohash.h.

## ◆ cbegin()

template<size_t N>

const_iterator dht::Hash< N >::cbegin | ( |  | ) | const
| inline

Definition at line 77 of file infohash.h.

## ◆ cend()

template<size_t N>

const_iterator dht::Hash< N >::cend | ( |  | ) | const
| inline

Definition at line 79 of file infohash.h.

## ◆ cmp()

template<size_t N>

int dht::Hash< N >::cmp | ( | const Hash< N > & | id1,
|  | const Hash< N > & | id2 )
| inlinestatic

Definition at line 156 of file infohash.h.

## ◆ commonBits()

template<size_t N>

constexpr unsigned dht::Hash< N >::commonBits | ( | const Hash< N > & | id1,
|  | const Hash< N > & | id2 )
| inlinestaticconstexpr

Find how many bits two ids have in common.

Definition at line 162 of file infohash.h.

## ◆ data() [1/2]

template<size_t N>

uint8_t * dht::Hash< N >::data | ( |  | ) |
| inline

Definition at line 75 of file infohash.h.

## ◆ data() [2/2]

template<size_t N>

const uint8_t * dht::Hash< N >::data | ( |  | ) | const
| inlineconstexpr

Definition at line 74 of file infohash.h.

## ◆ end()

template<size_t N>

iterator dht::Hash< N >::end | ( |  | ) |
| inline

Definition at line 78 of file infohash.h.

## ◆ get() [1/4]

template<size_t N>
template<size_t H>

Hash dht::Hash< N >::get | ( | const Hash< H > & | o | ) |
| inlinestatic

Definition at line 225 of file infohash.h.

## ◆ get() [2/4]

template<size_t N>

Hash dht::Hash< N >::get | ( | const std::vector< uint8_t > & | data | ) |
| inlinestatic

Definition at line 222 of file infohash.h.

## ◆ get() [3/4]

template<size_t N>

Hash dht::Hash< N >::get | ( | const uint8_t * | data,
|  | size_t | data_len )
| inlinestatic

Computes the hash from a given data buffer of size data_len.

Definition at line 233 of file infohash.h.

## ◆ get() [4/4]

template<size_t N>

Hash dht::Hash< N >::get | ( | std::string_view | data | ) |
| inlinestatic

Definition at line 220 of file infohash.h.

## ◆ getBit()

template<size_t N>

bool dht::Hash< N >::getBit | ( | unsigned | nbit | ) | const
| inlineconstexpr

Definition at line 197 of file infohash.h.

## ◆ getRandom() [1/2]

template<size_t N>

Hash< N > dht::Hash< N >::getRandom | ( |  | ) |
| static

Definition at line 346 of file infohash.h.

## ◆ getRandom() [2/2]

template<size_t N>
template<typename Rd>

Hash< N > dht::Hash< N >::getRandom | ( | Rd & | rdev | ) |

Definition at line 360 of file infohash.h.

## ◆ lowbit()

template<size_t N>

int dht::Hash< N >::lowbit | ( |  | ) | const
| inlineconstexpr

Find the lowest 1 bit in an id. Result will allways be lower than 8*N

Definition at line 141 of file infohash.h.

## ◆ msgpack_pack()

template<size_t N>
template<typename Packer>

void dht::Hash< N >::msgpack_pack | ( | Packer & | pk | ) | const
| inline

Definition at line 258 of file infohash.h.

## ◆ msgpack_unpack()

template<size_t N>

void dht::Hash< N >::msgpack_unpack | ( | msgpack::object | o | ) |
| inline

Definition at line 264 of file infohash.h.

## ◆ operator bool()

template<size_t N>

dht::Hash< N >::operator bool | ( |  | ) | const
| inlineexplicitconstexpr

Definition at line 115 of file infohash.h.

## ◆ operator!=()

template<size_t N>

bool dht::Hash< N >::operator!= | ( | const Hash< N > & | h | ) | const
| inlineconstexpr

Definition at line 95 of file infohash.h.

## ◆ operator<()

template<size_t N>

bool dht::Hash< N >::operator< | ( | const Hash< N > & | o | ) | const
| inlineconstexpr

Definition at line 97 of file infohash.h.

## ◆ operator==()

template<size_t N>

bool dht::Hash< N >::operator== | ( | const Hash< N > & | h | ) | const
| inlineconstexpr

Definition at line 83 of file infohash.h.

## ◆ operator[]() [1/2]

template<size_t N>

uint8_t & dht::Hash< N >::operator[] | ( | size_t | index | ) |
| inline

Definition at line 134 of file infohash.h.

## ◆ operator[]() [2/2]

template<size_t N>

const uint8_t & dht::Hash< N >::operator[] | ( | size_t | index | ) | const
| inlineconstexpr

Definition at line 135 of file infohash.h.

## ◆ operator^()

template<size_t N>

Hash dht::Hash< N >::operator^ | ( | const Hash< N > & | o | ) | const
| inlineconstexpr

Definition at line 106 of file infohash.h.

## ◆ setBit()

template<size_t N>

void dht::Hash< N >::setBit | ( | unsigned | nbit,
|  | bool | b )
| inline

Definition at line 204 of file infohash.h.

## ◆ size()

template<size_t N>

constexpr size_t dht::Hash< N >::size | ( |  | ) |
| inlinestaticconstexprnoexcept

Definition at line 73 of file infohash.h.

## ◆ to_c_str()

template<size_t N>

const char * dht::Hash< N >::to_c_str | ( |  | ) | const

Definition at line 421 of file infohash.h.

## ◆ to_view()

template<size_t N>

std::string_view dht::Hash< N >::to_view | ( |  | ) | const
| inline

Returns view to thread-allocated memory, only valid until the next call to this function.

Definition at line 252 of file infohash.h.

## ◆ toFloat()

template<size_t N>

double dht::Hash< N >::toFloat | ( |  | ) | const
| inline

Definition at line 211 of file infohash.h.

## ◆ toString()

template<size_t N>

std::string dht::Hash< N >::toString | ( |  | ) | const

Definition at line 435 of file infohash.h.

## ◆ xorCmp()

template<size_t N>

int dht::Hash< N >::xorCmp | ( | const Hash< N > & | id1,
|  | const Hash< N > & | id2 ) const
| inlineconstexpr

Determine whether id1 or id2 is closer to this

Definition at line 185 of file infohash.h.

## ◆ zero()

template<size_t N>

constexpr Hash dht::Hash< N >::zero | ( |  | ) |
| inlinestaticconstexprnoexcept

Definition at line 81 of file infohash.h.

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

- /home/noptrix/ba/blackarch/packages/opendht-c/src/opendht/include/opendht/infohash.h