Fixie tries
The Array Mapped Trie is an interesting data structure that&#x27;s really hard to represent in code. Even this rust version is forced to use unsafe and manual allocation to pull it off.<p>Most libraries seem to resort to using a dynamic array, like a Go slice:<p><pre><code>    type bitmapNode struct {
        childBitmap uint64
        children []node
        bitpos uint64
    }
</code></pre>
But that wastes space (there&#x27;s no need to store the length&#x2F;capacity) and may add a level of indirection, so doesn&#x27;t really represent the actual data structure at all.<p>The original paper includes this note: <a href="http:&#x2F;&#x2F;lampwww.epfl.ch&#x2F;papers&#x2F;idealhashtrees.pdf" rel="nofollow">http:&#x2F;&#x2F;lampwww.epfl.ch&#x2F;papers&#x2F;idealhashtrees.pdf</a><p>&gt; As Nilsson and Tikkanen [1998] remark, performance critically depends on the memory allocation system and careful organization is rewarded.<p>There are all kinds of clever workarounds to this problem, like using part of the pointer for additional meaning, or, perhaps the most fruitful, using different mechanisms for different sized nodes. For example: <a href="https:&#x2F;&#x2F;db.in.tum.de&#x2F;~leis&#x2F;papers&#x2F;ART.pdf" rel="nofollow">https:&#x2F;&#x2F;db.in.tum.de&#x2F;~leis&#x2F;papers&#x2F;ART.pdf</a> and  <a href="https:&#x2F;&#x2F;www.usenix.org&#x2F;system&#x2F;files&#x2F;conference&#x2F;fast17&#x2F;fast17-lee.pdf" rel="nofollow">https:&#x2F;&#x2F;www.usenix.org&#x2F;system&#x2F;files&#x2F;conference&#x2F;fast17&#x2F;fast17...</a><p>These adaptive radix trees have 4 node types: Node4, Node16, Node48, and Node256. Node4 uses two sorted arrays of up to 4 items, Node16 uses an idea similar to the array mapped trie, using a bitfield and compressed arrays, Node48 and Node256 are more like traditional tries, since at that size the memory loss is worth the trade off.<p>What&#x27;s frustrating about these data structures is just how hard they are to implement. Pointers, structural types, arrays and bytes seem wholly inadequate to the task and your code becomes a mishmash of low-level, specialized instructions, hacky unsafe memory access, and byzantine bit-shifting. This note in the code just about sums it up:<p><pre><code>    &#x2F;&#x2F; It should be possible to implement this for arbitrary types
    &#x2F;&#x2F; implementing BitAnd and friends, but my attempts to do so were
    &#x2F;&#x2F; constantly thwarted.
    macro_rules! trivial_fixed_length_key_impl {
        ($($name:ident,)*) =&gt; {
            $(#[allow(trivial_numeric_casts)] impl FixedLengthKey for $name {
                const LEVELS: usize = 2 * mem::size_of::&lt;Self&gt;();
                #[inline]
                fn nibble(&amp;self, idx: usize) -&gt; u8 {
                    ((*self &gt;&gt; (4*(Self::LEVELS-idx-1))) &amp; 15) as u8
                }
                #[inline]
                fn empty() -&gt; Self { 0 }
                #[inline]
                fn concat_nibble(&amp;mut self, nibble: u8) {
                    *self = (*self &lt;&lt; 4) | (nibble as Self)
                }
            })*
        }
    }
</code></pre>
It&#x27;s a circle-sized data-structure trying to fit in a square-sized programming worldview.<p>I wonder if we end up with hash tables, not because they&#x27;re technically superior, but because all of our programming languages make them easy to implement and reason about, and when try to leave that box, we constantly bang our head against a wall, and end up with code that always just looks like gobbledy gook.<p>The latter linked paper is particularly damning in this respect, as it introduces this esoteric world of persistent memory, which doesn&#x27;t even really exist yet, and yet will supposedly dominate computing for the next decade. Are we going to get new versions of programming languages to take advantage of this technology, or are we going to continue down the path of becoming wholly reliant on super-intelligent compilers to do paradigm translation?<p>Do we really want a world where only computers know how to program computers anymore?