File tree 1 file changed +50
-0
lines changed
SabreTools.Hashing/XxHash
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace SabreTools . Hashing . XxHash
4
+ {
5
+ internal class XxHash32
6
+ {
7
+ /// <summary>
8
+ /// The 32-bit seed to alter the hash result predictably.
9
+ /// </summary>
10
+ private uint _seed ;
11
+
12
+ /// <summary>
13
+ /// Internal xxHash32 state
14
+ /// </summary>
15
+ private readonly XXH32State _state ;
16
+
17
+ public XxHash32 ( uint seed = 0 )
18
+ {
19
+ _seed = seed ;
20
+ _state = new XXH32State ( ) ;
21
+ _state . Reset ( seed ) ;
22
+ }
23
+
24
+ /// <summary>
25
+ /// Reset the internal hashing state
26
+ /// </summary>
27
+ public void Reset ( )
28
+ {
29
+ _state . Reset ( _seed ) ;
30
+ }
31
+
32
+ /// <summary>
33
+ /// Hash a block of data and append it to the existing hash
34
+ /// </summary>
35
+ /// <param name="data">Byte array representing the data</param>
36
+ /// <param name="offset">Offset in the byte array to include</param>
37
+ /// <param name="length">Length of the data to hash</param>
38
+ public void TransformBlock ( byte [ ] data , int offset , int length )
39
+ => _state . Update ( data , offset , length ) ;
40
+
41
+ /// <summary>
42
+ /// Finalize the hash and return as a byte array
43
+ /// </summary>
44
+ public byte [ ] Finalize ( )
45
+ {
46
+ uint hash = _state . Digest ( ) ;
47
+ return BitConverter . GetBytes ( hash ) ;
48
+ }
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments