j
jaipkg.dev
packages / library / xxh3

xxh3

5a23a44library

No description provided.

No license · updated 7 months ago

Jai xxh3 (xxHash64) Module

This module provides a fast, non-cryptographic 64-bit hash function based on the principles of the xxHash algorithm. It's optimized for speed and collision resistance in general-purpose hashing (like hash tables and checksums).

Usage

The primary function is hash, overloaded to accept various input types.

hash(data: $T, seed = 0) -> u64;

T could be any primitive type (u8, s32, float64, ...), enums, string, or arrays of primitive types

Example

XXH3 :: #import,file "xxh3.jai";
#import "Basic";

main :: () {
    // Hash a string
    hash1 := XXH3.hash("performance boost");
    print("Hash 1: %\n", hash1);

    // Hash with a seed
    hash2 := XXH3.hash(12345, 0xABCD);
    print("Hash 2: %\n", hash2);

    // Hash a byte array
    data: [7]u8 = ---;
    hash3 := XXH3.hash(data);
    print("Hash 3: %\n", hash3);
}

Technical Details

  • Algorithm: Implements the xxHash64 variant.
  • Performance: Utilizes pointer arithmetic and the native Jai rotate operators (<<<, >>>) for maximum throughput.
  • Constants: Uses standard xxHash primes