limb 0.2.0

2024-01-09

hlookup(3)
limb manual
hlookup(3)

NAME

hlookup, hlookup32, hlookup64 - compute the hash of a given block of data

SYNOPSIS

#include <limb/hlookup.h>
void hlookup(u32 *main, u32 *second, const void *data, size_t dlen)
u32 hlookup32(const void *data, size_t dlen)
u64 hlookup64(const void *data, size_t dlen)

DESCRIPTION

These functions are designed to compute 32bit hashes of the given block of data pointed by data of length dlen. Resulting hashes are aimed for use in hash table lookups, e.g. with hmap_set(3), or anything where one collision in 2^32 is acceptable, they are not meant to be used for cryptographic purposes. See hasher_hash(3) for such use cases.

The hlookup() function calculates two 32bit hashes at once. You can either only use the main one, switch to the second one should the main one not please you, or combine them into a 64bit value/hash.

It is allowed for second to be NULL if you only need one hash. main however obvisouly cannot be NULL.

Both main and second (when not NULL) should be initialized with an initial value used as seed (can be zero), and will be set to the resulting hashes.

For convenience, the hlookup32() and hlookup64() functions can be used to have a 32bit or 64bit hash returned, respectively. The later one being made of the main hash for the lower bits and second hash for the higher bits of the returned 64bit hash.

Both will use dlen << 2 as initial seed value, and 0 as second seed value (for lookup64())

RETURN VALUES

The hlookup32() function returns a 32bit hash, the hlookup64() function returns a 64bit hash.

limb 0.1.0
2023-07-24
hlookup(3)