fasthash
| Kind | ffi-zig |
|---|---|
| Capabilities | ffi |
| Categories | algorithms cryptography ffi |
| Keywords | hash hashing xxhash performance zig-ffi |
High-performance hashing functions written in Zig
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/fasthash.kit | Kit API and FFI bindings for FastHash |
tests/algorithm-tests.test.kit | Tests for the exported hashing API shape |
tests/fasthash.test.kit | Tests for hashing behavior and algorithm properties |
zig/hash.h | C header for the Zig FFI functions |
zig/hash.zig | Zig implementations of the hash algorithms |
zig/kit_ffi.zig | Kit FFI helper types for Zig packages |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-fasthash.gitUsage
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}"
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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