solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
Functions
hash.h File Reference

Collection of fast, non-cryptographic hash functions for general-purpose hashing. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <xxhash.h>
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.

Functions

uint32_t solidc_djb2_hash (const void *key)
 DJB2 hash function for null-terminated strings.
 
uint32_t solidc_djb2a_hash (const void *key)
 DJB2A hash function (XOR variant) for null-terminated strings.
 
uint32_t solidc_sdbm_hash (const void *key)
 SDBM hash function for null-terminated strings.
 
uint32_t solidc_fnv1a_hash (const void *key)
 FNV-1a 32-bit hash function for null-terminated strings.
 
uint64_t solidc_fnv1a_hash64 (const void *key)
 FNV-1a 64-bit hash function for null-terminated strings.
 
uint32_t solidc_elf_hash (const void *key)
 ELF hash function for null-terminated strings.
 
uint32_t solidc_crc32_hash (const void *key, size_t len)
 CRC32 hash function for arbitrary binary data.
 
uint32_t solidc_murmur_hash (const char *key, uint32_t len, uint32_t seed)
 MurmurHash3 32-bit hash function.
 

Detailed Description

Collection of fast, non-cryptographic hash functions for general-purpose hashing.

This library provides several well-known hash functions suitable for hash tables, checksums, and other non-cryptographic applications. For cryptographic hashing, use dedicated cryptographic libraries instead.

Available hash functions:

Definition in file hash.h.

Function Documentation

◆ solidc_crc32_hash()

uint32_t solidc_crc32_hash ( const void *  key,
size_t  len 
)

CRC32 hash function for arbitrary binary data.

Cyclic Redundancy Check using standard CRC32 polynomial. Useful for checksums and data integrity verification.

Parameters
keyPointer to data buffer
lenLength of data in bytes
Returns
32-bit CRC32 checksum
Note
Can handle binary data with embedded null bytes.

CRC32 hash function implementation. Standard CRC32 with polynomial 0xEDB88320.

Definition at line 110 of file hash.c.

References solidc_crc32_hash().

Referenced by solidc_crc32_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_djb2_hash()

uint32_t solidc_djb2_hash ( const void *  key)

DJB2 hash function for null-terminated strings.

A simple and effective hash function created by Daniel J. Bernstein. Formula: hash = hash * 33 + c

Parameters
keyPointer to null-terminated string
Returns
32-bit hash value
Note
This function expects a null-terminated string.
See also
http://www.cse.yorku.ca/~oz/hash.html

DJB2 hash function implementation. Simple and effective hash created by Daniel J. Bernstein.

Definition at line 10 of file hash.c.

References solidc_djb2_hash().

Referenced by solidc_djb2_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_djb2a_hash()

uint32_t solidc_djb2a_hash ( const void *  key)

DJB2A hash function (XOR variant) for null-terminated strings.

Variant of DJB2 using XOR instead of addition. Formula: hash = hash * 33 ^ c

Parameters
keyPointer to null-terminated string
Returns
32-bit hash value
Note
This function expects a null-terminated string.

DJB2A hash function implementation (XOR variant). Uses XOR instead of addition for mixing.

Definition at line 26 of file hash.c.

References solidc_djb2a_hash().

Referenced by solidc_djb2a_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_elf_hash()

uint32_t solidc_elf_hash ( const void *  key)

ELF hash function for null-terminated strings.

Hash function used in the ELF (Executable and Linkable Format) object file format.

Parameters
keyPointer to null-terminated string
Returns
32-bit hash value
Note
This function expects a null-terminated string.

ELF hash function implementation. Used in ELF object file format.

Definition at line 74 of file hash.c.

References solidc_elf_hash().

Referenced by solidc_elf_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_fnv1a_hash()

uint32_t solidc_fnv1a_hash ( const void *  key)

FNV-1a 32-bit hash function for null-terminated strings.

Fowler-Noll-Vo hash with good distribution properties. Uses XOR-then-multiply approach.

Parameters
keyPointer to null-terminated string
Returns
32-bit hash value
Note
This function expects a null-terminated string.
See also
http://www.isthe.com/chongo/tech/comp/fnv/

FNV-1a 32-bit hash function implementation. Fowler-Noll-Vo hash with good distribution.

Definition at line 42 of file hash.c.

References solidc_fnv1a_hash().

Referenced by solidc_fnv1a_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_fnv1a_hash64()

uint64_t solidc_fnv1a_hash64 ( const void *  key)

FNV-1a 64-bit hash function for null-terminated strings.

64-bit version of FNV-1a, providing larger hash space. Useful when 32-bit hash collisions are a concern.

Parameters
keyPointer to null-terminated string
Returns
64-bit hash value
Note
This function expects a null-terminated string.
See also
http://www.isthe.com/chongo/tech/comp/fnv/

FNV-1a 64-bit hash function implementation. 64-bit version providing larger hash space.

Definition at line 58 of file hash.c.

References solidc_fnv1a_hash64().

Referenced by solidc_fnv1a_hash64().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_murmur_hash()

uint32_t solidc_murmur_hash ( const char *  key,
uint32_t  len,
uint32_t  seed 
)

MurmurHash3 32-bit hash function.

Excellent general-purpose hash with good distribution and performance. Widely used in hash tables and bloom filters.

Parameters
keyPointer to data buffer
lenLength of data in bytes
seedSeed value for hash initialization (use 0 for default)
Returns
32-bit hash value
Note
Can handle binary data with embedded null bytes.
See also
https://en.wikipedia.org/wiki/MurmurHash

MurmurHash3 32-bit implementation. Excellent general-purpose hash with good distribution.

Definition at line 128 of file hash.c.

References solidc_murmur_hash().

Referenced by solidc_murmur_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solidc_sdbm_hash()

uint32_t solidc_sdbm_hash ( const void *  key)

SDBM hash function for null-terminated strings.

Hash function used in the SDBM database library. Formula: hash = c + (hash << 6) + (hash << 16) - hash

Parameters
keyPointer to null-terminated string
Returns
32-bit hash value
Note
This function expects a null-terminated string.

SDBM hash function implementation. Used in SDBM database library.

Definition at line 95 of file hash.c.

References solidc_sdbm_hash().

Referenced by solidc_sdbm_hash().

Here is the call graph for this function:
Here is the caller graph for this function: