Shouldn't it be `i < storage[index].length` on line 46?
@BeauCarnes7 жыл бұрын
Yup! I fixed it in the code that is linked to in the description.
@__abshir4 жыл бұрын
line 45*
@funkybuddha15983 жыл бұрын
I wasted 2 hours because of that!
@NathanielBabalola2 жыл бұрын
On line 30, you're overwriting the previous value that was tied to that key. Is that how it's meant to be ?
@dcts75262 жыл бұрын
was looking for that comment. Since the hashfunction is deterministic, the same key will always result in the same index, hence the value must be by definition the same. Overriding it is unneccessary you are right!
@jhovahngibbs67206 жыл бұрын
tux is a penguin, that made me smile
7 жыл бұрын
hey, good video
@chavychaze93665 ай бұрын
awful explanation, awful. Why make such an easy topic so hard?
@fatemabohra42776 жыл бұрын
there is no such video except this which explains a simple hash function in javascript in a practical way.
@shayanjavadi7 жыл бұрын
Really weird mixture of var let and const here. Your storage can be a const since the array location in the memory doesn't change, only the array items do. all the functions should also be consts as well. there's really no point in using var anymore. great video otherwise!
@camillemorell32704 жыл бұрын
This is the best video I've watched on Hash Tables
@paschalynukwuani69302 жыл бұрын
Beau you are one of the best tutors on the internet.
@goodrowj5 жыл бұрын
I think I might be missing something here, wasn't the point of a hastable to have O(1) reads, inserts, and deletes? This is running O(n) blocks for each of those operations. Is there a way to get those down to O(1) in Javascript?
@ernwillburn5 жыл бұрын
Yeah this video is not really correct or O(1)
@dannytran46675 жыл бұрын
You get constant time by reducing the chance of collision. One simple way to do this is to double your storage size when the load factor gets high (the ratio of items to buckets). When you hit the load factor, double the number of buckets (in this case the storage Limit) and rehash all the items so hopefully they're in their own bucket.
@seyfullah7314 Жыл бұрын
Average time complexity of finding the hash value of any input is already O(n), However, how come the average time complexity of insertion be O(1) ?
@NathanielBabalola2 жыл бұрын
The buckets in the hashtable function is 4, but you're using 10 in the hash function ?
@bluemenkranz_29532 жыл бұрын
actually iam a beginner but when i reading the code for add function i got confused and i try to fix it with this code instead > this.add = function (key, value) { var index = hash(key, storageLimit); if (storage[index] === undefined) { storage[index] = [key, value]; } else { storage[index].push([key, value]); } }; still work tho
@bruhmoment37312 жыл бұрын
hello Genshin player.
@goodwish15437 жыл бұрын
Nice explanation. Good work, Beau Carnes ! Line 42, There is a use case in Remove method, that is the key doesn't exist in array. The code logic works. If we may test it separately, it'll be more clear.
@vishalheble7 жыл бұрын
Can you explain what do you mean by "When (inserted=== false), then push the key,vales into storage array. But how do we get multiple entries for the same bucket? It means collision right? But how can it happen when you don't find the same key which actually happens in previous case i.e. when the key exists already. Help me.
@sergeypomaraiko46617 жыл бұрын
at line 43 you have deleted array item, but length of array wasn't changed. So line 42 never will be true if we have inserted item once
@facundomartingarciaengel63183 жыл бұрын
U re the best bro ;) thanks from Argentina!
@OliverMensahDev7 жыл бұрын
Good work Sir
@JohnDoe-ji1zv5 жыл бұрын
Is hashtable actually used in a daily programming ? Could you give an example please
@kattenelvis17785 жыл бұрын
No it's only used in leetcode and interview questions.
@RedEyedJedi4 жыл бұрын
It is used anytime you want a fast insertion, look up or delete. The data structure you decide to use should always be based on how the data is going to be used. Don't just use an array for everything, although an array can be used for most things, speed is a major factor in developing software.
@dcts75262 жыл бұрын
Good question, would be interested to hear too. We all use hashtables indirectly by using hashmaps, sets or simply objects. But I've never applied a hashtable throughout my developer career so far too...
@sabuein Жыл бұрын
Thank you.
@greendsnow2 жыл бұрын
what?
@ChocolateMilkCultLeader4 жыл бұрын
So well done
@aaronargottelopez34883 жыл бұрын
Thanks
@anirvanchandra7 жыл бұрын
which text editor do you use
@rexromae177 жыл бұрын
that looks like CodePen
@FernandoFleuryGil7 жыл бұрын
it's a website called codepen
@sifatmoonjerin24794 жыл бұрын
Hey, great content! But I think using splice instead of delete will be a better solution. This throws an error if you remove a chained key and then try to reassign it.
@BrasilEmFatos3 жыл бұрын
hmm, but I think splice gonna remove the slot spaces in our storage, while delete keeps the space associated with that index but with an undefined value.