4#ifndef GREM_CORE_FORMATS_CRC32_HPP
5#define GREM_CORE_FORMATS_CRC32_HPP
24 for (
size_t i = 128; i != 0; i >>= 1) {
25 crc32 = (crc32 >> 1) ^ ((crc32 & 1) ? 0xEDB88320 : 0);
26 for (
size_t j = 0; j < 256; j += i * 2) {
27 result[i + j] = crc32 ^ result[j];
34 constexpr CRC32() noexcept = default;
36 constexpr explicit
CRC32(uint32_t value) noexcept
47 constexpr explicit operator uint32_t() const noexcept {
55 for (
const byte byte : bytes) {
56 value = (value >> 8) ^ CRC_TABLE[(value ^
static_cast<uint32_t
>(bit_cast<uint8_t>(
byte))) & 0xFF];
63 for (
const char ch : chars) {
64 value = (value >> 8) ^ CRC_TABLE[(value ^
static_cast<uint32_t
>(bit_cast<uint8_t>(ch))) & 0xFF];
87 template <
typename Stream>
89 return stream << crc32.value;
92 template <
typename Stream>
94 return stream >> crc32.value;
106 return hasher(
static_cast<uint32_t
>(crc32));
110 std::hash<uint32_t> hasher;
friend constexpr CRC32 operator+(CRC32 a, Span< const byte > bytes) noexcept
Definition CRC32.hpp:79
friend constexpr Stream & operator>>(Stream &stream, CRC32 &crc32)
Definition CRC32.hpp:93
constexpr CRC32 & operator+=(StringView chars) noexcept
Definition CRC32.hpp:74
constexpr CRC32(StringView chars) noexcept
Definition CRC32.hpp:43
constexpr void append(StringView chars) noexcept
Definition CRC32.hpp:61
constexpr CRC32 & operator+=(Span< const byte > bytes) noexcept
Definition CRC32.hpp:69
friend constexpr Stream & operator<<(Stream &stream, CRC32 crc32)
Definition CRC32.hpp:88
constexpr CRC32() noexcept=default
friend constexpr CRC32 operator+(CRC32 a, StringView chars) noexcept
Definition CRC32.hpp:83
constexpr bool operator==(const CRC32 &) const noexcept=default
constexpr CRC32(Span< const byte > bytes) noexcept
Definition CRC32.hpp:39
constexpr void append(Span< const byte > bytes) noexcept
Definition CRC32.hpp:53
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
std::size_t operator()(const grem::CRC32 &crc32) const
Definition CRC32.hpp:105