Skip to content
Commit 49fb5f0a authored by Damian Krolik's avatar Damian Krolik Committed by Carles Cufí
Browse files

nvs: replace CRC with better hash function for lookup cache

NVS lookup cache currently uses CRC8/16 as a hash function
to determine the cache position, which is not ideal choice.
For example, when NVS lookup cache size is 512 and 256
subsequent NVS IDs are written (that is, 0, 1.., 255), this
results in 128 cache collisions.

It is better to use a dedicated integer hash function. This
PR uses one of the 16-bit integer hash functions discovered
with https://github.com/skeeto/hash-prospector

 project. The
hash function was additionally tested in the context of NVS
lookup cache using simple NVS ID allocation patterns as well
as using real device NVS dump.

Also, add a test case to verify that the hash function is
not extremely bad.

Signed-off-by: default avatarDamian Krolik <damian.krolik@nordicsemi.no>
parent 5f0efb94
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment