I explored and created persistent data structures and functional tools to operate over them

PROJECT NAME: Zimple


persistent data structures for Zig

I’ve been exploring/making persistent data structures for Zig (Vector, HAMT, HashSet).

The project uses arenas to avoid manual lifetime tracking. The whole tree is allocated into an arena and dropped when done.

There are also lazy iterators (map, filter, fold) using anytype callables to avoid virtual dispatch overhead.

Benchmarking and a writeup vs standard Zig and OCaml are included for comparing the memory density and allocation speed to measure the trade-offs.

Here is the repo: GitHub - bneb/zimple: Functional programming in Zig. No runtime. No GC. Just comptime and arenas. · GitHub

Supported Zig versions

what versions are supported? 0.16

2 Likes

What LLM wrote this?

I wrote it using an AI-augmented workflow.

I’m not sure if you are trying to say that this is slop, or genuinely curious about the setup. I’ll assume you are engaging in good faith, and so I’ll respond earnestly.

My setup uses a custom harness that controls cost by leveraging on device Gemma 4 when it can, Deepseek and Gemini flash and pro models depending on retry logic, task complexity, etc…

I break up the work into a design phase, where I tend to steer a lot more. Once I have a fairly tight design, I spin up coding agents to edit one file or function at a time, with success/exit criteria of good test coverage. Then I’ll go and fix or de-slop the code if necessary.

Nice, I’ve sometimes wanted a persistent data structure but didn’t have one on hand and didn’t want to spend time writing one.

One note though: in the section on Lifetime Management & Arenas it says nodes are dropped in O(1) time. I wouldn’t really characterize ArenaAllocator.deinit ad O(1). It is O(n) where n is the number of allocations.

ref:

https://ziglang.org/documentation/0.16.0/std/#std.heap.ArenaAllocator.deinit

Zig’s ArenaAllocator is an automation/organizational tool, not an optimization tool. Still a good use case for ArenaAllocator, but if you were looking for the HMH-style virtual memory arena trick–which I would describe as having an O(1) deinit–that’s not what ArenaAllocator provides.

2 Likes

I would suggest comparing your hamt hash implementation to zig’s builtin AutoHashMap as an oracle for correctness. Test the contents as sets, and make sure every single key and value is correct for all operations.

1 Like

A good idea that I shouldn’t have overlooked. I was also missing a benchmark there. This caught a collision bug in the remove path. Cheers.

Thanks. i am not all that familiar here, and your comment was helpful. I updated the docs accordingly.

1 Like