BashSpark
Loading...
Searching...
No Matches
hash.h File Reference

Implements FNV-1a hash functions for strings. More...

#include <cstdint>
#include <string>
#include <string_view>
Include dependency graph for hash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  bs
 BashSpark main namespace.
 

Functions

constexpr std::uint64_t bs::hash (const char *const pString, const std::size_t nLength)
 Hashes a string.
 
constexpr std::uint64_t bs::hash (const std::string_view sString)
 Hashes a string.
 
std::uint64_t bs::hash (const std::string &sString)
 Hashes a string.
 
constexpr std::uint64_t bs::hash (const char *const pString)
 Hashes a string.
 

Variables

constexpr std::uint64_t bs::FNV_OFFSET_BASIS = 2166136261
 FVN-1 offset basis.
 
constexpr std::uint64_t bs::FNVPrime = 16777619
 FVN-1 prime number.
 

Detailed Description

Implements FNV-1a hash functions for strings.

This header file provides functions to hash strings using the FNV-1a hashing algorithm. It includes overloads for C-style strings, std::string, and std::string_view. The FNV-1a algorithm is a simple and efficient non-cryptographic hash function.

Note
The hashing functions are constexpr where applicable, allowing compile-time evaluation for constant expressions.
Date
Created on 2/11/25
Author
Dante Doménech Martínez
Warning
The input string should be properly null-terminated for C-style string functions.

This file is part of BashSpark. Copyright (c) 2025 Dante Doménech Martínez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.