diff options
author | Karl Berry <karl@freefriends.org> | 2008-05-15 16:12:48 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-05-15 16:12:48 +0000 |
commit | bd2d913a35df5a223eab385296046922ecdd1d4e (patch) | |
tree | c125f8fe4c2337ada9ee569ceb5c8f9cc4bccf37 /Build/source/utils/lzma/src/sdk/Common/CRC.cpp | |
parent | 93b3db7c8015cf9b3e4970fb154f91d87225c35a (diff) |
rename lzma-utils to lzma, since that is now the upstream name
git-svn-id: svn://tug.org/texlive/trunk@8161 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/lzma/src/sdk/Common/CRC.cpp')
-rw-r--r-- | Build/source/utils/lzma/src/sdk/Common/CRC.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Build/source/utils/lzma/src/sdk/Common/CRC.cpp b/Build/source/utils/lzma/src/sdk/Common/CRC.cpp new file mode 100644 index 00000000000..35e1a187517 --- /dev/null +++ b/Build/source/utils/lzma/src/sdk/Common/CRC.cpp @@ -0,0 +1,61 @@ +// Common/CRC.cpp + +#include "StdAfx.h" + +#include "CRC.h" + +static const UInt32 kCRCPoly = 0xEDB88320; + +UInt32 CCRC::Table[256]; + +void CCRC::InitTable() +{ + for (UInt32 i = 0; i < 256; i++) + { + UInt32 r = i; + for (int j = 0; j < 8; j++) + if (r & 1) + r = (r >> 1) ^ kCRCPoly; + else + r >>= 1; + CCRC::Table[i] = r; + } +} + +class CCRCTableInit +{ +public: + CCRCTableInit() { CCRC::InitTable(); } +} g_CRCTableInit; + +void CCRC::UpdateByte(Byte b) +{ + _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8); +} + +void CCRC::UpdateUInt16(UInt16 v) +{ + UpdateByte(Byte(v)); + UpdateByte(Byte(v >> 8)); +} + +void CCRC::UpdateUInt32(UInt32 v) +{ + for (int i = 0; i < 4; i++) + UpdateByte((Byte)(v >> (8 * i))); +} + +void CCRC::UpdateUInt64(UInt64 v) +{ + for (int i = 0; i < 8; i++) + UpdateByte((Byte)(v >> (8 * i))); +} + +void CCRC::Update(const void *data, size_t size) +{ + UInt32 v = _value; + const Byte *p = (const Byte *)data; + for (; size > 0 ; size--, p++) + v = Table[((Byte)(v)) ^ *p] ^ (v >> 8); + _value = v; +} |