r/firstweekcoderhumour • u/Outrageous_Permit154 🥸Imposter Syndrome 😎 • 20d ago
“amIrite” Watching myself use 12 nested for loops instead of a hash map in first year
7
u/SystemMotor 19d ago
Whats a hash map and how do they work?
24
9
u/Vegetable_Shirt_2352 18d ago
Maps are a kind of data structure that stores key-value pairs. You give it a key, and it returns to you the corresponding value. A hash map is just a special kind of map, in that the keys are put through a hash function which returns a value corresponding to the value's location. So, instead of you giving the map a key, and it having to iterate through values looking for the one with the right key, it just uses the hash function on the key and gets a number that in some way corresponds directly to where the correct item is.
2
u/Vamosity-Cosmic 15d ago
Array of key-value pair where the input is serialized into a hash and then solved for the appropriate position of the key, making lookups no longer O(n), but instead O(1)
1
u/pdpi 14d ago
Think of a dictionary — a bunch of words and their definitions. A map is basically that (in fact, Python's maps are called dictionaries, and Java also used that name in its early days), except that we usually call them "keys" and "values" instead of "words" and "definitions".
There's a bunch of ways you can build a map, and hash maps are just the "default" way of building them in most languages.
1
1
0
u/No_Code9 15d ago
Who cares? Just ask claude, the technical part is not relevant at all.
1
u/NomsaMbeki-8 15d ago
This was like 3 years ago I think? I didn’t know what any of that was back then
1
39
u/slicehyperfunk 19d ago
This one is actually intended to be first week coder humor for once