scclib
Stable Cloud Computing C++ Library
Public Member Functions | List of all members
scc::encode::Adler32 Class Reference

Adler-32 checksum allowing rolling calculation. More...

#include <adler32.h>

Public Member Functions

 Adler32 ()
 Construct with initialized value.
 
 Adler32 (const void *loc, int len)
 Construct with initial value. More...
 
 operator uint32_t () const
 
uint32_t val () const
 
int size ()
 Size of the current window.
 
uint32_t reset ()
 Reset the checksum.
 
uint32_t reset (const void *loc, int len)
 Reset the checksum, and update with initial value. More...
 
uint32_t update (const void *, int)
 Update the checksum with buffer contents. More...
 
uint32_t combine (const Adler32 &)
 
uint32_t rotate (unsigned char, unsigned char)
 Update the checksum with next byte. More...
 
uint32_t rotate (char xrem, char xadd)
 

Detailed Description

Adler-32 checksum allowing rolling calculation.

Rolling calculation allows very fast calculations within a sliding window, removing the overhead of recalculating for the entire window size.

Test example from scclib/encode/unittest/adler32.cc

static string test =
"ljpoaweu9uwat7a9g0ujaW219U0U;DSJGEOPUJGAfPVAPUAS:FGJALGJ7804-85," // 64 bytes
"G;AKGPTG[ASIGSFDAS[DFSAPDFJASPFJSPADFJPAJPGAJSGSAGJAPJGAPJGPOIOO"; // 64 bytes
static uint32_t all_ad = 0xf9932612; // all bytes
static uint32_t last64_ad = 0x583e1280; // last 64 bytes
Adler32 ad;
size_t sz = test.size(); // 128 bytes
ad.reset(test.data(), sz/2); // first 64 bytes, sets window size to 64
ASSERT_EQ(ad.size(), 64);
// rolling 64 byte window, will calculate the checksum at each 64 byte window
for (size_t i = 0; i < 64; i++)
{
ad.rotate(test[i], test[64+i]); // first byte is 0-63, last is 64-127
}
ASSERT_EQ(ad, last64_ad); // end up with the last 64 bytes checksum
Adler32()
Construct with initialized value.
Definition: adler32.h:38
Examples
scclib/encode/unittest/adler32.cc.

Definition at line 32 of file adler32.h.

Constructor & Destructor Documentation

◆ Adler32()

scc::encode::Adler32::Adler32 ( const void *  loc,
int  len 
)
inline

Construct with initial value.

Parameters
locBuffer location.
lenBuffer size.

Definition at line 43 of file adler32.h.

Member Function Documentation

◆ reset()

uint32_t scc::encode::Adler32::reset ( const void *  loc,
int  len 
)
inline

Reset the checksum, and update with initial value.

Parameters
locBuffer location.
lenBuffer size. Window length is set to len.

Definition at line 72 of file adler32.h.

◆ rotate()

uint32_t Adler32::rotate ( unsigned char  xrem,
unsigned char  xadd 
)

Update the checksum with next byte.

Usable for a "rolling window" checksum.

For example for bytes 01234 with checksum ch1, calling rotate('0', '5') will produce a checksum ad2 on bytes 12345.

Parameters
xremByte to rotate out (first in old window)
xaddByte to rotate in (last in new window)

see https://openresearch-repository.anu.edu.au/bitstream/1885/40765/3/TR-CS-96-05.pdf

Definition at line 36 of file adler32.cc.

◆ update()

uint32_t Adler32::update ( const void *  loc,
int  len 
)

Update the checksum with buffer contents.

Parameters
locBuffer location.
lenBuffer size. Window length is increased by len.

Definition at line 7 of file adler32.cc.


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