OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
adler32.cpp File Reference
#include <cstddef>
#include <cstdint>
#include <limits>
#include <cmath>
#include <iostream>

Go to the source code of this file.

Functions

void cpp_adler32 (const unsigned char *data, int len, int *result)
void test_cpp_adler32 ()

Variables

constexpr uint32_t ROOT = 65521

Function Documentation

◆ 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;
34 b = (b + a) % ROOT;
35 }
36 // cast the result into an int (32 bits)
37 uint32_t r = (b << 16) | a;
38 *result = *reinterpret_cast<int32_t*>(&r);
39}
constexpr uint32_t ROOT
Definition adler32.cpp:28

◆ 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 // find the next representable value of data2[50]
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 //print the two values
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)
Definition adler32.cpp:30

Variable Documentation

◆ ROOT

uint32_t ROOT = 65521
constexpr

Definition at line 28 of file adler32.cpp.