Live data from Hacker News

Hash tables with O(1) worst-case lookup and space efficiency [pdf]

ru.is

31–40 of 45 posts

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#31

I've had some luck turning a cuckoo hash into a sort of LRU cache. Whenever you do an insert, replace the older item. Iirc, everything else stayed the same. Using more than 2 hashed really helped.

I'd been wondering how best to make an LRU cache, and now you come along and give a really good solution. Nice!

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#32

I've had some luck turning a cuckoo hash into a sort of LRU cache. Whenever you do an insert, replace the older item. Iirc, everything else stayed the same. Using more than 2 hashed really helped.

This is really clever, thanks for the hack.

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#33
Every time I've tried comparing cuckoo hashing vs traditional hash algorithms in practice, the time taken to compute the additional hash functions outweighs any gains in performance.

Counter-intuitively, I've also noticed in many cases that using binary search over sorted elements in contiguous memory is actually faster than using a hash table at all.

Has anyone else found this?

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#34
post #20
post #18

Earlier quoted context omitted.

Chained hash tables have constant time insertion, but I'm not sure about the amortized lookup time (the worst case is linear)

You are kidding, right? The name chain itself suggest linear worst case behavior.

"insertion".

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#35
post #32

I've had some luck turning a cuckoo hash into a sort of LRU cache. Whenever you do an insert, replace the older item. Iirc, everything else stayed the same. Using more than 2 hashed really helped.

This is really clever, thanks for the hack.

That's not a hack. It's an algorithm.

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#36
post #20

Earlier quoted context omitted.

You are kidding, right? The name chain itself suggest linear worst case behavior.

"insertion".

My fault. Just saw constant time and chain in one sentence and panicked ;)

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#37
post #33

Every time I've tried comparing cuckoo hashing vs traditional hash algorithms in practice, the time taken to compute the additional hash functions outweighs any gains in performance. Counter-intuitively, I've also noticed in many cases that using binary search over sorted elements in contiguous memory is actually faster than using a hash table at all. Has anyone else found this?

I almost always prefer some kind of balanced tree to a hash table, because no matter the original specifications, sometime during the development of a program I usually need the elements in order.

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#38
post #31

I've had some luck turning a cuckoo hash into a sort of LRU cache. Whenever you do an insert, replace the older item. Iirc, everything else stayed the same. Using more than 2 hashed really helped.

I'd been wondering how best to make an LRU cache, and now you come along and give a really good solution. Nice!

That is not LRU, it's "replace with some other random thing some time, based on a hash function".

Re: Hash tables with O(1) worst-case lookup and space efficiency [pdf]

#40
post #35
post #32

Earlier quoted context omitted.

This is really clever, thanks for the hack.

That's not a hack. It's an algorithm.

Ooh so a hack is sort of an eigentransform of an algorithm in the sense that a hacked algorithm is still an algorithm.
Post reply on HN