From 0adf3b9b215ab90533b0a4b07d6bf4c12dad74bf Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 5 Sep 2025 13:28:23 +0200 Subject: feat: libSystem: `libsys_hash_64` is now defined in `src/System.cc` Signed-off-by: Amlal El Mahrouss --- dev/libSystem/src/System.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'dev/libSystem/src/System.cc') diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc index 3870ff18..ba848a18 100644 --- a/dev/libSystem/src/System.cc +++ b/dev/libSystem/src/System.cc @@ -23,6 +23,23 @@ IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { } } +/// @note this uses the FNV 64-bit variant. +IMPORT_C UInt64 libsys_hash_64(const Char* path) { + if (!path || *path == 0) return 0; + + const UInt64 kFNVSeed = 0xcbf29ce484222325ULL; + const UInt64 kFNVPrime = 0x100000001b3ULL; + + UInt64 hash = kFNVSeed; + + while (*path) { + hash ^= (Char) (*path++); + hash *= kFNVPrime; + } + + return hash; +} + // memmove-style copy IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { // handles overlap, prefers 64-bit word copies when aligned -- cgit v1.2.3