Live data from Hacker News

The Universal Data Structure

elbenshira.com

11–20 of 108 posts

Re: The Universal Data Structure

#11
>"I hope you’re convinced. A hash is simple. A hash is fast. A hash is all you need."

Hash tables are cool but they are far from being the only thing you need.

The problem with this kind of subtle satire without a disclaimer at the end is that some people would fall by this and blindly follow it (collisions weren't mentioned not even once nor cache misses).

Re: The Universal Data Structure

#12
post #5

Like a well trained Pavlov dog[1], reading the title brought "Lua table"[2] to my mind, the most flexible data structure I have worked with, by far. [1] https://en.wikipedia.org/wiki/Classical_conditioning [2] http://www.lua.org/pil/2.5.html

> reading the title brought "Lua table"[2] to my mind, the most flexible data structure I have worked with, by far.

Which is not necessarily a good thing. PHP's array and JS's Object are essentially the same thing.

Re: The Universal Data Structure

#13
"Hashes are always O(1) reads, inserts and writes."

Maybe, once you've found a location to read, insert, or write to. The author neglects the runtime cost required for the hash algorithm itself, which may not be trivial; computing the hash of a string key is typically an O(n) operation.

Furthermore, unless a suitable table size is selected, integer keys (should one use a map like an array) will eventually hash to the same value, requiring even more time to iterate through all the remaining values that match that key until the desired value is found.

"I don’t know why you would ever use [a linked list] over an array (or a hash)..."

Here's why: because arrays take up space whether you use it or not. Linked lists don't suffer from this problem, but at the cost of 1-2 pointers per item. Has the author seriously never managed memory before? Please tell me this article is a joke.

Re: The Universal Data Structure

#14
post #2

I wish they had used the word "map" in place of "hash" throughout this entire article. The use of hashes is an implementation detail and wholly irrelevant.

> The use of hashes is an implementation detail and wholly irrelevant.

Not in this case. An ordered map implemented as a tree has the same interface but with very different operation complexities

Re: The Universal Data Structure

#15

>"I hope you’re convinced. A hash is simple. A hash is fast. A hash is all you need." Hash tables are cool but they are far from being the only thing you need. The problem with this kind of subtle satire without a disclaimer at the end is that some people would fall by this and blindly follow it (collisions weren't mentioned not even once nor cache misses).

I don't think the satire was particularly subtle!

Re: The Universal Data Structure

#16
post #13

"Hashes are always O(1) reads, inserts and writes." Maybe, once you've found a location to read, insert, or write to. The author neglects the runtime cost required for the hash algorithm itself, which may not be trivial; computing the hash of a string key is typically an O(n) operation. Furthermore, unless a suitable table size is selected, integer keys (should one use a map like an array) will eventually hash to the…

[deleted]

Re: The Universal Data Structure

#17

>"I hope you’re convinced. A hash is simple. A hash is fast. A hash is all you need." Hash tables are cool but they are far from being the only thing you need. The problem with this kind of subtle satire without a disclaimer at the end is that some people would fall by this and blindly follow it (collisions weren't mentioned not even once nor cache misses).

I don't think the satire was particularly subtle!

Given the number of comments with "Please tell me this is a satire" in this thread, I would say it wasn't particularly explicit.

Re: The Universal Data Structure

#18
post #13

"Hashes are always O(1) reads, inserts and writes." Maybe, once you've found a location to read, insert, or write to. The author neglects the runtime cost required for the hash algorithm itself, which may not be trivial; computing the hash of a string key is typically an O(n) operation. Furthermore, unless a suitable table size is selected, integer keys (should one use a map like an array) will eventually hash to the…

It's even tagged "bad-theory." I think it's pretty clearly a joke! A really good one!

Re: The Universal Data Structure

#19
post #13

"Hashes are always O(1) reads, inserts and writes." Maybe, once you've found a location to read, insert, or write to. The author neglects the runtime cost required for the hash algorithm itself, which may not be trivial; computing the hash of a string key is typically an O(n) operation. Furthermore, unless a suitable table size is selected, integer keys (should one use a map like an array) will eventually hash to the…

> Linked lists don't suffer from this problem, but at the cost of 1-2 pointers per item.

Another cost is the cache misses. If you are doing operations in a sequential fashion using an array would have a significant advantage if the number of elements is high. That's another tradeoff to take in consideration.

Post reply on HN