3 ms·
> the hash function "randomly" but reproducably assigning a position to items Right, which is a pretty good description of what this does. It's random because
by munificent 9y ago
> the hash function "randomly" but reproducably assigning a position to items
Right, which is a pretty good description of what this does. It's random because it literally generates a pseudo-random number. And it's reproducible because it only generates it once and then stores it with the object to reuse it later.
> This way, it's more some indexed storage with randomized positions.
That's a great one-sentence description of a hash table. :)
- kevin_thibedeau 9y agoThat's not reproducable. Hashes are reconstructed from the original data even if it no longer exists as a formal in memory object. This is just a random ID.
- AgentME 9y agoJavascript Maps and Sets key off of the object's identity, not its contents.
- kevin_thibedeau 9y agoThat's all great. It isn't a hash, which by definition requires a hashing function applied to transform input data.
- ninkendo 9y agoShouldn’t they just call the attribute “objectIdentity” then? The fact that it’s used to access a hash table in some use cases doesn’t make it a “hash code”. You’d just as well call it an “equality checking code”, or name it after any other use case you could think of for a unique identifier. Ruby calls its equivalent construct “object_id” and that makes so much more sense.
- munificent 9y agoFor mutable objects in an OOP language, the object's identity is "the original data". The values that may happen to be stored in any other fields at various points in time are not part of the object's state and cannot affect the hash code. (If they could, mutating the object would change its hash code, which would be Very Bad.)