summaryrefslogtreecommitdiff
path: root/xmake/core/base/hash.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-19 23:16:35 +0800
committerruki <[email protected]>2022-05-19 23:16:35 +0800
commit7ee3bcea46426a9cc67b5a175f0f4abe0e5dd238 (patch)
tree15b24bc73573ec0d7530d9028e8bf3e3c5ce2442 /xmake/core/base/hash.lua
parent2a3f925f6dd3c3ffd0b4322b2423125dd207b045 (diff)
add xxhash
Diffstat (limited to 'xmake/core/base/hash.lua')
-rw-r--r--xmake/core/base/hash.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua
index f76c3812a..74bbfd4cd 100644
--- a/xmake/core/base/hash.lua
+++ b/xmake/core/base/hash.lua
@@ -29,6 +29,7 @@ local bytes = require("base/bytes")
-- save metatable and builtin functions
hash._md5 = hash._md5 or hash.md5
hash._sha = hash._sha or hash.sha
+hash._xxhash = hash._xxhash or hash.xxhash
-- make md5 from the given file or data
function hash.md5(file_or_data)
@@ -69,5 +70,31 @@ function hash.sha256(file_or_data)
return hashstr, errors
end
+-- make xxhash64 from the given file or data
+function hash.xxhash64(file_or_data)
+ local hashstr, errors
+ if bytes.instance_of(file_or_data) then
+ local datasize = file_or_data:size()
+ local dataaddr = file_or_data:caddr()
+ hashstr, errors = hash._xxhash(64, dataaddr, datasize)
+ else
+ hashstr, errors = hash._xxhash(64, file_or_data)
+ end
+ return hashstr, errors
+end
+
+-- make xxhash128 from the given file or data
+function hash.xxhash128(file_or_data)
+ local hashstr, errors
+ if bytes.instance_of(file_or_data) then
+ local datasize = file_or_data:size()
+ local dataaddr = file_or_data:caddr()
+ hashstr, errors = hash._xxhash(128, dataaddr, datasize)
+ else
+ hashstr, errors = hash._xxhash(128, file_or_data)
+ end
+ return hashstr, errors
+end
+
-- return module: hash
return hash