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!