https://github.com/naqvis/crystal-fnv
Crystal Implementation of Fowler–Noll–Vo hash
https://github.com/naqvis/crystal-fnv
crystal crystal-fnv crystal-lang crystal-language crystal-shard fnv fnv-1a fnv-algorithms
Last synced: 5 months ago
JSON representation
Crystal Implementation of Fowler–Noll–Vo hash
- Host: GitHub
- URL: https://github.com/naqvis/crystal-fnv
- Owner: naqvis
- License: mit
- Created: 2020-04-22T15:11:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-24T15:37:07.000Z (over 4 years ago)
- Last Synced: 2025-05-12T22:55:23.559Z (5 months ago)
- Topics: crystal, crystal-fnv, crystal-lang, crystal-language, crystal-shard, fnv, fnv-1a, fnv-algorithms
- Language: Crystal
- Homepage:
- Size: 6.84 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crystal-FNV
Implements 32, 64 and 128 bits FNV-1 and FNV-1a [Fowler–Noll–Vo hash function](http://www.isthe.com/chongo/tech/comp/fnv/index.html). FNV is a non-cryptographic hash function created by
Glenn Fowler, Landon Curt Noll, and Phong Vo. Refer to [Wikipedia](https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function) for more details.## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
fnv:
github: naqvis/crystal-fnv
```2. Run `shards install`
## Usage
```Crystal
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
1. Fork it ()
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
- [Ali Naqvi](https://github.com/naqvis) - creator and maintainer