aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/digest/old_crc/crc.h
diff options
context:
space:
mode:
authorsergey <sergey@yandex-team.ru>2022-02-10 16:47:29 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:29 +0300
commit5d8d1af4df7f9cd4acc021f069546c30677e7979 (patch)
tree07a39da188e8b418699f992f22d829a37a1411b2 /library/cpp/digest/old_crc/crc.h
parent32b231c8474a1ade4bdf776ade6a20341691d9d7 (diff)
downloadydb-5d8d1af4df7f9cd4acc021f069546c30677e7979.tar.gz
Restoring authorship annotation for <sergey@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/digest/old_crc/crc.h')
-rw-r--r--library/cpp/digest/old_crc/crc.h58
1 files changed, 29 insertions, 29 deletions
diff --git a/library/cpp/digest/old_crc/crc.h b/library/cpp/digest/old_crc/crc.h
index 4a3ce6d05e..f37394139d 100644
--- a/library/cpp/digest/old_crc/crc.h
+++ b/library/cpp/digest/old_crc/crc.h
@@ -1,45 +1,45 @@
#pragma once
-
+
#include <util/system/defaults.h>
-
-#define CRC16INIT 0
-#define CRC32INIT 0
-#define CRC64INIT ULL(0xFFFFFFFFFFFFFFFF)
-
-// CCITT CRC-16
+
+#define CRC16INIT 0
+#define CRC32INIT 0
+#define CRC64INIT ULL(0xFFFFFFFFFFFFFFFF)
+
+// CCITT CRC-16
inline ui16 crc16(const char* buf, size_t buflen, ui32 crcinit = CRC16INIT) {
- ui32 crc = 0xFFFF & ((crcinit >> 8) ^ (crcinit << 8));
+ ui32 crc = 0xFFFF & ((crcinit >> 8) ^ (crcinit << 8));
const char* end = buf + buflen;
extern const ui32* crctab16;
-
- while (buf < end) {
- crc = (crc >> 8) ^ crctab16[(crc ^ *buf) & 0xFF];
- ++buf;
- }
+
+ while (buf < end) {
+ crc = (crc >> 8) ^ crctab16[(crc ^ *buf) & 0xFF];
+ ++buf;
+ }
return (ui16)(0xFFFF & ((crc >> 8) ^ (crc << 8)));
-}
-
+}
+
struct IdTR {
Y_FORCE_INLINE static ui8 T(ui8 a) {
return a;
}
};
-// CCITT CRC-32
+// CCITT CRC-32
template <class TR>
inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) {
- ui32 crc = crcinit ^ 0xFFFFFFFF;
+ ui32 crc = crcinit ^ 0xFFFFFFFF;
const char* end = buf + buflen;
extern const ui32* crctab32;
-
+
while (buf < end) {
crc = (crc >> 8) ^ crctab32[(crc ^ TR::T((ui8)*buf)) & 0xFF];
- ++buf;
- }
-
- return crc ^ 0xFFFFFFFF;
-}
+ ++buf;
+ }
+ return crc ^ 0xFFFFFFFF;
+}
+
inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) {
return crc32<IdTR>(buf, buflen, crcinit);
}
@@ -48,17 +48,17 @@ 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.
+// 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;
-
+
while (buflen--) {
- crcinit = crctab64[((crcinit >> 56) ^ *ptr++)] ^ (crcinit << 8);
+ crcinit = crctab64[((crcinit >> 56) ^ *ptr++)] ^ (crcinit << 8);
}
- return crcinit;
-}
-
+ return crcinit;
+}
+
namespace NCrcPrivate {
template <unsigned N>
struct TCrcHelper;