diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/digest/old_crc/crc.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/digest/old_crc/crc.h')
-rw-r--r-- | library/cpp/digest/old_crc/crc.h | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/library/cpp/digest/old_crc/crc.h b/library/cpp/digest/old_crc/crc.h index e7da8967a8..4a3ce6d05e 100644 --- a/library/cpp/digest/old_crc/crc.h +++ b/library/cpp/digest/old_crc/crc.h @@ -7,19 +7,19 @@ #define CRC64INIT ULL(0xFFFFFFFFFFFFFFFF) // CCITT CRC-16 -inline ui16 crc16(const char* buf, size_t buflen, ui32 crcinit = CRC16INIT) { +inline ui16 crc16(const char* buf, size_t buflen, ui32 crcinit = CRC16INIT) { ui32 crc = 0xFFFF & ((crcinit >> 8) ^ (crcinit << 8)); - const char* end = buf + buflen; - extern const ui32* crctab16; + const char* end = buf + buflen; + extern const ui32* crctab16; while (buf < end) { crc = (crc >> 8) ^ crctab16[(crc ^ *buf) & 0xFF]; ++buf; } - return (ui16)(0xFFFF & ((crc >> 8) ^ (crc << 8))); + return (ui16)(0xFFFF & ((crc >> 8) ^ (crc << 8))); } -struct IdTR { +struct IdTR { Y_FORCE_INLINE static ui8 T(ui8 a) { return a; } @@ -27,31 +27,31 @@ struct IdTR { // CCITT CRC-32 template <class TR> -inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) { +inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) { ui32 crc = crcinit ^ 0xFFFFFFFF; - const char* end = buf + buflen; - extern const ui32* crctab32; + const char* end = buf + buflen; + extern const ui32* crctab32; - while (buf < end) { + while (buf < end) { crc = (crc >> 8) ^ crctab32[(crc ^ TR::T((ui8)*buf)) & 0xFF]; ++buf; } - + return crc ^ 0xFFFFFFFF; } -inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) { +inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) { return crc32<IdTR>(buf, buflen, crcinit); } -inline ui32 crc32(const void* buf, size_t buflen, ui32 crcinit = CRC32INIT) { - return crc32((const char*)buf, buflen, crcinit); +inline ui32 crc32(const void* buf, size_t buflen, ui32 crcinit = CRC32INIT) { + return crc32((const char*)buf, buflen, crcinit); } // Copyright (C) Sewell Development Corporation, 1994 - 1998. -inline ui64 crc64(const void* buf, size_t buflen, ui64 crcinit = CRC64INIT) { - const unsigned char* ptr = (const unsigned char*)buf; - extern const ui64* crctab64; +inline ui64 crc64(const void* buf, size_t buflen, ui64 crcinit = CRC64INIT) { + const unsigned char* ptr = (const unsigned char*)buf; + extern const ui64* crctab64; while (buflen--) { crcinit = crctab64[((crcinit >> 56) ^ *ptr++)] ^ (crcinit << 8); @@ -59,32 +59,32 @@ inline ui64 crc64(const void* buf, size_t buflen, ui64 crcinit = CRC64INIT) { return crcinit; } -namespace NCrcPrivate { - template <unsigned N> - struct TCrcHelper; - -#define DEF_CRC_FUNC(t) \ - template <> \ - struct TCrcHelper<t> { \ - static const ui##t Init = CRC##t##INIT; \ - static inline ui##t Crc(const void* buf, size_t buflen, ui##t crcinit) { \ - return crc##t((const char*)buf, buflen, crcinit); \ - } \ - }; - - DEF_CRC_FUNC(16) - DEF_CRC_FUNC(32) - DEF_CRC_FUNC(64) - -#undef DEF_CRC_FUNC -} - +namespace NCrcPrivate { + template <unsigned N> + struct TCrcHelper; + +#define DEF_CRC_FUNC(t) \ + template <> \ + struct TCrcHelper<t> { \ + static const ui##t Init = CRC##t##INIT; \ + static inline ui##t Crc(const void* buf, size_t buflen, ui##t crcinit) { \ + return crc##t((const char*)buf, buflen, crcinit); \ + } \ + }; + + DEF_CRC_FUNC(16) + DEF_CRC_FUNC(32) + DEF_CRC_FUNC(64) + +#undef DEF_CRC_FUNC +} + template <class T> -static inline T Crc(const void* buf, size_t len, T init) { - return (T)NCrcPrivate::TCrcHelper<8 * sizeof(T)>::Crc(buf, len, init); +static inline T Crc(const void* buf, size_t len, T init) { + return (T)NCrcPrivate::TCrcHelper<8 * sizeof(T)>::Crc(buf, len, init); } -template <class T> -static inline T Crc(const void* buf, size_t len) { - return Crc<T>(buf, len, (T)NCrcPrivate::TCrcHelper<8 * sizeof(T)>::Init); -} +template <class T> +static inline T Crc(const void* buf, size_t len) { + return Crc<T>(buf, len, (T)NCrcPrivate::TCrcHelper<8 * sizeof(T)>::Init); +} |