Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daisuke-t-jp/fnv
FNV hash framework in Swift.
https://github.com/daisuke-t-jp/fnv
carthage cocoapods fnv hash ios linux macos swift swift-package-manager tvos
Last synced: 2 months ago
JSON representation
FNV hash framework in Swift.
- Host: GitHub
- URL: https://github.com/daisuke-t-jp/fnv
- Owner: daisuke-t-jp
- License: mit
- Created: 2019-02-04T20:58:52.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-09-20T05:21:37.000Z (over 2 years ago)
- Last Synced: 2024-10-07T21:34:02.023Z (4 months ago)
- Topics: carthage, cocoapods, fnv, hash, ios, linux, macos, swift, swift-package-manager, tvos
- Language: Swift
- Homepage: https://cocoapods.org/pods/FNV
- Size: 402 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
------
![Platform](https://img.shields.io/badge/Platform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20Linux-blue.svg)
[![Language Swift%204.2,%205.0](https://img.shields.io/badge/Language-Swift%204.2,%205.0-orange.svg)](https://developer.apple.com/swift)
[![CocoaPods](https://img.shields.io/cocoapods/v/FNV.svg)](https://cocoapods.org/pods/FNV)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-green.svg)](https://github.com/Carthage/Carthage)
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-green.svg)](https://github.com/apple/swift-package-manager)
![Build Status](https://github.com/daisuke-t-jp/FNV/actions/workflows/ci.yml/badge.svg)# Introduction
[**FNV**](http://www.isthe.com/chongo/tech/comp/fnv/index.html) (Fowler/Noll/Vo) hash framework in Swift.
A framework includes FNV-0(32/64bit), FNV-1(32/64bit), FNV-1a(32/64bit) functions.
Original FNV algorithm created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong Vo.# Requirements
- Platforms
- iOS 10.0+
- macOS 10.12+
- tvOS 12.0+
- Linux
- Swift 4.2, 5.0# Installation
## CocoaPods
```
use_frameworks!target 'target' do
pod 'FNV'
end
```## Carthage
`github "daisuke-t-jp/FNV"`# Usage
## Import framework
``` swift
import FNV
```## Generate digest(One-shot)
### FNV-0
``` swift
/**
* 32 bit
*/
let digest = FNV.FNV0_32.digest("Hello World!")
// digest -> 0x6990d79dlet digestHex = FNV.FNV0_32.digestHex("Hello World!")
// digestHex -> "6990d79d"/**
* 64bit
*/
let digest = FNV.FNV0_64.digest("Hello World!")
// digest -> 0xdd8b4a711cd6199dlet digestHex = FNV.FNV0_64.digestHex("Hello World!")
// digestHex -> "dd8b4a711cd6199d"
```## FNV-1
``` swift
/**
* 32 bit
*/
let digest = FNV.FNV1_32.digest("Hello World!")
// digest -> 0x12a9a41clet digestHex = FNV.FNV1_32.digestHex("Hello World!")
// digestHex -> "12a9a41c"/**
* 64bit
*/
let digest = FNV.FNV1_64.digest("Hello World!")
// digest -> 0x8e59dd02f68c387clet digestHex = FNV.FNV1_64.digestHex("Hello World!")
// digestHex -> "8e59dd02f68c387c"
```## FNV-1a
``` swift
/**
* 32 bit
*/
let digest = FNV.FNV1a_32.digest("Hello World!")
// digest -> 0xb1ea4872let digestHex = FNV.FNV1a_32.digestHex("Hello World!")
// digestHex -> "b1ea4872"/**
* 64bit
*/
let digest = FNV.FNV1a_64.digest("Hello World!")
// digest -> 0x8c0ec8d1fb9e6e32let digestHex = FNV.FNV1a_64.digestHex("Hello World!")
// digestHex -> "8c0ec8d1fb9e6e32"
```## Generate digest(Streaming)
### FNV-0
``` swift
/**
* 32 bit
*/
let fnv = FNV.FNV0_32()
fnv.update("Hello ")
fnv.update("World!")let digest = fnv.digest()
// digest -> 0x6990d79dlet digestHex = fnv.digestHex()
// digestHex -> "6990d79d"/**
* 64bit
*/
let fnv = FNV.FNV0_64()
fnv.update("Hello ")
fnv.update("World!")let digest = fnv.digest()
// digest -> 0xdd8b4a711cd6199dlet digestHex = fnv.digestHex()
// digestHex -> "dd8b4a711cd6199d"
```### FNV-1
``` swift
/**
* 32 bit
*/
let fnv = FNV.FNV1_32()
fnv.update("Hello ")
fnv.update("World!")let digest = fnv.digest()
// digest -> 0x12a9a41clet digestHex = fnv.digestHex()
// digestHex -> "12a9a41c"/**
* 64bit
*/
let fnv = FNV.FNV1_64()
fnv.update("Hello ")
fnv.update("World!")let digest = fnv.digest()
// digest -> 0x8e59dd02f68c387clet digestHex = fnv.digestHex()
// digestHex -> "8e59dd02f68c387c"
```### FNV-1a
``` swift
/**
* 32 bit
*/
let fnv = FNV.FNV1a_32()
fnv.update("Hello ")
fnv.update("World!")let digest = fnv.digest()
// digest -> 0xb1ea4872let digestHex = fnv.digestHex()
// digestHex -> "b1ea4872"/**
* 64bit
*/
let fnv = FNV.FNV1a_64()
fnv.update("Hello ")
fnv.update("World!")let digest = fnv.digest()
// digest -> 0x8c0ec8d1fb9e6e32let digestHex = fnv.digestHex()
// digestHex -> "8c0ec8d1fb9e6e32"
```# Demo
There are demos.
- [iOS](https://github.com/daisuke-t-jp/FNV/tree/master/Demo/FNVDemoiOS)
- [macOS](https://github.com/daisuke-t-jp/FNV/tree/master/Demo/FNVDemoMacOS)
- [tvOS](https://github.com/daisuke-t-jp/FNV/tree/master/Demo/FNVDemoTvOS)