Maps in C++ (std::map and std::unordered_map)

  Рет қаралды 222,373

The Cherno

The Cherno

Күн бұрын

Пікірлер: 301
@TheCherno
@TheCherno 2 жыл бұрын
Hope you all enjoyed the latest addition to the C++ series! Let me know if you have any questions about maps below 👇 Also definitely check out Hostinger for all your web hosting needs, and use coupon code CHERNO for a discount: hostinger.com/cherno
@brandonmint00721
@brandonmint00721 2 жыл бұрын
Please please make a video about named pipes
@ed7590
@ed7590 2 жыл бұрын
Please could you talk about dealing with hash collisions? In your vector video and others you did a great job explaining how they're implemented in memory. Something similar for maps and unordered_maps would be really helpful. Thanks for all the great videos!
@joachimfritscher5688
@joachimfritscher5688 2 жыл бұрын
Can you do a vid on template metaprogramming? And as code review it would actually be nice to go over a library container such as vector and explain what is going on. Especially as a beginner /intermediate this feels like it's a whole other language
@rajagopal1373
@rajagopal1373 2 жыл бұрын
@@brandonmint007216 Yoiuu. €1€98£8 98IIIYU78
@oleholgerson3416
@oleholgerson3416 2 жыл бұрын
thanks Cherno, as always great content. Would be great if you could also talk about std::equal_to in the context of unordered maps and hash collision resolution etc. Especially what happens if hash collisions occur. Keep up the good work.
@crystalferrai
@crystalferrai 2 жыл бұрын
15:20 A hash function is not required to return a unique hash. Two things with the same hash will be stored in the same bucket, which is inefficient for lookups, but it will function fine. The hash provides fast access to the appropriate bucket. The equality operator is what determines if a key actually matches. You should strive to make unique hashes for performance reasons, but hash collisions will not compromise the map. 26:50 -If two cities have the same population and that is all you are using for comparison, then they will appear in an arbitrary order but still appear next to each other in the map. Nothing is broken in this case. You just will not be able to rely on their order remaining consistent as the map changes.- This is incorrect. Not sure what I was thinking when I wrote it.
@raksipulikka
@raksipulikka 2 жыл бұрын
Yup and in addition it's possible that different hashes end up in same bucket
@felipegutierrez3477
@felipegutierrez3477 2 жыл бұрын
You can come up with a great hash function that minimizes the amount of collisions, but at the end of the day you can compromise a bit of speed when creating the hash map through linear probing or other methods (O(N)) to get perfect collision-less hash maps by sampling the next index until you are sure that you don't have collisions.
@Chakaramba
@Chakaramba 2 жыл бұрын
As for now, it seems like youtube should give a platform for contributing into videos' drafts with deep fakes :3 Im pretty sure that we could bring all the educational stuff to a brand new level
@rhoynarr
@rhoynarr 2 жыл бұрын
"26:50 If two cities have the same population and that is all you are using for comparison, then they will appear in an arbitrary order but still appear next to each other in the map. Nothing is broken in this case. You just will not be able to rely on their order remaining consistent as the map changes." you are wrong. in c++20 the population is used for the key, if it's equal between two objects the compiler will assume that you are referring to the same object.
@crystalferrai
@crystalferrai 2 жыл бұрын
@@rhoynarr You are correct. I am not sure what I was thinking when I wrote that 6 months ago.
@SonicFan535
@SonicFan535 2 жыл бұрын
21:01 - When using find(), you can avoid the second lookup required by at() by saving the iterator returned by find(). For example: if (const auto it = cities.find("Berlin"); it != cities.end()) { const CityRecord& berlinData = it->second; // ... } I recommend always doing this whenever you use find() to do a lookup. If you only need to know whether the element exists or not, you can use ".count(key) != 0" (or ".contains(key)" in C++20) instead.
@jacobm1190
@jacobm1190 2 жыл бұрын
I actually had this little mistake a couple times in my current project. Very cool tip.
@metal571
@metal571 2 жыл бұрын
100% agree. Worth noting also that your "it" is taking advantage of C++17 if-initializer syntax, so this isn't available before that language version
@DrShwynx
@DrShwynx 2 жыл бұрын
I’ve personally always used .count() and then accessed with either [] operator or .at(). I didn’t know about .find()
@Gmitbotw
@Gmitbotw 2 жыл бұрын
Also, if you want to check wether or not a map contains a key but don't need to access its value, you can use std::unordered_map::contains(key), available in C++20
@quademasters249
@quademasters249 2 жыл бұрын
@@DrShwynx That works with vectors but not a map. "find" in a vector is a linear search. You could use for(auto& val : vector ) to iterate over the vector too for searching and just "break;" out of it. Find is useful if you want to use the iterator later on and not just finish up in the loop.
@AxElKo440
@AxElKo440 2 жыл бұрын
Hey Cherno, I started watching you 5 years ago, while I was in my first year of college. I saw every video you made. I patiently rewrote line by line your sparky engine, but then I had so many school duties and I had to start working to pay for the college, so that I had to stop following you. Now 5 years later I'm back and ready to continue. I don't know what is so magical about working with OpenGL and graphics, but it's still my dream job to work with OpenGL. I tried many specialization like neural nets, hardware design in VHDL, motor control, image processing but nothing got me interested as OpenGL. Best part of college was C++ course, where I applied everything you taught me. Thank you so much for your content and god bless your family.
@arminbosten8159
@arminbosten8159 2 жыл бұрын
Yes! This C++ series is truly a gold mine :D
@oj0024
@oj0024 2 жыл бұрын
The find + at pattern at 20:50 does twice the amount of necessary work, because find already returns a pointer to the data.
@CamdenVaughan
@CamdenVaughan 2 жыл бұрын
Hey Cherno, would love a “productivity in c++” kind of video maybe going over keyboard shortcuts or ways to code more efficiently in visual studio or just in general
@msamkleaf9945
@msamkleaf9945 2 жыл бұрын
Screw you doctor your pills made me feel worse.
@SaintMorning
@SaintMorning Жыл бұрын
@Ralph Reilly there is nothing personal about how to use vs's editor functionality. you would be surprised how much time you could save if someone showed you how to use it properly.
@jeffvenancius
@jeffvenancius Жыл бұрын
Look out for CUA, it's awesome what you can do in basicaly ANY text editor.
@theglowpt3
@theglowpt3 Жыл бұрын
Vim. Keybindings. Full. Stop.
@MrCleverOnion
@MrCleverOnion Жыл бұрын
It's called vim homeboy
@milo20060
@milo20060 2 жыл бұрын
100/100 c++ videos from this playlist watched! Been very informative so thanks for this series!
@oj0024
@oj0024 2 жыл бұрын
One important thing to mention is that the std:: (unordered-)map/set containers are very slow, because they need to guarantee pointer stability and abi breaks hinder compiler vendors from improving them. You can get speedups of sometimes up to 5x by just using a different hash map, e.g. absl::flat_hash_map or tsl::robin_map.
@marcspecter
@marcspecter 2 жыл бұрын
can you link to some reliable anaysis/commentary on this?
@theKStocky
@theKStocky 2 жыл бұрын
I will counter this by saying. This does not matter unless it is showing up in performance captures as a problem. Use the standard library liberally and as much as you can. It is fantastic and should be the first tool that you reach for. And if you happen to notice slow downs and find that something in the standard library is actually the issue, then start to look elsewhere for replacements. As a software engineer, it is the API and guarantees that that API gives that matter most. Software has to be correct before it can be fast. And if you can just swap something out later for something that has a faster implementation, but the same API then it's probably easier to just use the standard library before reaching beyond it when it might be a non-issue anyway.
@ShivamJha00
@ShivamJha00 2 жыл бұрын
@@theKStocky true
@SheelByTorn
@SheelByTorn 2 жыл бұрын
Define slow here, what is slow are you talking about? Insertion? Appending? Search? deletion? Be specific since all data structures has their pro's and cons.
@oj0024
@oj0024 2 жыл бұрын
@@marcspecter Search for Martin Ankerl's Hashmaps Benchmarks for a recent (2019) thorough hash table benchmark
@gaureshbhati8484
@gaureshbhati8484 2 жыл бұрын
Expecting more content in this C++ series. This series is a gem. 🔥
@brainloading5543
@brainloading5543 2 жыл бұрын
Indeed it is
@garba1204
@garba1204 2 жыл бұрын
Am totally cured off herpes (hsv1) and am so so happy right now thanks Dretiko on KZbin for your good work,,
@londonerwalks
@londonerwalks 2 жыл бұрын
Thanks for your videos Cherno. I only just stumbled across your channel and your videos have been a really useful recap for my rusty C++ skills from over a decade ago!
@leeroyjenkns5182
@leeroyjenkns5182 2 жыл бұрын
Never would've thought I'd learn basic c++ in two weeks knowing just js but here we are. This series is wild.
@ykjo4010
@ykjo4010 2 жыл бұрын
Finally a C++ series tutorial with an old style thumbnail!
@wintiepower7225
@wintiepower7225 2 жыл бұрын
Great video! A follow up video about std::set in which you compare the different sets to the different maps would be awesome! Keep it up!
@wintiepower7225
@wintiepower7225 2 жыл бұрын
Or perhaps about the container adaptors like stack, queue and priority_queue
@bunpasi
@bunpasi 2 жыл бұрын
15:51 What you're trying to do is called aggregate initialization. It requires you to also use curly brackets. Unfortunately you'll need to use push_back instead of emplace_back because the parameters aren't passed through, but the object is first created and then passed through. Thanks for the great content. Keep them coming!!
@SHSULeadTrumpet
@SHSULeadTrumpet 2 жыл бұрын
I love the honesty of how you handled the odditites in the industry, I love that you explain multiple ways of doing something even if there is a less conventional way as a just in case, I love that you actually explain how to read the error messages and output errors and most of all I love your accent. Thank you so much for being clear and connecting dots.
@ohwow2074
@ohwow2074 2 жыл бұрын
Oh nice. Finally a video for the C++ series. I got so excited when I saw the notification.
@beboba2498
@beboba2498 Жыл бұрын
at 21:18 you're searching for element twice, at "find" call and at "at" call The better way would be to get an iterator of "find" and then use iterator instead of "at" call For unordered_map it might be not that important but it is for a map
@TheMR-777
@TheMR-777 2 жыл бұрын
15:48 Hey TheCherno, it can be solved by passing the arguments as "initializer list-looking" syntax, as emplace_back is requiring a single Object. So, the arguments have to be a single object. They can be: .emplace_back(CityRecord{ "CityName", 50000, 70, 70}); Or just, .emplace_back({ "CityName", 50000, 70, 70}); By the way, I'm a long-term TheCherno follower, and it's the first time I suggested something to my mentor :)
@vtgordo
@vtgordo 5 ай бұрын
This was big for me. I am still at 12 minutes into video, and tried to compile. Compiler said nope. Something about no overloaded function had that many parameters. ChatGPT showed me how to build constructors for my struct (messy). This cleaned that right up!
@TheMR-777
@TheMR-777 5 ай бұрын
@@vtgordo It's a pleasure to know :)
@adrianwild957
@adrianwild957 3 ай бұрын
That was actually perfect for a beginner. Thank you!
@shreyadalvi1532
@shreyadalvi1532 2 жыл бұрын
Thank you so much to put more content in this series. Waiting for more videos on data structures
@ycombinator765
@ycombinator765 2 жыл бұрын
💯 completed. Thank You. Its a historic moment.
@postdisc0
@postdisc0 Жыл бұрын
wow, i learned about at() throwing in the morning getting to work, and the same day I actually used this knowledge in my work process! so cool, never payed attention to that before
@6px
@6px 2 жыл бұрын
100th video in the playlist!🔥
@ucheachay5885
@ucheachay5885 2 жыл бұрын
Yes !!!, Thanks so much for these. Please more on c++ data structures
@Wwise_sounds
@Wwise_sounds 2 жыл бұрын
I was almost two weeks behind on my assigment. this helped me to finally get the courage and finish it. thanks!
@tljstewart
@tljstewart 2 жыл бұрын
Gold, I'd expect nothing less. Thanks Cherno
@luisfernando3405
@luisfernando3405 2 жыл бұрын
Guy, i'm from Brazil, english not is my native language, but i need to say that this channel is my favorite font to learn and apply your content; Thank you for this video, i very like to be here. 🎯🚀
@joshdoesthings7836
@joshdoesthings7836 2 жыл бұрын
This is so cool! I was just doing a Clash of Code on CodingGame yesterday and asking a guy about these! Now, you're posting a video on them: A nice coincidence!
@avimalka5362
@avimalka5362 2 жыл бұрын
Like your videos a lot, hope to see more of these! I will be nice if you could have videos about C++20 features. P.S You could have mention that c++20 has contains() for maps.
@MLBB_CHILL
@MLBB_CHILL 2 жыл бұрын
100th video of the c++ series. Well done Yan!!
@gaiashkenazy
@gaiashkenazy 2 жыл бұрын
Yes!! Continue this series I love it!!!
@Phroggster
@Phroggster 2 жыл бұрын
STL error/warning messages are so much fun to try and comprehend. At least C# custom hashing is wickedly easy to implement, albeit a bit challenging to implement "correctly" (with uniformly-distributed hash codes). All of this discussion about std::map, and you just lit the light bulb for a problem that I was dealing with. Thanks Cherno!
@Phroggster
@Phroggster 2 жыл бұрын
For the next episode, don't forget to compare a std::map to a constexpr std::vector, because compilers don't already do enough work on our behalf.
@YANZH-p2o
@YANZH-p2o Жыл бұрын
Looking forward to the video of the performance between these maps!!!🤩
@gohli8457
@gohli8457 2 жыл бұрын
Fantastic video for C++ learner!
@tamp1o
@tamp1o 2 жыл бұрын
Thank you, for saving my course project.
@shriram5494
@shriram5494 2 жыл бұрын
20:50 now you can use std::unordered_map::contains in c++20 instead of checking if find() equals the past-the-end
@mobslicer1529
@mobslicer1529 2 жыл бұрын
the equals sign is because of microsoft's new font having ligatures, you can disable it
@rami_atallah
@rami_atallah 2 жыл бұрын
Thanks for c++ tutorial/series. You're amazing keep on
@waldek4798
@waldek4798 Жыл бұрын
Sure, performance video about maps would be awesome!
@CastleBomber
@CastleBomber Жыл бұрын
damn, in 10 seconds you've solved my c++20 problem. twas a hardly laugh to see that i've been rockin' C++14 the whole time
@ajitbansal5120
@ajitbansal5120 2 жыл бұрын
When using string as a key for map it’s generally good to pass a string comparator func as well
@mjthebest7294
@mjthebest7294 2 жыл бұрын
Of course we want performance comparisons and/or performance measuring tips in general. :)
@coderoyalty
@coderoyalty 2 жыл бұрын
Wow bro… you gat me dripping … I was just thinking of it about an hour ago…
@maheshchoubey
@maheshchoubey 2 жыл бұрын
Very well explained , appreciate for your hard work and honest effort !!
@imereque
@imereque 2 жыл бұрын
Thank you very much for all the explanations and examples, Cherno! Would definitely love to see a benchmark comparison for various kinds of maps! On a separate note, you once mentioned thinking about a video on variadic templates - would be excited to see that one too!
@thehappyvultur2886
@thehappyvultur2886 2 жыл бұрын
Nice video, however, at 15:31, when 2 keys give the same hash they don't necessarily map to the same element, they only do it when they compare equal, so, just returning 0 in the hash function will not break the unordered_map, it will only make it really slow. Also, your setup seems to implicityly define some constructors and operators as, with `g++ -std=c++17`, in the std::vector example you needed to define the constructor and for using a custom type for the key in a std::unordered_map it also needed defining operator==. I think you should mention that you also need to define something that would tell if 2 keys are equal
@GamingDemiurge
@GamingDemiurge 2 жыл бұрын
I love this little focus videos man. Keep it up!
@rcookie5128
@rcookie5128 2 жыл бұрын
Appreciate this series so much!
@edensheiko
@edensheiko 2 жыл бұрын
!the best c++ channel
@cghost4yt
@cghost4yt 2 жыл бұрын
Fantastic channel! really nice to have as support when I'm studying. I think a video about concepts and constraints in C++20 would be interesting
@mikeorioles
@mikeorioles Жыл бұрын
This video helped a ton. Thanks as always.
@justinpakarno4346
@justinpakarno4346 2 жыл бұрын
Keep streaming Yan, it makes my day.
@kirubel_t7150
@kirubel_t7150 2 жыл бұрын
you are basically screwed. absolutely loved that word "screwed".🤣🤣
@gaurav3588
@gaurav3588 9 ай бұрын
since when Mr. Beast is teaching programming???
@Killerkraft975
@Killerkraft975 3 ай бұрын
This didn't age well LOL
@chess-code-and-math
@chess-code-and-math 3 ай бұрын
LOL mrbeast is teaching programming
@xuetu42
@xuetu42 Жыл бұрын
Your videos are so funny and teach me a lots
@aidanmorrison5925
@aidanmorrison5925 2 жыл бұрын
Great video as always. I'd be keen to see the performance benchmarking of standard and unordered maps. I've heard that there's a couple of dimensions to the problem, in particular if the keys, (when strings) often start with identical substrings (common issue naming keys, eg 'address_line_1', 'address_line_2' etc) as this affects how long the string comparisons take to find the location in the tree. So apparently ordered maps can be faster for small collections, where a very small tree search can outstip the hash function, and the transition point depends on how distinct (or overlapping) the start of the strings in the keys are on average. I haven't done any benchmarking myself, but would be great to see.
@PedroOliveira-sl6nw
@PedroOliveira-sl6nw 2 жыл бұрын
I wonder if having a vector and then a map/unordered_map is too much for situations where you have too many elements (+1M) and you are iterating (i.e. every frame) but also need that fast lookup. Then we could iterate over the vector but lookup through the map. Maybe is not the best types but some kinda of searchable index that would retrieve the vector index of the object.
@user-sl6gn1ss8p
@user-sl6gn1ss8p 2 жыл бұрын
I was wondering the same
@deanjohnson8233
@deanjohnson8233 2 жыл бұрын
This is a common space vs. time trade off. You are taking up more memory for an increase in speed. Depending on how you use the data, yes something like this can be worthwhile. Just remember that simply consuming more memory can hurt performance because it can affect caching performance. You might hear people call this kind of stuff a “hybrid” data structure as well. This is referring to some combination of two other data structures to get the benefits of both. This is never without downsides, but those downsides might not matter for your use case.
@user-sl6gn1ss8p
@user-sl6gn1ss8p 2 жыл бұрын
@@deanjohnson8233 so, "profile it" it is I guess : p
@ChlorieHCl
@ChlorieHCl 2 жыл бұрын
16:07 I think you don't need the constructor now if you're using C++20. C++20 permits aggregate initialization with parentheses now.
@ChlorieHCl
@ChlorieHCl 2 жыл бұрын
Also you can specialize the std::hash struct without opening the std namespace, just use template struct std::hash { things } and you're good to go.
@Charles_Zheng
@Charles_Zheng Жыл бұрын
It has been a year, and i still want to see the performance comparison and more c++ series!!!
@ZulnorineP_Coding
@ZulnorineP_Coding 6 ай бұрын
We can also use the operator= to get the specific element in the vector :
@FreeDomSy-nk9ue
@FreeDomSy-nk9ue 2 жыл бұрын
In C++20 you could do map.contains() to check if an element exists.
@oiyo6241
@oiyo6241 2 жыл бұрын
Bro, perfect timing.
@oblivionronin
@oblivionronin 2 жыл бұрын
I was already familiar with std::map, but i was not aware of the constness of the operator[] and how it always insert an element regardless, good stuff, keep it up ! Definitly interested to see a benchmark video !
@dealloc
@dealloc 2 жыл бұрын
You can have best of both worlds with an index map; store values in a Vec and a map of hashes to indexes. Although the tradeoff is that more memory is used.
@kdowd161
@kdowd161 Жыл бұрын
You are to C++ as Shakespeare is to the rhyming couplet - that was just great stuff....
@SilkRed
@SilkRed 2 жыл бұрын
Please continue this series
@Uvuv6969
@Uvuv6969 2 жыл бұрын
I’m confused on the second quarter, after around 9:30. My brain just doesn’t want to comprehend all that new stuff rn. I’ll be coming back to this video later!
@Uvuv6969
@Uvuv6969 2 жыл бұрын
Update: im back bitches
@R4ngeR4pidz
@R4ngeR4pidz 2 жыл бұрын
I actually learned this today, would have liked to have this video a couple hours ago hahaha
@JorgeLuis-ts6qp
@JorgeLuis-ts6qp 2 жыл бұрын
Why the sintaxis to define the hash function is so complex? Why is not possible to define a hash method in the struct? Just the same as it is possible to define the less than operator to use std::map
@beizhou4025
@beizhou4025 Жыл бұрын
Do we need to write a customised hash function for using std::vector as the key?
@nathanielfincham704
@nathanielfincham704 Жыл бұрын
Once again you summarize a key data structure better than my college professor.
@sunnyshukla3502
@sunnyshukla3502 2 жыл бұрын
"Why are there two different types of maps? Because there are different types of maps." - Cherno 2022
@hackpulsar
@hackpulsar 2 жыл бұрын
19:46 that`s why i love c++, sometimes it`s so tricky and unpredictible
@mikaay4269
@mikaay4269 2 жыл бұрын
Python developers when Cherno says "Expensive" *cricket noises*
@mastershooter64
@mastershooter64 2 жыл бұрын
i would love a video going over a bunch of beginner, intermediate, advanced projects in c++ since yk the best way to learn to code is to...actually code lol
@pranalisuhaspatil
@pranalisuhaspatil 2 ай бұрын
Hey Brother. I am Pranali from India. I work as C++ developer. Your videos helped me a lot. What I liked most is short & detailed videos. can you make the same on DSA & design patterns?
@A-_AkramahFaizi
@A-_AkramahFaizi 2 жыл бұрын
@The Cherno Please make a video for all the shortcut you use for coding, like at 06:55 and 21:00. I am highly anticipating it.
@franciscomalmeida
@franciscomalmeida 2 жыл бұрын
Note that using std::pmr memory resources can significantly improve your containers performance, provided you set your memory resource objects appropriately.
@singhHarleen
@singhHarleen Жыл бұрын
Hey would love to see the performance benchmarks you mentioned towards the end of the video. Thanks for the brilliant content
@TheFinalCutBG
@TheFinalCutBG 2 жыл бұрын
Finally! A new video!!!!!!!
@amayesingnathan
@amayesingnathan 2 жыл бұрын
Another great video! I'd love to see a video where you write your own memory allocator, maybe talking about different ways to implement them, and what scenarios each way might provide a boost in performance for. I've been working on my own physics engine and took a lot of inspiration from Box2D which uses a couple of different custom allocators for different situations, and I'd love to learn more.
@hymen0callis
@hymen0callis 2 жыл бұрын
Thanks for reminding me of binary search. Haven't used that algo in years, mainly because the containers I work with tend to be unordered. But good to know, that you *could* use it.
@bongcloud757
@bongcloud757 2 жыл бұрын
Wow i love that visual studio theme! Sir can you please tell what theme is it?
@Tag23456
@Tag23456 2 жыл бұрын
I came for Cherno video. I stayed for the monologue.
@daleowens7695
@daleowens7695 2 жыл бұрын
A proper rigorous benchmark comparing map, unordered_map, and vector would be great. I constantly read benchmarks are meaningless because they weren't implemented correctly. It would be nice to see an example of that. It would also be nice to see a more sophisticated process than simply printing times from a timer. Perhaps memory usage and the underlying data structures that give rise to whether a map is ordered or not. Hell, cache friendliness of the three methods would be cool to see as well.
@garthenar
@garthenar 2 жыл бұрын
I'm glad you're still doing these!! These video's help a lot. I''m not doing maps yet but I know I'll be back here in no time. I can't wait until I know enough to follow your code review videos!
@hugoalmeida1291
@hugoalmeida1291 2 жыл бұрын
I missed this series so much buddy =]
@tljstewart
@tljstewart 2 жыл бұрын
Would love to see some Cmake stuff, I find I am able to get up and running with python, importing package and sharing code quickly, would be nice to see your approach with Cmake
@samuelmartin7319
@samuelmartin7319 2 жыл бұрын
So I know that the C++ std::map uses a red-black tree implementation. I can't remember where I read this, but I thought it said that std::map uses an array to implement a red-black tree. If that is correct, why would you implement it using an array? How would it be any better? In a traditional rbt, any rotation will be O(1), but using an array implementation you would need to shift a lot of elements up and down the tree.
@h.hristov
@h.hristov Жыл бұрын
Please make the benchmark performance comparison between map and unordered_map! Thanks!
@gone57576
@gone57576 2 жыл бұрын
the audio doesn’t fit the video well, but the general quality is much better!
@Lynx-ji5gz
@Lynx-ji5gz 2 жыл бұрын
your video is amazing
@jeanahollings
@jeanahollings Жыл бұрын
Thank you, as always, I learn more from you than I would have ever even thought to ask. If you're looking for request though, I'd like to understand the hashing process. What is it doing with that string that somehow magically makes everything faster? Is the string converted to an int and then the int used as an index? How is that faster? I'm sure I'm not even asking the right question but I bet you could provide the right answer anyway because you have a deep understanding that I hope to get to at some point.
@supercyclone8342
@supercyclone8342 11 ай бұрын
This video reminded me of why I put off learning C++ for so long! I've been using C# for years and even learned C last year, but C++ still scared me lol. I was going through your playlist and following along pretty well and then I started skipping around... and well... That hash setup is gross XD. I'll stick with it tho!
@roman-fo2sk
@roman-fo2sk 2 жыл бұрын
great video as always, you should give a talk at cppcon about teaching cpp next year
@weirddan455
@weirddan455 2 жыл бұрын
15:30 Would it really override data if your hashes come out to the same? I thought it would do a memcmp or something under the hood as a way of handling collisions.
@SonicFan535
@SonicFan535 2 жыл бұрын
It stores the colliding elements in the same bucket and handles lookup by doing a linear search using the equals operator, so yeah there is no overriding of data. The worst that can happen is poor performance.
@MirralisDias
@MirralisDias 2 жыл бұрын
I was about to comment about this
@inakisoler4221
@inakisoler4221 2 жыл бұрын
If you have a map with a key and some struct, how can you find a specific struct inside the map if you are given a struct to look for and not a key? For example, you want to erase Paris from the map in a function and for that you are given as parameter a CityRecord, but not a "Paris" string.
@BhavinMoriya-i8i
@BhavinMoriya-i8i 6 ай бұрын
Fantastic video:) Do you have to reference berlinData while creating the instance? May I know why?
@XAE-L-xy7mi
@XAE-L-xy7mi 2 жыл бұрын
Thanks for the great videos. Yes, a video map benchmark please :)
What exactly is NULL?
18:06
The Cherno
Рет қаралды 195 М.
Is C BETTER than C++ for beginners? // Code Review
31:16
The Cherno
Рет қаралды 26 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 31 МЛН
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 2,9 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
ITERATORS in C++
17:09
The Cherno
Рет қаралды 212 М.
Stop using std::vector wrong
23:14
The Cherno
Рет қаралды 149 М.
Map and HashMap in Java - Full Tutorial
10:10
Coding with John
Рет қаралды 601 М.
Back To Basics: C++ Containers
31:41
javidx9
Рет қаралды 188 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 825 М.
Why Didn't He Get the Job? Let's Find Out! // Code Review
27:25
The Cherno
Рет қаралды 148 М.
Hash Tables and Hash Functions
13:56
Computer Science Lessons
Рет қаралды 1,6 МЛН
Harder Than It Seems? 5 Minute Timer in C++
20:10
The Cherno
Рет қаралды 215 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 31 МЛН