FNV 1.1.2

FNV 1.1.2

Maintained by Daisuke T.




FNV 1.1.2

  • By
  • daisuke-t-jp


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.