ALBA
albaDataChecksum.h
Go to the documentation of this file.
1/*=========================================================================
2 Program: Multimod Application Framework RELOADED
3 Module: $RCSfile: albaDataChecksum.h,v $
4 Language: C++
5 Date: $Date: 2009-10-30 07:24:41 $
6 Version: $Revision: 1.1.2.2 $
7 Authors: Josef Kohout (Josef.Kohout *AT* beds.ac.uk)
8 ==========================================================================
9 Copyright (c) 2008 University of Bedfordshire (www.beds.ac.uk)
10 See the COPYINGS file for license details
11 =========================================================================
12 Computes checksum of general data that can be used to detect,
13 whether something important has changed (something has changed
14 as timestamp is different). For instance, a VTK filter may
15 compute something internally from a scalar field of input data
16 and reuse it as long as this field does not change, no matter
17 whether any other field has changed (which would mean that the
18 input has a different timestamp).
19
20*/
21
22#ifndef albaDataChecksum_h__
23#define albaDataChecksum_h__
30{
31public:
33 inline static unsigned long Adler32Checksum(unsigned char* data, int len);
34
36 inline static unsigned long CombineAdler32Checksums(unsigned long chcksum1, unsigned long chcksum2);
37};
38
39#pragma region Inlines
40//----------------------------------------------------------------------------------
41//Computes Adler32 checksum for the given data
42inline /*static*/ unsigned long albaDataChecksum::Adler32Checksum(unsigned char* data, int len)
43//----------------------------------------------------------------------------------
44{
45 unsigned long a = 1, b = 0;
46 while (len != 0)
47 {
48 a = (a + *data++) % 65521;
49 b = (b + a) % 65521;
50
51 len--;
52 }
53
54 return (b << 16) | a;
55}
56
57//----------------------------------------------------------------------------------
58//Combines two checksums computed by Adler32Checksum to give a new one */
59inline /*static*/unsigned long albaDataChecksum::CombineAdler32Checksums(
60 unsigned long chcksum1, unsigned long chcksum2)
61 //----------------------------------------------------------------------------------
62{
63 unsigned long a = ((chcksum1 & 0xFFFF) + (chcksum2 & 0xFFFF)) % 65521;
64 unsigned long b = ((chcksum1 >> 16) + (chcksum2 >> 16)) % 65521;
65
66 return (b << 16) | a;
67}
68#pragma endregion Inlines
69
70
71
72#endif // albaDataChecksum_h__
class name: albaDataChecksum Can compute Adler checksum for a given data, and combine two adler check...
static unsigned long Adler32Checksum(unsigned char *data, int len)
Computes Adler32 checksum for the given data.
static unsigned long CombineAdler32Checksums(unsigned long chcksum1, unsigned long chcksum2)
Combines two checksums computed by Adler32Checksum to give a new one.