fasthash

High-performance hashing functions written in Zig

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/fasthash.kitKit API and FFI bindings for FastHash
tests/algorithm-tests.test.kitTests for the exported hashing API shape
tests/fasthash.test.kitTests for hashing behavior and algorithm properties
zig/hash.hC header for the Zig FFI functions
zig/hash.zigZig implementations of the hash algorithms
zig/kit_ffi.zigKit FFI helper types for Zig packages

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-fasthash.git

Usage

import Kit.Fasthash as FastHash

main = fn =>
  data = "hello world"

  # Compute hashes with individual algorithms
  fnv = FastHash.fnv1a data
  djb2 = FastHash.djb2 data
  sdbm = FastHash.sdbm data
  rolling = FastHash.rolling data
  xor = FastHash.xor data

  println "FNV-1a:  ${Int.to-string fnv}"
  println "DJB2:    ${Int.to-string djb2}"
  println "SDBM:    ${Int.to-string sdbm}"
  println "Rolling: ${Int.to-string rolling}"
  println "XOR:     ${Int.to-string xor}"

  # Select an algorithm by name at runtime
  selected = FastHash.hash "fnv1a" data
  println "Selected hash: ${Int.to-string selected}"

  # Combine hash values for composite keys
  name-hash = FastHash.fnv1a "Jane"
  id-hash = FastHash.fnv1a "12345"
  combined = FastHash.combine name-hash id-hash
  println "Combined hash: ${Int.to-string combined}"

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/fasthash/, making it available for import as Kit.Fasthash in other projects.

License

This package is released under the MIT License - see LICENSE for details.

Exported Functions & Types

fnv1a

String -> Int

rolling

String -> Int

djb2

String -> Int

sdbm

String -> Int

xor

String -> Int

combine

Int -> Int -> Int

version

() -> Int

hash

String -> String -> Int