For a hash table, the general "promise" is that you map a very large space of keys (e.g. all strings) to a very small space of indexes using a simple function. Common sense might tell you that this shouldn't be possible ("how can you put something big into something small?") - and of course actual hash tables solve the conundrum by acknowledging collisions and defining ways to deal with them.
But by saying "let's assume no collisions" the reader is asked to just ignore the logical contradiction instead of solving it. That can lead to frustration in the best case or to serious misconceptions in the worst case.
Of course there is nothing wrong with saying "let's ignore those points for now, I'll explain later". Also I guess it depends very much on the learning style of the reader. But bad simplification can be very annoying for some learners.
He's just saying that the hash table is pretty useless if two random keys could access the same memory.
I think a lot of people that are in this thread went into this project with the complete wrong state of mind.
I'm not trying to teach people how a hash table or linked list implementation works. I'm not trying to make a library that is useful to anyone.
What I'm trying to do is connect the dots between a bunch of different important concepts in data structures.
People can go read things about each of these individual topics to great length and I encourage them too, but in general there are a lot of great computer science resources for just piecing a lot of related topics together for beginners.
Sure you can read a 600 page book that will cover things from end to end, but those are very intimidating when you have no prior knowledge of the topic and sometimes you don't get as much out of them if you don't know the basics.
If I can provide people with just a quick highlight reel of essential knowledge of data structures then I've done what I set out to do.
I hope Hacker News can appreciate that, I don't expect it to, but I can hope.
Also, there is no TOC to gloss over, the ascii, cute as it is, is harder to fly over than legit text with embedded code snippets.
But then again I don't know why you thought your opinion mattered if you didn't even read it. I guess that is the quality feedback I do expect from Hacker News commentors though.
self.i +=1
if self.i > len(self.a)/2:
self.a[:self.i] = []
self.i = 0
I didn't test the above code, and I am only 50% sure it is bug-free. I'm 99% sure the leaky version is bug-free. Memory leaks are not a bug if I document them, right? ;)But yes, periodically deleting the wasted space is still easier than trying to do the usual thing with circular buffers and stuff :)
Eh, for a certain definition of "algorithm". Plenty of signal processing algorithms, for instance, have nothing to do with data structures.
Algorithms + Data Structures = Programs
Second, I don't think the best place to go on lengthy explanations with figures included is in the comments of a source code file. Markdown is your friend.
I have 2 issues with this [..] I don't read stuff on data
structures to amuse myself. I want it to be as succint and
to the point as possible and not waste my time kidding
around.
Someone should write a serious data structures book for you. Oh wait, they have, there are literally hundreds of them.If you're attacking a topic with your full attention then you want maximum information as fast as possible.
If you're tired on a friday and want to learn something and have fun then information density doesn't matter anymore.
[ 1,2,3,undefined/null,undefined/null,undefined/null,undefined/null,undefined/null,4,5,6,undefined/null,undefined/null,undefined/null] - With the hashtables function, if you accidentally generate an index that is say 100,000, wouldn't you end up with an unwieldy-sized array that would be more difficult to search than one like this:
[{ value: 1, index: 103405}, { value: 2, index: 14550 }]
Or does JS store the arrays as an object internally and just stringify them with all the blanks?
Also, the part where it explains why memory is zero-addressed is so wrong, it rustled my jimmies.
That is why the word 'simplified' appears in the title, and the words 'super simplified' appear in the linked document. The purpose is to convey a point, and take away other distractions. Its probably not a good idea to introduce calculus to first graders either. If you don't think omitted content is a distraction, then it's probably not meant for you.