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


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.

Documentation

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"

Swift Package Manager

import PackageDescription

let package = Package(
  name: "YOUR_PACKAGE_NAME",
  dependencies: [
    // Swift 4.2
    .package(url: "https://github.com/daisuke-t-jp/FNV.git", .exact("1.0.11"))
    
    // Swift 5.0
    .package(url: "https://github.com/daisuke-t-jp/FNV.git", from: "1.0.12")
  ],
  targets: [
    .target(
      name: "YOUR_TARGET_NAME",
      dependencies: ["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: 0
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

1.0.13 - Apr 17, 2019

Update

  • Fix Deployment Targets

1.0.12 - Mar 26, 2019

Update

  • Migrating to Swift 5.0 / Xcode 10.2

1.0.11 - Mar 6, 2019

Update

  • Add Streaming hash

1.0.10 - Mar 5, 2019

Added

  • Digest's hex string func
  • Document(jazzy)

1.0.9 - Feb 28, 2019

Update

  • Passed SwiftLint
  • Add Document comments