FNVHashValue

master

A Swift implementation of the Fowler–Noll–Vo (FNV) hash function
itssofluffy/FNVHashValue

FNVHashValue

Swift Swift Build Status macOS Linux License

A Swift implementation of the Fowler–Noll–Vo (FNV) hash function

This code provides implementations of the FNV-1 and FNV-1a hash functions in pure Swift. Computes 64-bit hashes on 64-bit devices and 32-bit hashes on 32-bit devices. Based on original code by Mauricio Santos as FNVHash-Swift and adaptted to plug directly into Hashable protocol to provide hashValue values (see examples).

Usage

If Swift Package Manager is used, add this package as a dependency in Package.swift,

import PackageDescription

let package = Package (
    name:  "<your-app-name>",
    dependencies: [
        .Package(url: "https://github.com/itssofluffy/FNVHashValue.git", majorVersion: 0)
    ]
)

Examples

extension MyClassA: Hashable {
    public var hashValue: Int {
        return fnv1(self.primaryKey)
    }

    ...
}

extension MyClassB: Hashable {
    public var hashValue: Int {
        return fnv1a(self.primaryKey)
    }

    ...
}

extension MyClassC: Hashable {
    public var hashValue: Int {
        return fnv1(typeToBytes(self.primaryKey1) + typeToBytes(self.primaryKey2))
    }

    ...
}

extension MyClassD: Hashable {
    public var hashValue: Int {
        return fnv1a(typeToBytes(self.primaryKey1) + typeToBytes(self.primaryKey2))
    }

    ...
}

Additional information

Fowler–Noll–Vo hash function

License

This project is released under the MIT license. See LICENSE for details.

Description

  • Swift Tools 3.1.0
View More Packages from this Author

Dependencies

Last updated: Sun Apr 12 2026 13:11:31 GMT-0900 (Hawaii-Aleutian Daylight Time)