From acd6903b2174c6f29eccf4b7fdcc151c276d5c1d Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 2 Jul 2024 17:59:07 +0200 Subject: [PATCH] includes/std: Added crc8, crc16 and crc64 functions Fixes #226 --- includes/std/hash.pat | 44 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/includes/std/hash.pat b/includes/std/hash.pat index e6c3817..ca22da4 100644 --- a/includes/std/hash.pat +++ b/includes/std/hash.pat @@ -6,9 +6,37 @@ namespace auto std::hash { + /** + Calculates the CRC8 hash of the bytes inside of a given pattern + @param pattern The pattern to calculate the CRC8 hash of + @param init The CRC8 init value + @param poly The CRC8 polynomial + @param xorout The CRC8 XOR-Out value + @param reflect_in Whether or not the input bytes should be reflected + @param reflect_out Whether or not the output should be reflected + @return Calculated CRC8 hash + */ + fn crc8(ref auto pattern, u8 init, u8 poly, u8 xorout, bool reflect_in, bool reflect_out) { + return builtin::std::hash::crc8(pattern, init, poly, xorout, reflect_in, reflect_out); + }; + + /** + Calculates the CRC16 hash of the bytes inside of a given pattern + @param pattern The pattern to calculate the CRC16 hash of + @param init The CRC16 init value + @param poly The CRC16 polynomial + @param xorout The CRC16 XOR-Out value + @param reflect_in Whether or not the input bytes should be reflected + @param reflect_out Whether or not the output should be reflected + @return Calculated CRC16 hash + */ + fn crc16(ref auto pattern, u16 init, u16 poly, u16 xorout, bool reflect_in, bool reflect_out) { + return builtin::std::hash::crc16(pattern, init, poly, xorout, reflect_in, reflect_out); + }; + /** Calculates the CRC32 hash of the bytes inside of a given pattern - @param pattern The pattern to calculate the crc32 hash of + @param pattern The pattern to calculate the CRC32 hash of @param init The CRC32 init value @param poly The CRC32 polynomial @param xorout The CRC32 XOR-Out value @@ -20,4 +48,18 @@ namespace auto std::hash { return builtin::std::hash::crc32(pattern, init, poly, xorout, reflect_in, reflect_out); }; + /** + Calculates the CRC64 hash of the bytes inside of a given pattern + @param pattern The pattern to calculate the CRC64 hash of + @param init The CRC64 init value + @param poly The CRC64 polynomial + @param xorout The CRC64 XOR-Out value + @param reflect_in Whether or not the input bytes should be reflected + @param reflect_out Whether or not the output should be reflected + @return Calculated CRC64 hash + */ + fn crc64(ref auto pattern, u64 init, u64 poly, u64 xorout, bool reflect_in, bool reflect_out) { + return builtin::std::hash::crc64(pattern, init, poly, xorout, reflect_in, reflect_out); + }; + } \ No newline at end of file