Fast and easy Hash function?

I want to keep a list of files of the SD card in RAM. So a kind of dictionary. The files can be in an arbitrary folders (or subfolders) in the SD card. In the code I want to quickly check if a given file name (with path) exists in the SD card.

Instead of storing a list of all file names and paths of the SD card in RAM, I was thinking of storing only a hash of each filepath to save RAM.

Do you know a fast and simple algorithm to convert a file path to a hash? The resulted hash id should be max 32-bit if possible.

Combine a 32-bit xorshift:

With a generic byte hashing algorithm:

Xorshift32 is guaranteed to have a full 32-bit period if used as the state transition function of a PRNG.
The generic algorithm has no guarantees, best measure it to make sure you’re happy with it.

(I used this hashing/checksum algorithm to detect when the EEPROM data had been corrupted.)

1 Like

Excellent! Looks like what I need.

1 Like

There may be some ways to speed it up if it’s not fast enough,
particularly if you can guarantee that the input size is a multiple of 4 bytes.