diff options
| author | Léo Lam <leo@leolam.fr> | 2022-01-03 01:26:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-03 01:26:59 +0100 |
| commit | 5953c55075338f1d2b5d71f5ad8b883888ef11f1 (patch) | |
| tree | 97dd6166bb5e8aed19873d3512b90fa74dfb4850 /Source/Core/Common/Hash.cpp | |
| parent | f6883a08830158e5ae768b633d69bb504c9e7e3c (diff) | |
| parent | 3d5b46615cfc6d238075a9a1666c29f6f54decbe (diff) | |
Merge pull request #10271 from Pokechu22/hash.h-merge
Merge CRC32.h into Hash.h and remove MD5.h
Diffstat (limited to 'Source/Core/Common/Hash.cpp')
| -rw-r--r-- | Source/Core/Common/Hash.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp index d0b05ec7b6..62b56bc82c 100644 --- a/Source/Core/Common/Hash.cpp +++ b/Source/Core/Common/Hash.cpp @@ -5,6 +5,8 @@ #include <algorithm> #include <cstring> +#include <zlib.h> + #include "Common/BitUtils.h" #include "Common/CPUDetect.h" #include "Common/CommonFuncs.h" @@ -529,4 +531,28 @@ void SetHash64Function() ptrHashFunction = &GetMurmurHash3; } } + +u32 ComputeCRC32(std::string_view data) +{ + return ComputeCRC32(reinterpret_cast<const u8*>(data.data()), static_cast<u32>(data.size())); +} + +u32 ComputeCRC32(const u8* ptr, u32 length) +{ + return UpdateCRC32(StartCRC32(), ptr, length); +} + +u32 StartCRC32() +{ + return crc32(0L, Z_NULL, 0); +} + +u32 UpdateCRC32(u32 crc, const u8* ptr, u32 length) +{ + static_assert(std::is_same_v<const u8*, const Bytef*>); + static_assert(std::is_same_v<u32, uInt>); + // Use zlib's crc32 implementation to compute the hash + // crc32_z (which takes a size_t) would be better, but it isn't available on Android + return crc32(crc, ptr, length); +} } // namespace Common |
