src/lookup3.h(3)

πŸ“¦ version 6.1.3, in epel 9

🌸 src/lookup3.h β€” NAME 🌸

okay so bestie, welcome to src/lookup3.h, which is literally a 32bit hash function implementation. that's it, that's the vibe. πŸ’…

this whole page is from the torque manual, section 3, and it's giving "auto-generated but make it cute" β€” we're about to get into it. πŸŽ€


✨ SYNOPSIS ✨

like, first thing's first, you gotta pull it in:

#include <pbs_config.h>

πŸ¦‹ Functions

  • uint32_t hashword (const uint32_t *k, size_t length, uint32_t initval) β€” this works on all machines. no cap, all of them.
  • uint32_t hashlittle (const void *key, size_t length, uint32_t initval) β€” hashlittle() -- hash a variable-length key into a 32-bit value.
  • uint32_t hashbig (const void *key, size_t length, uint32_t initval) β€” hashbig(): This is the same as hashword() on big-endian machines.

πŸ’– Detailed Description πŸ’–

32bit hash function implementation.

Taken from: http://burtleburtle.net/bob/hash/

like... it's a hash function library, babes, what more do you want from her 😭 she's been doing this since forever and she's iconic for it.


πŸ‘‘ Function Documentation πŸ‘‘

⭐ uint32_t hashword (const uint32 * k, size_t length, uint32 initval)

This works on all machines. ✨ To be useful, it requires:

  • that the key be an array of uint32's, and
  • that all your machines have the same endianness, and
  • that the length be the number of uint32's in the key

The function hashword() is identical to hashlittle() on little-endian machines, and identical to hashbig() on big-endian machines, except that the length has to be measured in uint32s rather than in bytes. hashlittle() is more complicated than hashword() only because hashlittle() has to dance around fitting the key bytes into registers. πŸ’ƒ she's literally doing choreo in there, respect her.

🫢 Parameters

  • k β€” the key, an array of uint32 values
  • length β€” the length of the key, in uint32s
  • initval β€” the previous hash, or an arbitrary value

🌈 uint32_t hashlittle (const void * key, size_t length, uint32 initval)

hashlittle() -- hash a variable-length key into a 32-bit value. periodt.

πŸ“ Parameters

  • key β€” the key (the unaligned variable-length array of bytes)
  • length β€” the length of the key, counting by bytes
  • initval β€” can be any 4-byte value

πŸ’œ Returns

Returns a 32-bit value. Every bit of the key affects every bit of the return value. Two keys differing by one or two bits will have totally different hash values. like, one tiny bit flip and she's a whole different person, that's main character energy fr fr πŸ”₯

The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do:

h = (h & hashmask(10));

In which case, the hash table should have hashsize(10) elements.

If you are hashing n strings (uint8 **)k, do it like this:

for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);

By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this code any way you wish, private, educational, or commercial. It's free. 🫢 Bob ate, honestly, king behavior.

Use for hash table lookup, or anything where one collision in 2^^32 is acceptable.

⚠️ Do NOT use for cryptographic purposes. like seriously bestie, do not. she is NOT that kind of girl, this is not a crypto hash, use her for lookup tables only, i'm begging πŸ™ˆ

🧚 uint32_t hashbig (const void * key, size_t length, uint32 initval)

hashbig(): This is the same as hashword() on big-endian machines. It is different from hashlittle() on all machines. hashbig() takes advantage of big-endian byte ordering. big-endian stans stay winning πŸ’€βœ¨


πŸŽ€ Author πŸŽ€

Generated automatically by Doxygen for torque from the source code. (so nobody hand-wrote this, it's a robot doing its little robot thing, we still love her πŸ€–πŸ’–)


and that's the whole page, bestie! πŸ¦‹ this was src/lookup3.h(3) from Version 6.1.3, dated Sat Jan 21 2023 β€” mwah, go hash something responsibly, ily, bye! πŸ’…πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from