{"id":10780,"date":"2022-09-01T13:39:59","date_gmt":"2022-09-01T17:39:59","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=10780"},"modified":"2022-09-01T13:39:59","modified_gmt":"2022-09-01T17:39:59","slug":"chris-wellons-on-hashing","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=10780","title":{"rendered":"Chris Wellons on Hashing"},"content":{"rendered":"<p>The first data structure I learned and really internalized was the hash table. I\u2019ve been using them my entire career and, given when I started, that meant implementing them myself. This was before I learned C and even C doesn\u2019t have a built-in hash table so it\u2019s always been a matter of build it or do without.<\/p>\n<p>These days, it\u2019s hard to find a (newer) language that doesn\u2019t have a built-in hash table or dictionary data type. There\u2019s a downside to that, however. For many younger engineers, hash tables are mysterious entities that seem like magic. There are, in fact, many strategies for implementing a hash table each with their own tradeoff and which is best depends on the particular application. The problem with a built-in type is that it\u2019s one size fits all.<\/p>\n<p>Chris Wellons writes mostly in C so he has implemented scores of hash tables. He\u2019s settled on <a href=\"https:\/\/nullprogram.com\/blog\/2022\/08\/08\/\">his own implementation method<\/a> which is basically open addressing with double hashing. You can check his post for what exactly that means but it\u2019s one of the main implementation methods. I\u2019ve always preferred the chaining method, which is usually faster but takes more storage. Like Wellons, I\u2019ve done scores of implementations.<\/p>\n<p>Why do that? After all, most languages have a built-in type and even C probably has a library that implements hash tables. <a href=\"https:\/\/www.reddit.com\/r\/programming\/comments\/wk0497\/the_quick_and_practical_msi_hash_table\/\">Lots of people think there IS no point<\/a> but I disagree: if you know how things work, you know how to pick the best implementation strategy for your particular application.<\/p>\n<p>Take a look at Wellons\u2019 post for some of those details. Section 6.4 of Volume 3 of Knuth\u2019s <a href=\"https:\/\/en.wikipedia.org\/wiki\/The_Art_of_Computer_Programming\">AOCP<\/a> has all the details on the various methods and their tradeoffs. If you\u2019re serious about software engineering, it will repay your attention.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first data structure I learned and really internalized was the hash table. I\u2019ve been using them my entire career and, given when I started, that meant implementing them myself. This was before I learned C and even C doesn\u2019t &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=10780\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[37],"class_list":["post-10780","post","type-post","status-publish","format-standard","hentry","category-general","tag-tech"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10780"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10780\/revisions"}],"predecessor-version":[{"id":10781,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10780\/revisions\/10781"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}