#include <cstddef>
#include <cstdint>
#include <limits>
#include <cmath>
#include <iostream>
Go to the source code of this file.
|
| constexpr uint32_t | ROOT = 65521 |
◆ cpp_adler32()
| void cpp_adler32 |
( |
const unsigned char * | data, |
|
|
int | len, |
|
|
int * | result ) |
Definition at line 30 of file adler32.cpp.
30 {
31 uint32_t a = 1, b = 0;
32 for (size_t i = 0; i < len; ++i) {
33 a = (a + data[i]) %
ROOT;
35 }
36
37 uint32_t
r = (b << 16) | a;
38 *result = *
reinterpret_cast<int32_t*
>(&
r);
39}
◆ test_cpp_adler32()
| void test_cpp_adler32 |
( |
| ) |
|
Definition at line 44 of file adler32.cpp.
45{
46 double * data = new double[100];
47 double * data2 = new double[100];
48
49 for (int i = 0; i < 100; ++i) {
50 data[i] = i;
51 data2[i] = i;
52 }
53
54
55 data2[50] = std::nextafter(data2[50], std::numeric_limits<double>::max());
56
57 int result1, result2;
58 cpp_adler32(
reinterpret_cast<unsigned char*
>(data), 100 *
sizeof(
double), &result1);
59 cpp_adler32(
reinterpret_cast<unsigned char*
>(data2), 100 *
sizeof(
double), &result2);
60
61 std::cout << "result1: " << result1 << std::endl;
62 std::cout << "result2: " << result2 << std::endl;
63
64}
void cpp_adler32(const unsigned char *data, int len, int *result)
◆ ROOT