Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rad, I wasn't aware of khash, thanks! Any idea how it compares to Google's dense_hash_map?


No clue! Your comment history seems to say you're more qualified to answer that than me.

My first look says that dense_hash_map seems to use STL stuff and generics, khash is in pure C, and uses macro hacks to achieve the same functionality and only has a few key types it can use (str, int, int64).

Other than that, dense_hash_map and khash both use quadratic probing (https://en.wikipedia.org/wiki/Quadratic_probing) to resolve collisions. I couldn't really dig and find the hashing functions used by dense_hash_map but khash uses a weird one called X31 (search in https://download.samba.org/pub/unpacked/ntdb/lib/ccan/hash/h...) for the string ones and .... nothing??? for ints, with an alternative of Wang's integer hash function (https://gist.github.com/badboy/6267743). The world of hashing functions seem to be a crazy underworld of arcane incantations, old tomes, and copy pasting and emailing and trying random shit. It's really wonderful, reminds me of the olden days.

Khash.h is a measly 624 lines of code, everything included, so there's that.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: