GDQuest / GDQuest/learn-gdscript

Chapter 24 (Creating Dictionaries) incorrectly states that hash values are unique

Open
#925 0 comments 0 reactions 0 assignees View on GitHub
content
Dominant language
GDScript
Stars
2.8k
Forks
235
PR merge metrics
No merged PRs in 30d

Description

**Issue description:**

In chapter 24, in the "How dictionaries work under the hood" box it is stated: "[...]In this case, hashing consists of converting a given key into a **unique** whole number.[...]" (emphasis mine).

This is incorrect. The hash values are not, in general, unique. As just one counter-example: Variant::hash() in variant.cpp returns a 32 bit value while "int" in GDScript is 64 bits. It's not possible to map every 64 bit value to a unique 32 bit value.

The explanation then goes on to claim (in effect) that you can't have two of the same key in a dictionary because they would have the same hash. This is also incorrect. While you can't have two of the same keys in a dictionary, you can have two keys with the same hash value (although a good hash function would make this unlikely).

I'm not sure it's possible to have a good, correct, concise explanation of hashes and their use in dictionaries here. The space seems too limited and IMHO it's probably not the appropriate level of detail at this point in the course.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.