CRC accumulator.
More...
#include <CRC.h>
|
| CRC () |
| Constructor. More...
|
|
template<typename P > |
| CRC (P param) |
| Constructor. More...
|
|
CRC< T > & | accumulate (std::string const &str) |
| Accumulates a string as a series of bytes. More...
|
|
CRC< T > & | accumulate (char const *sz) |
| Accumulates a C-string as a series of bytes. More...
|
|
template<typename P > |
CRC< T > & | accumulate (std::vector< P > const &v) |
| Accumulates a vector as a series of contained objects. More...
|
|
template<typename P > |
CRC< T > & | accumulate (P value) |
| Accumulates an arithmetic value. More...
|
|
CRC< T > & | accumulate (char const *data, size_t offset, size_t length) |
| Accumulates arbitraty bytes. More...
|
|
template<typename Iter > |
CRC< T > & | accumulate (const Iter first, const Iter last) |
| Accumulates a range of elements. More...
|
|
T | get () const |
| Returns the CRC value resulting from the accumulation. More...
|
|
template<typename T>
class shlublu::CRC< T >
CRC accumulator.
Handled types are shlublu::crc32_t
and shlublu::crc64_t
, which are both unsigned integers. Shorthands for these types are shlublu::CRC32
and shlublu::CRC64
.
◆ CRC() [1/2]
Constructor.
Initializes to zero.
◆ CRC() [2/2]
template<typename T >
template<typename P >
Constructor.
Accumulates the passed object.
- Parameters
-
param | initial object to accumulate. |
◆ accumulate() [1/6]
Accumulates a string as a series of bytes.
- Parameters
-
str | the string to accumulate |
- Returns
- a reference to this CRC object
◆ accumulate() [2/6]
Accumulates a C-string as a series of bytes.
- Parameters
-
sz | the C-string to accumulate |
- Returns
- a reference to this CRC object
◆ accumulate() [3/6]
template<typename T >
template<typename P >
Accumulates a vector as a series of contained objects.
- Parameters
-
v | the vector to accumulate |
- Returns
- a reference to this CRC object
◆ accumulate() [4/6]
template<typename T >
template<typename P >
Accumulates an arithmetic value.
Eligibility of the parameter is evaluated at compile-time by std::is_arithmetic<P>
.
- Parameters
-
value | the value to accumulate |
- Returns
- a reference to this CRC object
- See also
- std::is_arithmetic
◆ accumulate() [5/6]
template<typename T >
CRC<T>& shlublu::CRC< T >::accumulate |
( |
char const * |
data, |
|
|
size_t |
offset, |
|
|
size_t |
length |
|
) |
| |
|
inline |
Accumulates arbitraty bytes.
This method can be used to accumulate an arbitrary object for which no other method applies. It is up to the developper to ensure such an accumulation is valid, consistent and repeatable.
- Parameters
-
data | data as an array of char |
offset | the offset to start accumulation from |
length | the number of bytes to accumulate |
- Returns
- a reference to this CRC object
Example
class X
{
public:
X(int a, double b) : mA(a), mB(b) {}
private:
int mA;
double mB;
};
const X x(42, 42.0);
crc.accumulate(reinterpret_cast<char const*>(&x), 0, sizeof(int));
◆ accumulate() [6/6]
template<typename T >
template<typename Iter >
CRC<T>& shlublu::CRC< T >::accumulate |
( |
const Iter |
first, |
|
|
const Iter |
last |
|
) |
| |
|
inline |
Accumulates a range of elements.
The range is delimited by [first,last).
- Parameters
-
first | iterator that begins the range |
last | iterator that ends the range |
- Returns
- a reference to this CRC object
Example
const std::vector<int> v{ { 1, 2, 3, 4 } };
crc.accumulate(v.begin(), v.end());
◆ get()
Returns the CRC value resulting from the accumulation.
- Returns
- the CRC value
The documentation for this class was generated from the following file:
- include/shlublu/hash/CRC.h