Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / hlookup.h / hlookup.3.md

% limb manual
% hlookup(3)
% limb 0.1.0
% 2023-07-24

# NAME

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


# SYNOPSIS

    #include <limb/hlookup.h>

```pre hl
void hlookup(u32 *<em>main</em>, u32 *<em>second</em>, const void *<em>data</em>, size_t <em>dlen</em>)
u32 hlookup32(const void *<em>data</em>, size_t <em>dlen</em>)
u64 hlookup64(const void *<em>data</em>, size_t <em>dlen</em>)
```

# 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.