File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ local ffi = require (" ffi" )
2+ require " ffi/xxhash_h"
3+
4+ local xxhash = ffi .loadlib (" xxhash" , " 0" )
5+
6+ local Hashoir = {}
7+
8+ function Hashoir :new ()
9+ local o = {}
10+ setmetatable (o , self )
11+ self .__index = self
12+ o .hs = ffi .gc (xxhash .XXH3_createState (), xxhash .XXH3_freeState )
13+ assert (o .hs ~= nil )
14+ xxhash .XXH3_64bits_reset (o .hs )
15+ return o
16+ end
17+
18+ function Hashoir :free ()
19+ xxhash .XXH3_freeState (ffi .gc (self .hs , nil ))
20+ self .hs = nil
21+ end
22+
23+ function Hashoir :reset ()
24+ xxhash .XXH3_64bits_reset (self .hs )
25+ return self
26+ end
27+
28+ function Hashoir :update (ptr , len )
29+ xxhash .XXH3_64bits_update (self .hs , ptr , len )
30+ return self
31+ end
32+
33+ function Hashoir :digest ()
34+ return xxhash .XXH3_64bits_digest (self .hs )
35+ end
36+
37+ function Hashoir :hexdigest ()
38+ return string.format (" %016x" , xxhash .XXH3_64bits_digest (self .hs ))
39+ end
40+
41+ return Hashoir
You can’t perform that action at this time.
0 commit comments