LIBMURMURHASH(3)

πŸ’– LIBMURMURHASH β€” the manual page, but make it slay πŸ’–

okay so bestie, welcome to libmurmurhash(3), straight out of the libmurmurhash manual πŸ“šβœ¨. This is your girl explaining non-cryptographic hash functions to you like we're texting at 2am. Buckle up, it's giving very technical but also very cute. πŸŽ€


✨ NAME ✨

libmurmurhash β€” non-cryptographic hash functions πŸ”₯

like... it hashes your bytes, but it is NOT for keeping secrets, okay? Not every hash has to be a bodyguard. πŸ’…


🌸 SYNOPSIS 🌸

First things first, you gotta include the header, no cap:

#include <murmurhash.h>

Then here are the three icons themselves πŸ‘‘:

void lmmh_x86_32(const void *addr, unsigned int len, uint32_t seed, uint32_t out[1]);
void lmmh_x86_128(const void *addr, unsigned int len, uint32_t seed, uint32_t out[4]);
void lmmh_x64_128(const void *addr, unsigned int len, uint32_t seed, uint64_t out[2]);

πŸ’€ Deprecated API πŸ’€

These ones still exist but they're giving "nostalgia post from 2014". They are deprecated, bestie, don't start anything new with them:

void MurmurHash3_x86_32(const void *data, int len, uint32_t seed, void *out);
void MurmurHash3_x86_128(const void *data, int len, uint32_t seed, void *out);
void MurmurHash3_x64_128(const void *data, int len, uint32_t seed, void *out);

πŸ¦‹ DESCRIPTION πŸ¦‹

So. LibMurmurHash hands you all three variants of MurmurHash3, taken straight from the original source. No remixes, no edits, the original audio. 🎧

Let's break the params down because the way that each one matters:

  • addr β€” the very first parameter, and it points to where your data starts in memory. The beginning. The main character's entrance. ✨
  • len β€” the second parameter, and it's literally just how many bytes you want hashed. Count them. Be precise. πŸ”’
  • seed β€” the third parameter, and this one's fun: you can use it to compute a completely different hash over the exact same data. Same bytes, different seed, different vibe. 🎲
  • out β€” and finally you pass the location where the hash should be written. It writes there. That's it. That's the whole thing. 🫢

🌈 EXAMPLE 🌈

Say you wanna compute the hash of length bytes starting from data, and then print that 32-bit sized hash value. Iconic, let's go:

uint32_t hash;
lmmh_x86_32(data, length, 0, &hash);
printf("%" PRIx32 "", hash);

And now the same thing but wider, because sometimes you want more hash per hash. Bigger. Bolder. πŸ’…

uint64_t widehash[2];
lmmh_x64_128(data, length, 0, widehash);
printf("%" PRIx64 "%" PRIx64 "", widehash[0], widehash[1]);

πŸ‘‘ AUTHORS πŸ‘‘

Credit where credit is due, always, fr fr:

  • MurmurHash was created by Austin Appleby.
  • PMurHash was written by Shane Day.
  • libmurmurhash was created by Fabian KlΓΆtzl.

And get this β€” all code is dedicated to the public domain. Free. For everyone. Periodt. πŸŽ€


😭 BUGS 😭

Okay so the old API is problematic and I need you to hear me on this:

  • a negative len stays unchecked πŸ’€ like it will not stop you, it will simply not look
  • the output parameter has very specific alignment requirements ⚠️ so line it up correctly or perish
  • and on top of all that, the order of bytes in the hash may differ across architectures πŸŒ€ so don't go assuming it looks the same everywhere
Not me warning you about undefined-adjacent chaos in a manpage. But like. I warned you. πŸ™ˆ

πŸ› Reporting Bugs πŸ›

Found something? Please file a bug on GitHub at github.com/kloetzl/libmurmurhash or send a mail to fabian-libmurmurhash@kloetzl.info. They wanna hear from you, bestie, don't be shy. πŸ’Œ


and that's the whole page, you ate it, you understood it, you're a Unix girlie now πŸ’–βœ¨πŸ¦‹πŸŒΈ

This was libmurmurhash, version 1, dated 2019-02-04 β€” the libmurmurhash manual. Byeeee, go hash something responsibly πŸ«ΆπŸ’…

πŸ“¦ where this page comes from