Swiftpack.co - Package - daisuke-t-jp/MurmurHash-Swift


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

Introduction

MurmurHash framework in Swift.
A framework includes MurmurHash3's x86_32/x86_128/x64_128 functions.

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 'MurmurHash-Swift'
end

Carthage

github "daisuke-t-jp/MurmurHash-Swift"

Swift Package Manager

import PackageDescription

let package = Package(
  name: "YOUR_PACKAGE_NAME",
  dependencies: [
    // Swift 4.2
    .package(url: "https://github.com/daisuke-t-jp/MurmurHash-Swift.git", .exact("1.0.11"))
    
    // Swift 5.0
    .package(url: "https://github.com/daisuke-t-jp/MurmurHash-Swift.git", from: "1.0.12")
  ],
  targets: [
    .target(
      name: "YOUR_TARGET_NAME",
      dependencies: ["MurmurHash-Swift"]),
  ]
)

Usage

Import framework

import MurmurHash_Swift

Generate digest(One-shot)

x86_32

let digest = MurmurHash3.x86_32.digest("Hello World! Hello World!")
// digest -> 0x0be480fc

// Using seed.
let digest = MurmurHash3.x86_32.digest("Hello World! Hello World!", seed: 0x7fffffff)
// digest -> 0x47fcc800

x86_128

let digest = MurmurHash3.x86_128.digestHex("Hello World! Hello World!")
// digest -> "86163d2b245b8ee23c4d056024166d77"

// Using seed.
let digest = MurmurHash3.x86_128.digestHex("Hello World! Hello World!", seed: 0x7fffffff)
// digest -> "d1ab28e6f4fc514c5e0df753b015261f"

x64_128

let digest = MurmurHash3.x64_128.digestHex("Hello World! Hello World!")
// digest -> "e881a28e49269b1e8d0d724eecb72e66"

// Using seed.
let digest = MurmurHash3.x64_128.digestHex("Hello World! Hello World!", seed: 0x7fffffff)
// digest -> "6028586a8c3df476fbd535aec6551aab"

Generate digest(Streaming)

x86_32

let mmh = MurmurHash3.x86_32() // if using seed, e.g. "MurmurHash3.x86_32(0x7fffffff)"

let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: "alice29", ofType: "txt")!
let data = NSData(contentsOfFile: path)! as Data

let bufSize = 1024
var index = 0

repeat {
  var lastIndex = index + bufSize
  if lastIndex > data.count {
    lastIndex = index + data.count - index
  }

  let data2 = data[index..<lastIndex]
  mmh.update(data2)

  index += data2.count
  if index >= data.count {
    break
  }
} while(true)

let digest = mmh.digest()
// digest -> 0xcae14481

x86_128

let mmh = MurmurHash3.x86_128() // if using seed, e.g. "MurmurHash3.x86_128(0x7fffffff)"

let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: "alice29", ofType: "txt")!
let data = NSData(contentsOfFile: path)! as Data

let bufSize = 1024
var index = 0

repeat {
  var lastIndex = index + bufSize
  if lastIndex > data.count {
    lastIndex = index + data.count - index
  }

  let data2 = data[index..<lastIndex]
  mmh.update(data2)

  index += data2.count
  if index >= data.count {
    break
  }
} while(true)

let digest = mmh.digestHex()
// digest -> "f3d9739244076beaaaa983c7cc4c7251"

x64_128

let mmh = MurmurHash3.x64_128() // if using seed, e.g. "MurmurHash3.x64_128(0x7fffffff)"

let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: "alice29", ofType: "txt")!
let data = NSData(contentsOfFile: path)! as Data

let bufSize = 1024
var index = 0

repeat {
  var lastIndex = index + bufSize
  if lastIndex > data.count {
    lastIndex = index + data.count - index
  }

  let data2 = data[index..<lastIndex]
  mmh.update(data2)

  index += data2.count
  if index >= data.count {
    break
  }
} while(true)

let digest = mmh.digestHex()
// digest -> "ef12617f3e2a5f9a44b3598f2e09cd50"

Demo

There are demos.

Github

link
Stars: 2
Help us keep the lights on

Dependencies

Used By

Total:

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 5, 2019

Add

  • Streaming hash
  • Document(jazzy)

1.0.10 - Feb 28, 2019

Update

  • Passed SwiftLint
  • Added Hex string func
  • Fix large tuple

1.0.9 - Feb 22, 2019

Update

  • Supported Linux