‹ BackHN Continuity

Thread

Needed 1+1, built a functional programming language

151 points · 80 comments · birdculture

  1. ancientstraits · · focus · HN ↗
    The &quot;how to implement a hash table&quot; article <a href="https:&#x2F;&#x2F;benhoyt.com&#x2F;writings&#x2F;hash-table-in-c&#x2F;" rel="nofollow">https:&#x2F;&#x2F;benhoyt.com&#x2F;writings&#x2F;hash-table-in-c&#x2F; was really helpful for me. I thought that hash tables were something that were basically impossible to make in C, but this showed that it was simpler.
    1. dprkh · · focus · HN ↗
      Arrays are hash tables. You can implement a very simple hash table from a tutorial, but can you implement a sophisticated one? What about a concurrent hash table?
      1. fodkodrasz · · focus · HN ↗
        &gt; Arrays are hash tables.

        Maybe in JavaScript... but there is a topic called datastructures, where arrays are arrays, and hashtables are hastables. If people say this without a flip of an eye I&#x27;m not surprised why people write stuff like

        &gt; I thought that hash tables were something that were basically impossible to make in C

        1. moregrist · · focus · HN ↗
          In a trivial sense, arrays are hash tables with a hash function of the identity f(x)=x.

          It’s just not particularly common (or helpful) to view them that way.

          1. dprkh · · focus · HN ↗
            In LeetCode, it&#x27;s a very common optimization. If your key values are dense, you use an array. If your key values are sparse, you use a dict.
        2. pjmlp · · focus · HN ↗
          Besides the sibling comment, you can used closed hash tables algorithm (open addressing), which is fully based on a single array.

          <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Open_addressing" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Open_addressing

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.