https://github.com/galactixx/zighash
Zighash is a Zig package for generating non-cryptographic hash values using a variety of popular algorithms: FNV-1a, MurmurHash3, SpookyHash, xxHash, SuperFastHash, and CityHash. Perfect for hash-based data structures, checksums, deduplication, and performance-sensitive applications.
https://github.com/galactixx/zighash
hashing zig zig-package ziglang
Last synced: 11 months ago
JSON representation
Zighash is a Zig package for generating non-cryptographic hash values using a variety of popular algorithms: FNV-1a, MurmurHash3, SpookyHash, xxHash, SuperFastHash, and CityHash. Perfect for hash-based data structures, checksums, deduplication, and performance-sensitive applications.
- Host: GitHub
- URL: https://github.com/galactixx/zighash
- Owner: galactixx
- License: mit
- Created: 2025-05-21T16:48:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-26T03:11:27.000Z (12 months ago)
- Last Synced: 2025-06-26T04:19:36.497Z (12 months ago)
- Topics: hashing, zig, zig-package, ziglang
- Language: Zig
- Homepage:
- Size: 2.92 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Zighash is a Zig package for generating non-cryptographic hash values using a variety of popular algorithms: **FNV-1a**, **MurmurHash3**, **SpookyHash**, **xxHash**, **SuperFastHash**, and **CityHash**.
## β¨ **Features**
* **Multiple Hash Algorithms:**
* **FNV-1a:** `fnv1aHash32`, `fnv1aHash64`
* **SuperFastHash:** `superFastHash32`
* **MurmurHash3:** `murmur3Hash32`
* **SpookyHash:** `spookyHash32`, `spookyHash64`
* **xxHash:** `xxHash32`, `xxHash64`
* **CityHash:** `cityHash32`, `cityHash64`
## π Getting Started
### Fetch via `zig fetch`
You can use the builtβin Zig fetcher to download and pin a tarball:
```bash
zig fetch --save git+https://github.com/galactixx/zighash#v0.2.0
```
> This adds an `zighash` entry under `.dependencies` in your `build.zig.zon`.
Then in your build.zig:
```zig
const zighash_mod = b.dependency("zighash", .{
.target = target,
.optimize = optimize,
}).module("zighash");
// add to library
lib_mod.addImport("zighash", zighash_mod);
// add to executable
exe.root_module.addImport("zighash", zighash_mod);
```
This lets you `const zh = @import("zighash");` in your Zig code.
## π **Usage**
```zig
const std = @import("std");
const zh = @import("zighash");
pub fn main() void {
const key = "Hello, Zig!";
const hash32 = zh.fnv1aHash32(key);
const hash64 = zh.xxHash64(key);
std.debug.print("FNV-1a 32-bit: {x}\n", .{hash32});
std.debug.print("xxHash 64-bit: {x}\n", .{hash64});
}
```
## π **API**
### FNV-1a
```zig
pub fn fnv1aHash32(key: []const u8) u32
```
* **Parameters:**
* `key`: The input byte slice (`[]const u8`) to hash.
* **Returns:** A 32-bit unsigned integer (`u32`) representing the FNV-1a hash.
```zig
pub fn fnv1aHash64(key: []const u8) u64
```
* **Parameters:**
* `key`: The input byte slice.
* **Returns:** A 64-bit unsigned integer (`u64`) representing the FNV-1a hash.
---
### MurmurHash3
```zig
pub fn murmur3Hash32(key: []const u8, seed: u32) u32
```
* **Parameters:**
* `key`: The input byte slice.
* `seed`: The 32-bit seed.
* **Returns:** A 32-bit unsigned integer (`u32`) computed by MurmurHash3.
---
### SpookyHash
```zig
pub fn spookyHash32(key: []const u8, seed: u32) u32
pub fn spookyHash64(key: []const u8, seed: u64) u64
```
* **Parameters:**
* `key`: The input byte slice.
* `seed`: The 32-bit (`u32`) or 64-bit (`u64`) seed.
* **Returns:** 32-bit (`u32`) or 64-bit (`u64`) hash values.
---
### xxHash
```zig
pub fn xxHash32(key: []const u8, seed: u32) u32
pub fn xxHash64(key: []const u8, seed: u64) u64
```
* **Parameters:**
* `key`: The input byte slice.
* `seed`: The 32-bit (`u32`) or 64-bit (`u64`) seed.
* **Returns:** 32-bit or 64-bit non-cryptographic hash.
---
### SuperFastHash
```zig
pub fn superFastHash32(key: []const u8) u32
```
* **Parameters:**
* `key`: The input byte slice.
* **Returns:** A 32-bit non-cryptographic hash.
---
### CityHash
```zig
pub fn cityHash32(key: []const u8) u32
pub fn cityHash64(key: []const u8) u64
```
* **Parameters:**
* `key`: The input byte slice.
* **Returns:** 32-bit or 64-bit hash optimized for varied input lengths.
## π€ **License**
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
## π **Contact**
Have questions or want to contribute? Open an issue or pull request on [GitHub](https://github.com/galactixx/zighash).