1 // BZip2Crc.h 2 3 #ifndef __BZIP2_CRC_H 4 #define __BZIP2_CRC_H 5 6 #include "../../Common/MyTypes.h" 7 8 class CBZip2Crc 9 { 10 UInt32 _value; 11 static UInt32 Table[256]; 12 public: 13 static void InitTable(); _value(initVal)14 CBZip2Crc(UInt32 initVal = 0xFFFFFFFF): _value(initVal) {}; 15 void Init(UInt32 initVal = 0xFFFFFFFF) { _value = initVal; } UpdateByte(Byte b)16 void UpdateByte(Byte b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); } UpdateByte(unsigned int b)17 void UpdateByte(unsigned int b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); } GetDigest()18 UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } 19 }; 20 21 class CBZip2CombinedCrc 22 { 23 UInt32 _value; 24 public: CBZip2CombinedCrc()25 CBZip2CombinedCrc(): _value(0){}; Init()26 void Init() { _value = 0; } Update(UInt32 v)27 void Update(UInt32 v) { _value = ((_value << 1) | (_value >> 31)) ^ v; } GetDigest()28 UInt32 GetDigest() const { return _value ; } 29 }; 30 31 #endif 32