OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
simple_checksum.cpp File Reference
#include <cstdint>
#include <cstring>
#include <cmath>
#include <limits>

Go to the source code of this file.

Macros

#define POLYNOMIAL   0xEDB88320

Functions

void init_crc32_table (uint32_t *crc32_table)
void simple_checksum (const double *vector, const int *length, double *hash)

Macro Definition Documentation

◆ POLYNOMIAL

#define POLYNOMIAL   0xEDB88320

Definition at line 32 of file simple_checksum.cpp.

Function Documentation

◆ init_crc32_table()

void init_crc32_table ( uint32_t * crc32_table)

Definition at line 34 of file simple_checksum.cpp.

34 {
35 for (uint32_t i = 0; i < 256; i++) {
36 uint32_t crc = i;
37 for (uint32_t j = 0; j < 8; j++) {
38 crc = (crc >> 1) ^ (POLYNOMIAL * (crc & 1));
39 }
40 crc32_table[i] = crc;
41 }
42}
#define POLYNOMIAL

◆ simple_checksum()

void simple_checksum ( const double * vector,
const int * length,
double * hash )

Definition at line 43 of file simple_checksum.cpp.

43 {
44 uint32_t crc32_table[256];
45 uint32_t crc = 0xFFFFFFFF; // initial value
46
47 init_crc32_table(crc32_table);
48
49 for (size_t i = 0; i < *length; i++) {
50 uint64_t value = *(uint64_t*)&vector[i]; // Conversion of double to uint64_t
51
52 for (size_t j = 0; j < sizeof(value); j++) {
53 uint8_t byte = value & 0xFF; // byte extraction
54 crc = (crc >> 8) ^ crc32_table[(crc ^ byte) & 0xFF];
55 value >>= 8; // shift for the next byte
56 }
57 }
58 *hash = (double) (crc ^ 0xFFFFFFFF);
59 }
void init_crc32_table(uint32_t *crc32_table)