Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Important

🔀 This repo has moved to Codeberg

The active copy now lives at codeberg.org/Heathen-Engineering/O3DE-xxHash — please point your git remote, UPM manifest, or Gem reference there going forward. That's where new commits, releases, and issues actually happen now.

This GitHub copy is preserved as-is and still works for anyone already pointing at it, but it isn't receiving new updates. It will be archived (read-only) once every downstream package that depends on it has finished migrating too, not immediately.

Questions? Discord.

xxHash for O3DE

Maintained

An Open 3D Engine (O3DE) gem that bundles xxHash — an extremely fast non-cryptographic hash algorithm by Yann Collet — and exposes it to C++, Script Canvas, and Lua.

Tip

Looking for the easiest way to install?
You can add this gem—along with all of Heathen's free O3DE tools—by using the centralized O3DE-Gems repository. Step-by-step setup instructions are available directly in its README.


Third-party attribution

This gem vendors the xxHash library unchanged (apart from a minor include-path adjustment required by the O3DE build system).

xxHash — Extremely Fast Hash algorithm
Copyright (C) 2012–2023 Yann Collet
BSD 2-Clause License
Homepage: https://xxhash.com
Source repository: https://github.com/Cyan4973/xxHash

The full BSD 2-Clause license text is located at:

Gems/xxHash/Code/Source/ThirdParty/xxHash/LICENSE

Become a GitHub Sponsor

Prefer a one-time purchase? Heathen's own storefront is live, direct source access at heathen.group/pricing, no sponsorship required.

Discord GitHub followers Support Heathen by becoming a GitHub Sponsor. Sponsorship directly funds the development and maintenance of free tools like this, as well as our game development Knowledge Base and community on Discord.

Sponsors also get access to our private SourceRepo, which includes developer tools for O3DE, Unreal, Unity, and Godot. Learn more or explore other ways to support @ heathen.group/kb


What it does

xxHash provides three hash variants exposed through the xxHashRequestBus EBus:

Function Algorithm Output Notes
Hash32 XXH32 AZ::u32 Classic 32-bit algorithm. XXH3 has no 32-bit variant; XXH32 is used here.
Hash64 XXH3_64bits AZ::u64 Modern 64-bit (xxHash v3); preferred for all new 64-bit use cases.
Hash128 XXH3_128bits AZ::Uuid Modern 128-bit (xxHash v3); fastest on current hardware.

Hash32 and Hash64 accept a seed value. Hash128 has no seed parameter. Hash128 returns an AZ::Uuid — a first-class O3DE type that works in serialization, Script Canvas, Lua, and AZStd collections without any extra setup.

Note: Hash32 uses the legacy XXH32 algorithm because the xxHash v3 family has no native 32-bit output. Prefer Hash64 or Hash128 for any new work where the output width is not constrained.

For high-throughput C++ code (e.g. raw byte buffers, streaming), you can also call the xxHash C API directly via #include <xxHash/xxhash.h>.


Requirements

  • O3DE engine 25.10.2 or compatible

Setup

1. Add the gem to your O3DE project

Register the gem with the O3DE Project Manager, or add it directly to your project's project.json:

"external_subdirectories": [
    "Gems/xxHash"
],
"gem_names": [
    "xxHash"
]

Then re-run CMake configuration so the build system picks up the new gem.


Usage — C++

Via the EBus (recommended for game code)

#include <xxHash/xxHashBus.h>

// 32-bit hash with default seed
AZ::u32 hash32 = 0;
xxHash::xxHashRequestBus::BroadcastResult(hash32, &xxHash::xxHashRequests::Hash32, "my string", 0u);

// 64-bit hash with a custom seed
AZ::u64 hash64 = 0;
xxHash::xxHashRequestBus::BroadcastResult(hash64, &xxHash::xxHashRequests::Hash64, "my string", 12345ull);

// 128-bit hash returned as AZ::Uuid
AZ::Uuid hash128;
xxHash::xxHashRequestBus::BroadcastResult(hash128, &xxHash::xxHashRequests::Hash128, "my string");

AZStd::string asString = hash128.ToString<AZStd::string>();

Via the AZ::Interface (lowest overhead, same process)

#include <xxHash/xxHashBus.h>

if (auto* xxhash = xxHash::xxHashInterface::Get())
{
    AZ::u64 id = xxhash->Hash64("EntityName", 0);
    AZ::Uuid uid = xxhash->Hash128("AssetPath/MyAsset.png");
}

Via the xxHash C API directly (raw performance)

Use this when you need to hash arbitrary byte buffers or use the streaming / secret-seed advanced APIs:

#define XXH_STATIC_LINKING_ONLY   // optional: access advanced declarations
#include <xxHash/xxhash.h>

// Hash a raw buffer
const void* data   = myBuffer.data();
size_t      length = myBuffer.size();

XXH32_hash_t  h32  = XXH32(data, length, 0);
XXH64_hash_t  h64  = XXH64(data, length, 0);
XXH128_hash_t h128 = XXH3_128bits(data, length);

Any gem that lists Gem::xxHash.API (or Gem::xxHash) as a BUILD_DEPENDENCY has access to <xxHash/xxhash.h> automatically.

CMake dependency

In your gem's Code/CMakeLists.txt, add Gem::xxHash.API to the appropriate target:

BUILD_DEPENDENCIES
    PUBLIC
        Gem::xxHash.API

Usage — Script Canvas

The xxHashRequestBus is fully reflected to the BehaviorContext. In Script Canvas, search the node palette for xxHash to find: image

Node Inputs Output
Hash32 String, Seed (u32) u32
Hash64 String, Seed (u64) u64
Hash128 String Uuid

All three nodes appear under the xxHash category and target the xxHashRequestBus broadcast address (no explicit address needed).


Usage — Lua

local hash32  = xxHashRequestBus.Broadcast.Hash32("hello world", 0)
local hash64  = xxHashRequestBus.Broadcast.Hash64("hello world", 0)
local hash128 = xxHashRequestBus.Broadcast.Hash128("hello world")

-- AZ::Uuid has a built-in string conversion
Debug.Log(tostring(hash128))

Public API reference

xxHashRequestBus events

Event Signature Description
Hash32 (string, u32 seed) → u32 32-bit hash (XXH32 — no XXH3 32-bit equivalent exists)
Hash64 (string, u64 seed) → u64 64-bit hash (XXH3_64bits)
Hash128 (string) → AZ::Uuid 128-bit hash (XXH3_128bits)

Public headers

Header Contents
xxHash/xxHashBus.h EBus interface — include this for game/gem code
xxHash/xxHashTypeIds.h AZ type ID constants
xxHash/xxhash.h The full xxHash C library — include for raw buffer access

About

An Open 3D Engine (O3DE) gem that bundles xxHash — an extremely fast non-cryptographic hash algorithm by Yann Collet — and exposes it to C++, Script Canvas, and Lua.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages