xref: /aosp_15_r20/external/lzma/CPP/7zip/Compress/BZip2Crc.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // BZip2Crc.h
2 
3 #ifndef ZIP7_INC_BZIP2_CRC_H
4 #define ZIP7_INC_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 b)17   void UpdateByte(unsigned 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