Zig-multi-index: generic multi-index container for Zig

Hi all,

I’ve been working on zig-multi-index, a small library that provides a zero-copy, compile-time multi-index container for Zig.

It lets you store a single collection of values and query it efficiently through multiple independent indexes (hash tables and/or AVL trees for now), all configured at comptime and kept automatically in sync.

Key points:

  • Type-safe, field-based indexing (.name, .age, etc.)

  • Index backends selected at compile time (AVL or hash table for now but more will come)

  • Zero-copy intrusive design: one copy of the data, shared across all indexes

  • O(1) lookups for unordered indexes, O(log n) + range queries for ordered ones

  • Atomic insert/update across all indexes (all-or-nothing)

Example:

var people = MultiIndex(Person, .{
    .name = .{ .unique = true, .ordered = false },
    .age = .{},
}).init(allocator);

if (people.find(.name, "Alice")) |p| {
    std.debug.print("{}\n", .{p.age});
}

The library is usable but still in beta. I’m mostly interested in feedback:
does this look useful, and is this something you’d consider using?

If there’s interest, I’ll keep developing it further (more backends, benchmarks, fuzzing, polish).

Thanks!

github: https://github.com/joachimgiron/zig-multi-index/

6 Likes

I think I would call it: generic multi-index container.
Describing it as compile-time made me think that the data structure is designed to be used at comptime, instead of being configured at comptime and then being usable at runtime.

I liked using multi-index data structures in the past, I will try it out when I have time.

3 Likes

Thanks for the feedback! I’ve updated the title, if you actually try it I would be happy to have your feedback!

2 Likes