crystal-fnv v0.1.3
Crystal-FNV
Implements 32, 64 and 128 bits FNV-1 and FNV-1a Fowler–Noll–Vo hash function. FNV is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Phong Vo. Refer to Wikipedia for more details.
Installation
-
Add the dependency to your
shard.yml
:dependencies: fnv: github: naqvis/crystal-fnv
-
Run
shards install
Usage
require "fnv"
# 32bit FNV-1
digest = Digest::FNV32.digest("foo")
p IO::ByteFormat::BigEndian.decode(UInt32, digest) # => 1083137555
# 32bit FNV-1a
digest = Digest::FNV32A.digest("foo")
p IO::ByteFormat::BigEndian.decode(UInt32, digest) # => 2851307223
# 64bit FNV-1
digest = Digest::FNV64.digest("foo")
p IO::ByteFormat::BigEndian.decode(UInt64, digest) # => 15621798640163566899
# 64bit FNV-1a
digest = Digest::FNV64A.digest("foo")
p IO::ByteFormat::BigEndian.decode(UInt64, digest) # => 15902901984413996407
# 128bit FNV-1
digest = Digest::FNV128.digest("foo")
p IO::ByteFormat::BigEndian.decode(UInt128, digest) # => 221377198890555750482995053501755142603
# 128bit FNV-1a
digest = Digest::FNV128A.digest("foo")
p IO::ByteFormat::BigEndian.decode(UInt128, digest) # => 221385884292107687162785618921601726655
Contributing
- Fork it (https://github.com/naqvis/crystal-fnv/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
- Ali Naqvi - creator and maintainer
Repository
crystal-fnv
Owner
Statistic
- 5
- 0
- 0
- 2
- 0
- over 3 years ago
- April 22, 2020
License
MIT License
Links
Synced at
Sun, 22 Dec 2024 12:19:31 GMT
Languages