xxhash
xxHash
xxHash is an extremely fast non-cryptographic hash algorithm, working at RAM speed limit. It comes in four flavors (XXH32, XXH64, XXH3_64bits and XXH3_128bits). For a more detailed comparison, see xxhash.com.
Current implementation status:
- [x] XXH32
- [x] XXH64
- [ ] XXH3_64
- [ ] XXH3_128
Installation
-
Add the dependency to your
shard.yml
:dependencies: xxhash: git: https://codeberg.org/Sylphrena/xxHash.cr.git
-
Run
shards install
Usage
require "xxhash"
# Hashing a file
File.open "path_to_file", "r" do |io|
# xxHash64 algorithm
XXHash.digest64(io)
# xxHash32 algorithm
XXHash.digest32(io)
# With hexstring return value
XXHash.hexdigest64(io)
# With hexstring return value
XXHash.hexdigest32(io)
end
# Hashing a `String`
XXHash.digest64("魑魅魍魎")
XXHash.digest32("魑魅魍魎")
XXHash.hexdigest64("魑魅魍魎")
XXHash.hexdigest32("魑魅魍魎")
Performance
Using spec/speed_test.cr
. Times include rewinding the IO, greatly influencing performance for small sizes.
| Size | H32 | H64 | | :-: | :-: | :-: | | 8 B | 202 MiB/s | 212 MiB/s | | 64 B | 1.4 GiB/s | 1.21 GiB/s | | 4 KiB | 4.54 GiB/s | 9.4 GiB/s | | 10 MiB | 4.5 GiB/s | 10.0 GiB/s |
Contributing
- Fork it (https://codeberg.org/Sylphrena/xxHash.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Sylphrena - creator and maintainer