xxhash

Pure crystal implementation of the xxHash algorithms
HEAD Latest release released

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

  1. Add the dependency to your shard.yml:

    dependencies:
      xxhash:
        git: https://codeberg.org/Sylphrena/xxHash.cr.git
    
  2. 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

  1. Fork it (https://codeberg.org/Sylphrena/xxHash.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

xxhash:
  git: https://codeberg.org/Sylphrena/xxHash.cr
  
License 0BSD
Crystal >= 1.14.0

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently