Swiftpack.co - daisuke-t-jp/FNV as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by daisuke-t-jp.
daisuke-t-jp/FNV 1.1.2
FNV hash framework in Swift.
⭐️ 2
🕓 2 weeks ago
.package(url: "https://github.com/daisuke-t-jp/FNV.git", from: "1.1.2")


Platform Language Swift%204.2,%205.0 CocoaPods Carthage compatible SwiftPM compatible Build Status

Introduction

FNV (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

import FNV

Generate digest(One-shot)

FNV-0

/**
 * 32 bit
 */
let digest = FNV.FNV0_32.digest("Hello World!")
// digest -> 0x6990d79d

let digestHex = FNV.FNV0_32.digestHex("Hello World!")
// digestHex -> "6990d79d"


/**
 * 64bit
 */
let digest = FNV.FNV0_64.digest("Hello World!")
// digest -> 0xdd8b4a711cd6199d

let digestHex = FNV.FNV0_64.digestHex("Hello World!")
// digestHex -> "dd8b4a711cd6199d"

FNV-1

/**
 * 32 bit
 */
let digest = FNV.FNV1_32.digest("Hello World!")
// digest -> 0x12a9a41c

let digestHex = FNV.FNV1_32.digestHex("Hello World!")
// digestHex -> "12a9a41c"


/**
 * 64bit
 */
let digest = FNV.FNV1_64.digest("Hello World!")
// digest -> 0x8e59dd02f68c387c

let digestHex = FNV.FNV1_64.digestHex("Hello World!")
// digestHex -> "8e59dd02f68c387c"

FNV-1a

/**
 * 32 bit
 */
let digest = FNV.FNV1a_32.digest("Hello World!")
// digest -> 0xb1ea4872

let digestHex = FNV.FNV1a_32.digestHex("Hello World!")
// digestHex -> "b1ea4872"


/**
 * 64bit
 */
let digest = FNV.FNV1a_64.digest("Hello World!")
// digest -> 0x8c0ec8d1fb9e6e32

let digestHex = FNV.FNV1a_64.digestHex("Hello World!")
// digestHex -> "8c0ec8d1fb9e6e32"

Generate digest(Streaming)

FNV-0

/**
 * 32 bit
 */
let fnv = FNV.FNV0_32()
fnv.update("Hello ")
fnv.update("World!")

let digest = fnv.digest()
// digest -> 0x6990d79d

let digestHex = fnv.digestHex()
// digestHex -> "6990d79d"


/**
 * 64bit
 */
let fnv = FNV.FNV0_64()
fnv.update("Hello ")
fnv.update("World!")

let digest = fnv.digest()
// digest -> 0xdd8b4a711cd6199d

let digestHex = fnv.digestHex()
// digestHex -> "dd8b4a711cd6199d"

FNV-1

/**
 * 32 bit
 */
let fnv = FNV.FNV1_32()
fnv.update("Hello ")
fnv.update("World!")

let digest = fnv.digest()
// digest -> 0x12a9a41c

let digestHex = fnv.digestHex()
// digestHex -> "12a9a41c"


/**
 * 64bit
 */
let fnv = FNV.FNV1_64()
fnv.update("Hello ")
fnv.update("World!")

let digest = fnv.digest()
// digest -> 0x8e59dd02f68c387c

let digestHex = fnv.digestHex()
// digestHex -> "8e59dd02f68c387c"

FNV-1a

/**
 * 32 bit
 */
let fnv = FNV.FNV1a_32()
fnv.update("Hello ")
fnv.update("World!")

let digest = fnv.digest()
// digest -> 0xb1ea4872

let digestHex = fnv.digestHex()
// digestHex -> "b1ea4872"


/**
 * 64bit
 */
let fnv = FNV.FNV1a_64()
fnv.update("Hello ")
fnv.update("World!")

let digest = fnv.digest()
// digest -> 0x8c0ec8d1fb9e6e32

let digestHex = fnv.digestHex()
// digestHex -> "8c0ec8d1fb9e6e32"

Demo

There are demos.

GitHub

link
Stars: 2
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.1.2
2 weeks ago
  • Refactoring / Thanks @ensan-hcl

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics