A tutorial on implementing a hash table in C++ via separate chaining.
Жүктеу.....
Пікірлер: 175
@Mmmmmkoogfssdvbhvggg3 жыл бұрын
Man! You are just amazing! I have coding interviews in a few days, and you just saved my ass. You have implemented almost all DS, and they are so neat and clean, the way it should be! Thanks man!
@noemanakram6581
2 жыл бұрын
what did u do
@Snake-ez1kl
Жыл бұрын
@@noemanakram6581 he is the ceo of google now
@mohammedhayyoun
5 ай бұрын
@@Snake-ez1kl LMAO
@luceracox76864 жыл бұрын
This was incredibly helpful. You explain each step clearly which is hard to find! Thank you:)
@MrJQ3d2 жыл бұрын
super amazing work man, props! you're a great programmer and teacher.
@nadiequintero99814 жыл бұрын
Very useful and clear video, thank you for helping me understand hash tables better.
@CodingJesus
4 жыл бұрын
No problemo
@soniasingh5323 жыл бұрын
love the perfection. the way you type and your explanation
@killingjoyandmemeing
3 жыл бұрын
thanks
@strawberrysultan3 ай бұрын
Thank you!! This was so helpful. Supplementing my classes with your videos now - my teacher only reads from the book.
@nordgaren23582 жыл бұрын
Question: Do you actually need the keyExists bool? Couldn't you just return in the for loop if the key exists after replacing it?
@brycejohansen71142 жыл бұрын
Why do you put return at the end of functions that have void as their return value?
@franky02264 жыл бұрын
That was a neat explanantion! thanks a lot, man!
@killingjoyandmemeing
3 жыл бұрын
welcome
@cnp46552 жыл бұрын
Since perfect hashing function is assumed, why use the for loops. Doesn't that make the time complexity greater than O(1)?
@chikin88953 жыл бұрын
This is actually ASMR lol
@jakobhuetter Жыл бұрын
Very helpful! I do have one question tho: you are saying in the beginning, that this would be hashing with seperate chaining. But wouldnt you append the value to the list of the other ones of the same hash value instead of replacing them in seperate chaining? Line 46 in your code. Or am i missing something there?
@shawn43652 жыл бұрын
how would I change this if I wanted each key to hold all of the different names instead of replacing the value
@adnanlokhandwala90023 жыл бұрын
Thank you, this was quite helpful, and quite catchy too XD. Keep up the good work, and all the very best
@CodingJesus
3 жыл бұрын
Thanks
@killingjoyandmemeing
3 жыл бұрын
@@CodingJesus welcome
@greglouis57793 жыл бұрын
i have a c++ project of storing 500 books from a .txt file in which there are details about the author,ISBN ,title, etc. and I have to find a convenient data structure for that to do insertion, deletion,searching can you help me out plz?
@epicjr72603 жыл бұрын
For the private member variable list hashTable, this is just a containter that is in an index of the array right? If so, are we able to use a vector or a linked list instead?
@CodingJesus
3 жыл бұрын
We want to have a set number of groupings, hence we want a container that cannot be resized. An array communicates that intent.
@sharinganuser15393 жыл бұрын
didn't understood why list::erase() can lead to segfault....even if last item is erased it will simply return container end ....how getting next itr position can lead to error?
@zombiehellmonkeygaming19563 жыл бұрын
Thanks so much for this, it helped a lot!
@CodingJesus
3 жыл бұрын
Glad it helped! Please consider subscribing for more help :D
@miclaymon3 жыл бұрын
thanks for helping me write my first working hash function. test on this tomorrow in 12 hours...
@CodingJesus
3 жыл бұрын
Best of luck!
@maishananjeeba7436 Жыл бұрын
is this code also considers the collison problem?
@makoricodes32622 жыл бұрын
this guy is doing god's work
@ElemenTalParkour2 жыл бұрын
Great video, thanks!! You would not have to go over all the table to check if is empty, if you found one element - return false.
@chuyinghe79533 жыл бұрын
great tutorial! I encountered a problem for using the function emplace_back(), IDE says it "no member named 'emplace_back' in 'std::__1::list
@jarreed0
3 жыл бұрын
May need to tell your compiler to use c++11
@ayaz.unstoppable3 жыл бұрын
Thank u this question was asked in sprinklr interview
@alphabeta30143 жыл бұрын
amazing lecture man. crystal clear.
@CodingJesus
3 жыл бұрын
Thanks, please consider subscribing for more.
@khaledelgharbi52003 жыл бұрын
Great tutorial, this will help me for my interview
@khaledelgharbi5200
3 жыл бұрын
One question: can we use this hash class in std::unordered_set ?
@halily.26263 жыл бұрын
thanks a lot. But I think using C sytle array is bad practice. The books always say use vector: I mean instead of this: list table[hashGroups]; isn't this better ? : using listType = list; vector table; Maybe, I am wrong, what do you think ?
@grapesalt
3 жыл бұрын
std::vector will be slower than C style array's.
@prabhjotsingh31723 жыл бұрын
Did you not implement SearchTable function?
@panicineurope3 жыл бұрын
Thanks guy! Very nice tutorial. Here's my go at the search function: string HashTable::searchTable(int key) { int hashValue = hashFunction(key); auto& cell = table[hashValue]; auto bItr = begin(cell); bool keyExists = false; for (; bItr != end(cell); bItr++) { if (bItr->first == key) { keyExists = true; return bItr->second; } } if (!keyExists) return "Result Not Found"; }
@ilanogaming5034
2 жыл бұрын
Hi there, how do i search for the other same key? for example : HT.insertTable(99, "Jim"); HT.insertTable(99, "Tim"); how do i search for value "Tim"? cause if i search for key 99 it displays "Jim"
@erlisibraimi5267
2 жыл бұрын
@@ilanogaming5034 you can't have 2 different values with the same key, that's why your value gets overridden
@reverse21902 жыл бұрын
How do you implement an iterator class for this? anyone got ideas?
@santiagomickelleoliverague23372 жыл бұрын
what is iterator ? im almost at fourth cicle and still without recognise some words
@japde2694 Жыл бұрын
what keyboard are you using ?!??!?!
@user-vz6wb7bj1c3 жыл бұрын
in line 44 , dont you need to check if Bitr->first == hashFunction(key) instead of key?
@CodingJesus
3 жыл бұрын
bItr points to key-value pair. bItr->first points to the key. bItr->second points to the value. We are checking whether the key exists, so we need to use bItr->first
@nnewram99364 жыл бұрын
in isEmpty, you dont need a sum. Just return true whenever the size is non zero in the loop, it will on average save a lot of execution time
@CodingJesus
4 жыл бұрын
Yeah, others have brought it up below. That's a good approach.
@nnewram9936
4 жыл бұрын
@@CodingJesus oof, didn't catch that. Well, great video anyways! Thanks for it.
@CallBlofD2 жыл бұрын
great video man! you explained amazing!! (p.s. you forgot const on the print function)
@nagarjunvinukonda1623 жыл бұрын
Hi Jesus, Does Separate changing mean Open addressing? What is the point of checking HT isempty( )or not at start of int main? We are creating Ht from start so of course it will be empty before inserting....
@CodingJesus
3 жыл бұрын
Just checking whether IsEmpty is coded correctly. And yes, separate chaining and open addressing are different.
@flexo6664 жыл бұрын
great video! Thank you!
@killingjoyandmemeing
3 жыл бұрын
welcome
@ibrahimvelasquez3874 Жыл бұрын
What keyboard are you using? It sounds good!
@husein_alfil Жыл бұрын
Great Video !! Great Job :D
@vaibhavgupta80484 жыл бұрын
thanks for the video, but i think in worst case time complexity for searching the value be O(n) in your code which is violating the concept of hash table , if yes ,can it be improved for getting the value in constant time.
@nathansantos74217 ай бұрын
Muito obrigado Jesus Cristo dos códigos, você é o cara, a main.
@arvinbrian71072 жыл бұрын
can anyone tell me which IDE is this?
@yazou13072 жыл бұрын
great video!
@highxavito4875 Жыл бұрын
hola buenas tu video me sirvio mucho, pero me gustaria saber como implementar un sistema de busqueda atravez de la key
@carlosniederauer18743 жыл бұрын
Great tutorial!
@killingjoyandmemeing
3 жыл бұрын
thx
@unknownsahb16703 жыл бұрын
display function?? i didnt see it
@mryup61004 жыл бұрын
I have the same setup as you! VS code with ubuntu subsytem terminal
@MeriemStudentDjidjeli Жыл бұрын
awesome video
@processorbot87614 жыл бұрын
this is a great video
@CodingJesus
4 жыл бұрын
Thank you! Make sure to check out my other videos.
@jasmeetsingh74994 жыл бұрын
isEmpty can be implemented in a better way (O(1) as opposed to O(hashGroups)), You could create a variable that stores number of empty hashGroups. So, numEmptyHashGroups = hashGroups initially. On insert, decrement numEmptyHashGroups if it is the first node in the list. Similarly when removing the item, increment numEmptyHashGroups if it is the last value. Implementation of isEmpty will become as simple as numEmptyHashGroups == hashGrorups. Also, in current implementation you don't need to calculate the sum, you could just return false if at any point the list is not empty. Aggregating the sum can cause overflow.
@CodingJesus
4 жыл бұрын
You can keep count of the amount of items successfully added and removed. Call isEmpty() will check whether itemCount is 0 or not.
@sharuns9173 жыл бұрын
Nice n quick...thanks
@divyanshr13 жыл бұрын
Thanks man, I have searched google, youtube, your video is the only source of hashmap implementation in c++. But one thing is that as we are using for loops in this code, it doesnot mean O(1) operations, right?
@getsuha
3 жыл бұрын
for loop gets used when there is collision and the worst case time complexity for collision is actually O(n), i.e. when all the values have collided. It would be O(logn) if implemented with an AVL tree.
@Bristol-MyersSquibb3 жыл бұрын
Hey u ever get a gpu?
@marflage4 жыл бұрын
Just what I was looking for. Amazing explanation. However, I can see that some beginners can get confused because of list, iterators and i{}. Nonetheless, it was a great video. PS: That keypresses and mouse clicks were hypnotic.
@CodingJesus
4 жыл бұрын
I was actually afraid that people would not like the typing sound and it would annoy them. But people seem to love it. I have another video coming out on Wednesday at 5:30 CST with more typing sounds. :D
@austintaylor5372
4 жыл бұрын
Yeah could you explain the i{} and how he did the iterator. I'm also trying to learn c++ i only code in c#
@CodingJesus
4 жыл бұрын
@@austintaylor5372 int x declares x but doesn't initialise it. By that I mean that 'x' has junk in it, and by junk I mean it can have anything in it. int x{} default-initialises x to int's default value, that being 0. Iterators are like pointers in a sense, except they are used on collections and there are several types of them. They allow you to iterate over a collection and, in some cases (non-const iterators), modify the contents of that collection. Hope this helped.
@austintaylor5372
4 жыл бұрын
@@CodingJesus yeah that makes alot of sense thank you :)
@user-qh9xl9ry7d9 ай бұрын
Umm... How do you overcome Hash Collision? I can't find it. How to overcome Hash Collision in this code
@user-wz5rk7eq2i
2 ай бұрын
Just using a list. Cell.emplace_back(key, value)
@brendankacic60663 жыл бұрын
Thanks so much!!
@mockingbird38093 жыл бұрын
For remove function, Doesn't this work? value_at_index.remove_if([&](std::pair capture) -> bool { if(capture.first == key){return true;} else{return false;} });
@CodingJesus
3 жыл бұрын
Why don't you try it out and test for yourself? That's the essence of learning :)
@hezhu48514 жыл бұрын
hi, could I know if you miss writing the search function
@CodingJesus
4 жыл бұрын
Yes, I left it as homework for you in particular. But only for you, not for anyone else.
@hezhu4851
4 жыл бұрын
@@CodingJesus And one more thing is here we use separate chaining method. But when we insert, if there's a conflict. You just erase the original value but not adding the value into next node of list. So maybe it is wrong here?
@gourav.barkle4 жыл бұрын
can anyone please tell me what is that sum followed by { }.
@CodingJesus
4 жыл бұрын
Brace initialization. It sets sum to 0. Please consider subscribing for more content!
@srihari56053 жыл бұрын
should have added a key-value pair that gets the same hash! excellent work though!
@HoserzzzАй бұрын
is the video completely corrupted for anyone else?
@banabana46914 жыл бұрын
Awesome.
@rohitk26294 жыл бұрын
The keyboard sounds like asmr. relaxing..
@quickyfast-sz9xc4 ай бұрын
bruh I copy line by line and it doesn't run at all.... tells me there's a lot of errors... I don't understand why it doesn't work..
@pranavnyavanandi97102 жыл бұрын
Man, can you make videos like this for java...?
@naufalmuhadzdzib73383 жыл бұрын
Big thanks :))
@aryanparekh93143 жыл бұрын
I really love this. One thing I am not able to understand is why the code will not work if you don't put a "&" operator in front of cell = hashFunction(key). Can anybody explain it to me?
@CodingJesus
3 жыл бұрын
What do you mean? Paste the code into Godbolt and share the generated link with me
@aryanparekh9314
3 жыл бұрын
@@CodingJesus I can't believe you replied!! I didn't know the concept of references in c++ so I didn't understand why you used a & operator in front of a variable. Well I understood it now but I do have a few doubts. Is this method faster than using a plain vectors? What is the best scenario in which I should use this?
@CodingJesus
3 жыл бұрын
@@aryanparekh9314 I still don't know what part of the video you're talking about.
@aryanparekh9314
3 жыл бұрын
@@CodingJesus Okay I'm sorry for being unclear, here is the time stamp 6:52 line:40 When you used cell as a reference
@CodingJesus
3 жыл бұрын
@@aryanparekh9314 You should use references when you want to change the value stored in the hash-table. Not aliasing the hash-table element with a reference will lead to you crating a copy of it. When you go to assign cell = something, it won't be stored in the hashtable, because 'cell' isn't a reference.
@mrkunalgoswami20102 жыл бұрын
can someone code it in c++ ?
@samiulislamsharan2 жыл бұрын
how can I implement the searchTable function?
@jamespolaroid4856
2 жыл бұрын
I gave it a try, seems to work, if its the best piece of code - i dont think so. string HashTable::searchTable(int key){ int hashValue = hashFunction(key); auto& cell = table[hashValue]; auto bItr = begin(cell); bool keyExists = false; string searchValue; for (; bItr != end(cell); bItr++) { if (bItr->first == key) { keyExists = true; searchValue = bItr->second; cout
@haiderpall49072 жыл бұрын
plz attach the source file for helping out
@grayscale-bitmask2 жыл бұрын
Great video! Especially in covering effective collision handling, since not all tutorials do that very well. FWIW, 1:25 should be "what it looks like" or just "how it looks". "Like" sounds a bit redundant if you pair it with "How". One of the best tutorials on this topic in any case.
@pranavbelgaonkar86343 жыл бұрын
Hi , I learned a lot from this video but i did not understand why you defined variable and then placed a curly bracket after it. Why not just leave it blank. thanks!
@CodingJesus
3 жыл бұрын
Google the difference between defining a variable and initializing it.
@Anubis101104 жыл бұрын
Amazing
@killingjoyandmemeing
3 жыл бұрын
ikr
@sigterm9ki114 жыл бұрын
no string searchTable(int key) function?
@CodingJesus
4 жыл бұрын
Nope, that's homework for you. ;)
@sigterm9ki11
4 жыл бұрын
@@CodingJesus lol, You sound like me. I just noticed the difference in signatures. Great work and discussion.
@CodingJesus
4 жыл бұрын
@@sigterm9ki11 Subscribe if you want to see more. What would you be interested in? Concurrent queue?
@garrettbellinghausen83892 жыл бұрын
Did he forget to write the code for the search function?
@kantocoder50463 жыл бұрын
Why are you using {} instead of = in the variables initialization? To make your code harder to comprehend?
3 жыл бұрын
better convention for OOP , it's recommended to use it this way by the standard because it reduce time complexity by avoiding useless operation
@kantocoder5046
3 жыл бұрын
@ >> recommended to use it this way by the standard >because it reduce time complexity by avoiding useless operation
@brainyfool4846
3 жыл бұрын
@ please please tell more or put a link when to use variable{} for initialization or @Coding Jesus please explain.
4 жыл бұрын
Very good explanation!! what IDE is that?
@CodingJesus
4 жыл бұрын
Visual Studio Code
4 жыл бұрын
@@CodingJesus thanks
@killingjoyandmemeing
3 жыл бұрын
@ welcome
@zackjohnson93872 жыл бұрын
I don't understand the purpose of the for loop for the insert function if you're just replacing the value. Why would you need to iterate the cell if you just look at the first value of cell to see if it's the key and if it is replace the second value with the value. Seems unnecessary to me.
@zackjohnson9387
2 жыл бұрын
Same with the remove function* Unless you are using chaining what is the point of the for loop?
@nbavideos44873 жыл бұрын
amazing explanation thanks a lot but tell me why use & in auto& cell = table [hashvalue]; to give you the address of each hash value or what explain with my all respect
@CodingJesus
3 жыл бұрын
We take a reference to that have because we want to alter it, as opposed to altering a copy of it. Hastable[hashKey] returns a reference to the item being held at that index.
@SuperWhatusername2 жыл бұрын
Thank you @Coding Jesus
@babaa57013 жыл бұрын
nice, video. Wish I had contrast, so I can see () {} [] better.
@alexchen68472 жыл бұрын
What's that IDE he's using? P.S. Kinda new to C++
@jamespolaroid4856
2 жыл бұрын
thats visual studio code (VSC)
@alexvallex5487
Жыл бұрын
@@jamespolaroid4856 do you know why my VSC does not like pointers? everytime i use -> it breaks
@jamespolaroid4856
Жыл бұрын
@@alexvallex5487 maybe wrong dash, maybe wrong 'bigger then'-sign - u can use (*variablenameBeforeArrow).variableAfterArrow instead, its just a different representation of the same concept
Пікірлер: 175
Man! You are just amazing! I have coding interviews in a few days, and you just saved my ass. You have implemented almost all DS, and they are so neat and clean, the way it should be! Thanks man!
@noemanakram6581
2 жыл бұрын
what did u do
@Snake-ez1kl
Жыл бұрын
@@noemanakram6581 he is the ceo of google now
@mohammedhayyoun
5 ай бұрын
@@Snake-ez1kl LMAO
This was incredibly helpful. You explain each step clearly which is hard to find! Thank you:)
super amazing work man, props! you're a great programmer and teacher.
Very useful and clear video, thank you for helping me understand hash tables better.
@CodingJesus
4 жыл бұрын
No problemo
love the perfection. the way you type and your explanation
@killingjoyandmemeing
3 жыл бұрын
thanks
Thank you!! This was so helpful. Supplementing my classes with your videos now - my teacher only reads from the book.
Question: Do you actually need the keyExists bool? Couldn't you just return in the for loop if the key exists after replacing it?
Why do you put return at the end of functions that have void as their return value?
That was a neat explanantion! thanks a lot, man!
@killingjoyandmemeing
3 жыл бұрын
welcome
Since perfect hashing function is assumed, why use the for loops. Doesn't that make the time complexity greater than O(1)?
This is actually ASMR lol
Very helpful! I do have one question tho: you are saying in the beginning, that this would be hashing with seperate chaining. But wouldnt you append the value to the list of the other ones of the same hash value instead of replacing them in seperate chaining? Line 46 in your code. Or am i missing something there?
how would I change this if I wanted each key to hold all of the different names instead of replacing the value
Thank you, this was quite helpful, and quite catchy too XD. Keep up the good work, and all the very best
@CodingJesus
3 жыл бұрын
Thanks
@killingjoyandmemeing
3 жыл бұрын
@@CodingJesus welcome
i have a c++ project of storing 500 books from a .txt file in which there are details about the author,ISBN ,title, etc. and I have to find a convenient data structure for that to do insertion, deletion,searching can you help me out plz?
For the private member variable list hashTable, this is just a containter that is in an index of the array right? If so, are we able to use a vector or a linked list instead?
@CodingJesus
3 жыл бұрын
We want to have a set number of groupings, hence we want a container that cannot be resized. An array communicates that intent.
didn't understood why list::erase() can lead to segfault....even if last item is erased it will simply return container end ....how getting next itr position can lead to error?
Thanks so much for this, it helped a lot!
@CodingJesus
3 жыл бұрын
Glad it helped! Please consider subscribing for more help :D
thanks for helping me write my first working hash function. test on this tomorrow in 12 hours...
@CodingJesus
3 жыл бұрын
Best of luck!
is this code also considers the collison problem?
this guy is doing god's work
Great video, thanks!! You would not have to go over all the table to check if is empty, if you found one element - return false.
great tutorial! I encountered a problem for using the function emplace_back(), IDE says it "no member named 'emplace_back' in 'std::__1::list
@jarreed0
3 жыл бұрын
May need to tell your compiler to use c++11
Thank u this question was asked in sprinklr interview
amazing lecture man. crystal clear.
@CodingJesus
3 жыл бұрын
Thanks, please consider subscribing for more.
Great tutorial, this will help me for my interview
@khaledelgharbi5200
3 жыл бұрын
One question: can we use this hash class in std::unordered_set ?
thanks a lot. But I think using C sytle array is bad practice. The books always say use vector: I mean instead of this: list table[hashGroups]; isn't this better ? : using listType = list; vector table; Maybe, I am wrong, what do you think ?
@grapesalt
3 жыл бұрын
std::vector will be slower than C style array's.
Did you not implement SearchTable function?
Thanks guy! Very nice tutorial. Here's my go at the search function: string HashTable::searchTable(int key) { int hashValue = hashFunction(key); auto& cell = table[hashValue]; auto bItr = begin(cell); bool keyExists = false; for (; bItr != end(cell); bItr++) { if (bItr->first == key) { keyExists = true; return bItr->second; } } if (!keyExists) return "Result Not Found"; }
@ilanogaming5034
2 жыл бұрын
Hi there, how do i search for the other same key? for example : HT.insertTable(99, "Jim"); HT.insertTable(99, "Tim"); how do i search for value "Tim"? cause if i search for key 99 it displays "Jim"
@erlisibraimi5267
2 жыл бұрын
@@ilanogaming5034 you can't have 2 different values with the same key, that's why your value gets overridden
How do you implement an iterator class for this? anyone got ideas?
what is iterator ? im almost at fourth cicle and still without recognise some words
what keyboard are you using ?!??!?!
in line 44 , dont you need to check if Bitr->first == hashFunction(key) instead of key?
@CodingJesus
3 жыл бұрын
bItr points to key-value pair. bItr->first points to the key. bItr->second points to the value. We are checking whether the key exists, so we need to use bItr->first
in isEmpty, you dont need a sum. Just return true whenever the size is non zero in the loop, it will on average save a lot of execution time
@CodingJesus
4 жыл бұрын
Yeah, others have brought it up below. That's a good approach.
@nnewram9936
4 жыл бұрын
@@CodingJesus oof, didn't catch that. Well, great video anyways! Thanks for it.
great video man! you explained amazing!! (p.s. you forgot const on the print function)
Hi Jesus, Does Separate changing mean Open addressing? What is the point of checking HT isempty( )or not at start of int main? We are creating Ht from start so of course it will be empty before inserting....
@CodingJesus
3 жыл бұрын
Just checking whether IsEmpty is coded correctly. And yes, separate chaining and open addressing are different.
great video! Thank you!
@killingjoyandmemeing
3 жыл бұрын
welcome
What keyboard are you using? It sounds good!
Great Video !! Great Job :D
thanks for the video, but i think in worst case time complexity for searching the value be O(n) in your code which is violating the concept of hash table , if yes ,can it be improved for getting the value in constant time.
Muito obrigado Jesus Cristo dos códigos, você é o cara, a main.
can anyone tell me which IDE is this?
great video!
hola buenas tu video me sirvio mucho, pero me gustaria saber como implementar un sistema de busqueda atravez de la key
Great tutorial!
@killingjoyandmemeing
3 жыл бұрын
thx
display function?? i didnt see it
I have the same setup as you! VS code with ubuntu subsytem terminal
awesome video
this is a great video
@CodingJesus
4 жыл бұрын
Thank you! Make sure to check out my other videos.
isEmpty can be implemented in a better way (O(1) as opposed to O(hashGroups)), You could create a variable that stores number of empty hashGroups. So, numEmptyHashGroups = hashGroups initially. On insert, decrement numEmptyHashGroups if it is the first node in the list. Similarly when removing the item, increment numEmptyHashGroups if it is the last value. Implementation of isEmpty will become as simple as numEmptyHashGroups == hashGrorups. Also, in current implementation you don't need to calculate the sum, you could just return false if at any point the list is not empty. Aggregating the sum can cause overflow.
@CodingJesus
4 жыл бұрын
You can keep count of the amount of items successfully added and removed. Call isEmpty() will check whether itemCount is 0 or not.
Nice n quick...thanks
Thanks man, I have searched google, youtube, your video is the only source of hashmap implementation in c++. But one thing is that as we are using for loops in this code, it doesnot mean O(1) operations, right?
@getsuha
3 жыл бұрын
for loop gets used when there is collision and the worst case time complexity for collision is actually O(n), i.e. when all the values have collided. It would be O(logn) if implemented with an AVL tree.
Hey u ever get a gpu?
Just what I was looking for. Amazing explanation. However, I can see that some beginners can get confused because of list, iterators and i{}. Nonetheless, it was a great video. PS: That keypresses and mouse clicks were hypnotic.
@CodingJesus
4 жыл бұрын
I was actually afraid that people would not like the typing sound and it would annoy them. But people seem to love it. I have another video coming out on Wednesday at 5:30 CST with more typing sounds. :D
@austintaylor5372
4 жыл бұрын
Yeah could you explain the i{} and how he did the iterator. I'm also trying to learn c++ i only code in c#
@CodingJesus
4 жыл бұрын
@@austintaylor5372 int x declares x but doesn't initialise it. By that I mean that 'x' has junk in it, and by junk I mean it can have anything in it. int x{} default-initialises x to int's default value, that being 0. Iterators are like pointers in a sense, except they are used on collections and there are several types of them. They allow you to iterate over a collection and, in some cases (non-const iterators), modify the contents of that collection. Hope this helped.
@austintaylor5372
4 жыл бұрын
@@CodingJesus yeah that makes alot of sense thank you :)
Umm... How do you overcome Hash Collision? I can't find it. How to overcome Hash Collision in this code
@user-wz5rk7eq2i
2 ай бұрын
Just using a list. Cell.emplace_back(key, value)
Thanks so much!!
For remove function, Doesn't this work? value_at_index.remove_if([&](std::pair capture) -> bool { if(capture.first == key){return true;} else{return false;} });
@CodingJesus
3 жыл бұрын
Why don't you try it out and test for yourself? That's the essence of learning :)
hi, could I know if you miss writing the search function
@CodingJesus
4 жыл бұрын
Yes, I left it as homework for you in particular. But only for you, not for anyone else.
@hezhu4851
4 жыл бұрын
@@CodingJesus And one more thing is here we use separate chaining method. But when we insert, if there's a conflict. You just erase the original value but not adding the value into next node of list. So maybe it is wrong here?
can anyone please tell me what is that sum followed by { }.
@CodingJesus
4 жыл бұрын
Brace initialization. It sets sum to 0. Please consider subscribing for more content!
should have added a key-value pair that gets the same hash! excellent work though!
is the video completely corrupted for anyone else?
Awesome.
The keyboard sounds like asmr. relaxing..
bruh I copy line by line and it doesn't run at all.... tells me there's a lot of errors... I don't understand why it doesn't work..
Man, can you make videos like this for java...?
Big thanks :))
I really love this. One thing I am not able to understand is why the code will not work if you don't put a "&" operator in front of cell = hashFunction(key). Can anybody explain it to me?
@CodingJesus
3 жыл бұрын
What do you mean? Paste the code into Godbolt and share the generated link with me
@aryanparekh9314
3 жыл бұрын
@@CodingJesus I can't believe you replied!! I didn't know the concept of references in c++ so I didn't understand why you used a & operator in front of a variable. Well I understood it now but I do have a few doubts. Is this method faster than using a plain vectors? What is the best scenario in which I should use this?
@CodingJesus
3 жыл бұрын
@@aryanparekh9314 I still don't know what part of the video you're talking about.
@aryanparekh9314
3 жыл бұрын
@@CodingJesus Okay I'm sorry for being unclear, here is the time stamp 6:52 line:40 When you used cell as a reference
@CodingJesus
3 жыл бұрын
@@aryanparekh9314 You should use references when you want to change the value stored in the hash-table. Not aliasing the hash-table element with a reference will lead to you crating a copy of it. When you go to assign cell = something, it won't be stored in the hashtable, because 'cell' isn't a reference.
can someone code it in c++ ?
how can I implement the searchTable function?
@jamespolaroid4856
2 жыл бұрын
I gave it a try, seems to work, if its the best piece of code - i dont think so. string HashTable::searchTable(int key){ int hashValue = hashFunction(key); auto& cell = table[hashValue]; auto bItr = begin(cell); bool keyExists = false; string searchValue; for (; bItr != end(cell); bItr++) { if (bItr->first == key) { keyExists = true; searchValue = bItr->second; cout
plz attach the source file for helping out
Great video! Especially in covering effective collision handling, since not all tutorials do that very well. FWIW, 1:25 should be "what it looks like" or just "how it looks". "Like" sounds a bit redundant if you pair it with "How". One of the best tutorials on this topic in any case.
Hi , I learned a lot from this video but i did not understand why you defined variable and then placed a curly bracket after it. Why not just leave it blank. thanks!
@CodingJesus
3 жыл бұрын
Google the difference between defining a variable and initializing it.
Amazing
@killingjoyandmemeing
3 жыл бұрын
ikr
no string searchTable(int key) function?
@CodingJesus
4 жыл бұрын
Nope, that's homework for you. ;)
@sigterm9ki11
4 жыл бұрын
@@CodingJesus lol, You sound like me. I just noticed the difference in signatures. Great work and discussion.
@CodingJesus
4 жыл бұрын
@@sigterm9ki11 Subscribe if you want to see more. What would you be interested in? Concurrent queue?
Did he forget to write the code for the search function?
Why are you using {} instead of = in the variables initialization? To make your code harder to comprehend?
3 жыл бұрын
better convention for OOP , it's recommended to use it this way by the standard because it reduce time complexity by avoiding useless operation
@kantocoder5046
3 жыл бұрын
@ >> recommended to use it this way by the standard >because it reduce time complexity by avoiding useless operation
@brainyfool4846
3 жыл бұрын
@ please please tell more or put a link when to use variable{} for initialization or @Coding Jesus please explain.
Very good explanation!! what IDE is that?
@CodingJesus
4 жыл бұрын
Visual Studio Code
4 жыл бұрын
@@CodingJesus thanks
@killingjoyandmemeing
3 жыл бұрын
@ welcome
I don't understand the purpose of the for loop for the insert function if you're just replacing the value. Why would you need to iterate the cell if you just look at the first value of cell to see if it's the key and if it is replace the second value with the value. Seems unnecessary to me.
@zackjohnson9387
2 жыл бұрын
Same with the remove function* Unless you are using chaining what is the point of the for loop?
amazing explanation thanks a lot but tell me why use & in auto& cell = table [hashvalue]; to give you the address of each hash value or what explain with my all respect
@CodingJesus
3 жыл бұрын
We take a reference to that have because we want to alter it, as opposed to altering a copy of it. Hastable[hashKey] returns a reference to the item being held at that index.
Thank you @Coding Jesus
nice, video. Wish I had contrast, so I can see () {} [] better.
What's that IDE he's using? P.S. Kinda new to C++
@jamespolaroid4856
2 жыл бұрын
thats visual studio code (VSC)
@alexvallex5487
Жыл бұрын
@@jamespolaroid4856 do you know why my VSC does not like pointers? everytime i use -> it breaks
@jamespolaroid4856
Жыл бұрын
@@alexvallex5487 maybe wrong dash, maybe wrong 'bigger then'-sign - u can use (*variablenameBeforeArrow).variableAfterArrow instead, its just a different representation of the same concept
@alexvallex5487
Жыл бұрын
@@jamespolaroid4856 thank youu
coding jesus man that name does suit you well
hello sir, in line 86 the second operand (
@felipesilva-mr5om
4 жыл бұрын
csrc.nist.gov/csrc/media/publications/fips/180/3/archive/2008-10-31/documents/fips180-3_final.pdf
@aimilios4794
3 жыл бұрын
use #include instead of #include
where is the search function?
@CodingJesus
3 жыл бұрын
It's homework. If you subscribe I may consider making a data structure with ONLY search ability, nothing else. Not even insert.
Can we get the source code?
@CodingJesus
4 жыл бұрын
No. The point is to watch and learn, not watch and copy-and-paste.
Thank you Jesus
Lmao this guy is called Coding Jesus
Amen
Should've zoomed in the screen a little bit......
So no one is going to talk bout that double intro?
@CodingJesus
4 жыл бұрын
Haahaha, I'll crop the intro out. I mentioned in the description to start at 0:16
@satyagyaparashar2575
4 жыл бұрын
Good content tho..keep it up bro.
rip Rick
@sp1xa
3 жыл бұрын
rip Bob
Is that your real name?
@CodingJesus
3 жыл бұрын
Yes, my first name is Coding and my last name is Jesus
now next tutorial CPP CON 17: kzread.info/dash/bejne/oJd8z6eOna3Alpc.html
You Didn't Implemented the SearchTable method😄
Not see clearly plz zoom the screen
Your teaching is amazing, but the Tabla that you are playing while typing is somewhat irritating.
yadi yadi yada....
you like pressing buttons dont you
He is Jesus