BashSpark
Loading...
Searching...
No Matches
bs::shell_hash Struct Reference

Custom hash functor for strings using the 64-bit FNV-1a algorithm. More...

#include <shell_hash.h>

Public Member Functions

std::uint64_t operator() (const std::string &sString) const noexcept
 Computes a 64-bit FNV-1a hash for a string.
 

Static Public Attributes

static constexpr std::uint64_t FNV_OFFSET = 1469598103934665603ull
 FVN offset.
 
static constexpr std::uint64_t FNV_PRIME = 1099511628211ull
 FVN prime.
 

Detailed Description

Custom hash functor for strings using the 64-bit FNV-1a algorithm.

This hash function is fast, has good distribution, and works well for small and medium-sized strings such as shell tokens, variable names, and keywords.

Member Function Documentation

◆ operator()()

std::uint64_t bs::shell_hash::operator() ( const std::string &  sString) const
inlinenoexcept

Computes a 64-bit FNV-1a hash for a string.

Parameters
sStringThe input string to hash.
Returns
A 64-bit hash value.

This implementation is based on the standard 64-bit FNV-1a algorithm:

hash = offset_basis
for each byte:
hash ^= byte
hash *= FNV_prime

The algorithm is simple but effective for non-cryptographic use.


The documentation for this struct was generated from the following file: