Show HN: A hash array-mapped trie implementation in C
Just a note about your 'exported memory allocation' API:<p><pre><code>    struct hamt_allocator {
        void *(*malloc)(const size_t size);
        void *(*realloc)(void *chunk, const size_t size);
        void (*free)(void *chunk);
    };
</code></pre>
This whole thing could just be:<p><pre><code>    struct hamt_allocator {
        void *cookie;
        void*  (*realloc) (struct hamt_allocator* h, void* chk, const size_t size);
    };
</code></pre>
With the following constraints:<p>1. `realloc(H, nullptr, N)` -- allocated N bytes<p>2. `realloc(H, p, 0)` -- frees the pointer p<p>3. `realloc(H, p, N)` -- resizes the pointer p<p>And, the user has access to a 'context' (`cookie`) so they can use a (for instance) pool allocation scheme. Personally, I like a slightly different API:<p><pre><code>    struct hamt_allocator {
        void *cookie;
        void*  (*realloc) (struct hamt_allocator* h, void* chk, const size_t oldsize, const size_t newsize);
    };
</code></pre>
With the following constraints:<p>1. `realloc(H, nullptr, 0, N)` -- allocated N bytes<p>2. `realloc(H, p, N, 0)` -- frees the pointer p<p>3. `realloc(H, p, N, M)` -- resizes the pointer p<p>But I know a lot of people get confused and/or don't like having to pass (& thus keep) so much information to the allocator.