33public static partial class CrcHelper
44{
55 /// <summary>
6- /// CRC32 算法 。
6+ /// CRC32 算法实现 。
77 /// </summary>
8+ /// <remarks>
9+ /// Implementation of the CRC32 algorithm.
10+ /// </remarks>
811 internal sealed class Crc32
912 {
1013 private const int TableLength = 256 ;
@@ -15,32 +18,80 @@ internal sealed class Crc32
1518 private readonly uint [ ] m_Table ;
1619 private uint m_Hash ;
1720
21+ /// <summary>
22+ /// 初始化 <see cref="Crc32"/> 类的新实例,使用默认多项式和种子值。
23+ /// </summary>
24+ /// <remarks>
25+ /// Initializes a new instance of the <see cref="Crc32"/> class with default polynomial and seed values.
26+ /// </remarks>
1827 public Crc32 ( ) : this ( DefaultPolynomial , DefaultSeed )
1928 {
2029 }
2130
31+ /// <summary>
32+ /// 初始化 <see cref="Crc32"/> 类的新实例,使用指定的多项式和种子值。
33+ /// </summary>
34+ /// <remarks>
35+ /// Initializes a new instance of the <see cref="Crc32"/> class with the specified polynomial and seed values.
36+ /// </remarks>
37+ /// <param name="polynomial">用于CRC计算的多项式 / The polynomial used for CRC calculation</param>
38+ /// <param name="seed">用于CRC计算的初始种子值 / The initial seed value for CRC calculation</param>
2239 public Crc32 ( uint polynomial , uint seed )
2340 {
2441 m_Seed = seed ;
2542 m_Table = InitializeTable ( polynomial ) ;
2643 m_Hash = seed ;
2744 }
2845
46+ /// <summary>
47+ /// 重置哈希计算到初始状态。
48+ /// </summary>
49+ /// <remarks>
50+ /// Resets the hash computation to the initial state.
51+ /// </remarks>
2952 public void Initialize ( )
3053 {
3154 m_Hash = m_Seed ;
3255 }
3356
57+ /// <summary>
58+ /// 对字节数组的指定范围进行哈希计算。
59+ /// </summary>
60+ /// <remarks>
61+ /// Computes the hash for the specified range of the byte array.
62+ /// </remarks>
63+ /// <param name="bytes">要计算哈希的字节数组 / The byte array to compute the hash for</param>
64+ /// <param name="offset">起始偏移量 / The starting offset</param>
65+ /// <param name="length">要计算的长度 / The length to compute</param>
3466 public void HashCore ( byte [ ] bytes , int offset , int length )
3567 {
3668 m_Hash = CalculateHash ( m_Table , m_Hash , bytes , offset , length ) ;
3769 }
3870
71+ /// <summary>
72+ /// 获取最终计算得到的CRC32哈希值。
73+ /// </summary>
74+ /// <remarks>
75+ /// Gets the final computed CRC32 hash value.
76+ /// </remarks>
77+ /// <returns>CRC32哈希值 / The CRC32 hash value</returns>
3978 public uint HashFinal ( )
4079 {
4180 return ~ m_Hash ;
4281 }
4382
83+ /// <summary>
84+ /// 使用指定的查找表计算字节数组的哈希值。
85+ /// </summary>
86+ /// <remarks>
87+ /// Calculates the hash of a byte array using the specified lookup table.
88+ /// </remarks>
89+ /// <param name="table">CRC查找表 / The CRC lookup table</param>
90+ /// <param name="value">初始哈希值 / The initial hash value</param>
91+ /// <param name="bytes">要计算哈希的字节数组 / The byte array to compute the hash for</param>
92+ /// <param name="offset">起始偏移量 / The starting offset</param>
93+ /// <param name="length">要计算的长度 / The length to compute</param>
94+ /// <returns>计算得到的哈希值 / The computed hash value</returns>
4495 private static uint CalculateHash ( uint [ ] table , uint value , byte [ ] bytes , int offset , int length )
4596 {
4697 var last = offset + length ;
@@ -55,6 +106,14 @@ private static uint CalculateHash(uint[] table, uint value, byte[] bytes, int of
55106 return value ;
56107 }
57108
109+ /// <summary>
110+ /// 根据指定的多项式初始化CRC查找表。
111+ /// </summary>
112+ /// <remarks>
113+ /// Initializes the CRC lookup table based on the specified polynomial.
114+ /// </remarks>
115+ /// <param name="polynomial">用于生成查找表的多项式 / The polynomial used to generate the lookup table</param>
116+ /// <returns>初始化后的CRC查找表 / The initialized CRC lookup table</returns>
58117 private static uint [ ] InitializeTable ( uint polynomial )
59118 {
60119 var table = new uint [ TableLength ] ;
0 commit comments