Re:Hash Functions
by scentoni on Saturday June 03, 2023 @12:11PM
(#36177825)
Those are examples of useful functions. They are not examples of useful hash functions.
[ Parent
| on HN ]
I think you're conflating "functions used to build a hash table" with "functions used to build a dictionary ADT." A hash table doesn't have to serve the purpose of storing items in a dictionary ADT. A hash table where everything that's similar collides into the same buckets is just as useful for finding "a linked list of similar items" in O(1), as a hash table where everything gets its own unique bucket is useful for finding items in O(1).
Specifically, these functions to not provide "uniform distribution".
Re:Hash Functions
by jagged-chisel on Saturday June 03, 2023 @12:59PM
(#36178305)
That isn’t a requirement of an algorithm called a hash function
From the article:
> For a function to be useful as a hash function, it must exhibit the property of uniform distribution
It's also listed as the first property on the Wikipedia page:
Re:Hash Functions
by jagged-chisel on Saturday June 03, 2023 @05:52PM
(#36180874)
I can’t find the text you quoted. The article starts off:
> A hash function is any function that can be used to map data of arbitrary size to fixed-size values
And the first sentence in the section you link says
> A good hash function should map the expected inputs as evenly as possible over its output range.
It doesn’t have to be “good” to be a hash function.
That's not a meaningful definition of a hash function, then.
def hash(val):
return 0
Re:Hash Functions
by jagged-chisel on Saturday June 03, 2023 @06:44PM
(#36181225)
Yes, this is a hash function. Whether it’s “useful” or “good” is the purview of the architect.
Tangential edit: https://xkcd.com/221/
Re:Hash Functions
by pcthrowaway on Sunday June 04, 2023 @04:59AM
(#36184137)
The best thing about that one is that it seeds the panel with a random number every time you refresh
Re:Hash Functions
by throwmeaway1212 on Saturday June 03, 2023 @06:46PM
(#36181236)
That has a pretty uniform distribution..
It's true that these functions are in some sense very different to traditional hash functions, because they are designed to create "collisions" (or at least be similar) for elements that are similar. But I still think it is intuitive to use the term, maybe qualified as a "similarity hash" (I've also seen "perceptual hash" or "semantic hash"). In both cases we are describing a (potentially) large object with a short code. In normal hashes, the hash is supposed to be the same for objects that are exactly the same - in similarity hashes, that is softened to similar hashes for similar objects.
Re:Hash Functions
by pcthrowaway on Sunday June 04, 2023 @04:56AM
(#36184127)
Functions that create collisions can still hashes can't they?
Things like CRCs, Checksums are loosely considered hash functions: https://en.wikipedia.org/wiki/List_of_hash_functions
MD5SUM is a classic example of a hash function with a low (but still reasonable) chance of a collision