Skip to main content

HashHelper

A static class in Alta.Values, Alta.Networking.

Helpers for the 16-bit hashes used to identify assets and prefabs over the network, and a stable string hash.

Fields​

MemberWhat it is
const int HashBitsNumber of bits in a compressed hash (16).
const ulong MaxHashLargest valid compressed hash (65535).
2 private and internal fields
MemberWhat it is
private static readonly Logger loggerLogger for this class.
private static Dictionary<Type, uint> savingHashesUnused cache of saving hashes per type.

Methods​

MemberWhat it is
static int GetHashCodeForString(string src)Fixed string hash (two djb2-style passes over alternating characters), so a string always gives the same hash on every machine.
static uint Hash(string text)Hashes a string with GetHashCodeForString, as a uint.
static uint HashCompressed(string text)Hashes a string and keeps the low 16 bits.
static bool Validate(ref int hash, Object current, Object target)Replaces the hash with a new one if it is 0 or out of range (or, in one overload, the object was copied); returns true if it changed.
static bool Validate(ref int hash, Object target)Replaces the hash with a new one if it is 0 or out of range (or, in one overload, the object was copied); returns true if it changed.
1 private and internal method
MemberWhat it is
private static int GetNewHash(Object target)Makes a new hash from the low 16 bits of the object's instance ID.