I've found that Zig is an excellent tool for implementing data-structure-oriented libraries. Comptime genericity is simple to understand and use, providing a C interface is very easy, and libraries take an allocator, so any memory-safety issues are the consumer's problem. If you want to use it from a memory-safe language, well, all of those have C FFIs so far as I know, Rust very much included, so you can.
A hypergraph is clearly a data structure which demands a lot of cyclic references, no getting around that, so I'm curious: can you compare and contrast the experience of implementing this in Rust vs. Zig?
Thanks for the feedback! Developing/prototyping is a very pleasant experience in Zig compared to Rust. It's obviously a different approach and some might find the tooling less mature but I quickly realized that the build system (as per 0.13.0) is very solid. You can build the docs, run the tests, etc. I'm a Neovim user and honestly the LSP (ZLS) is stable and you can additionally get the compilation errors (you need to create a check step in your build file). In tests, using with the testing allocator to catch memory leaks guides you while prototyping.
This is a well put description of my experience when implementing the same data structures in both Rust and Zig. it probably would not be a good idea, but sometimes I wish I had some kind of 'inline Zig' macro in Rust to pull out when doing that type of work
> A hypergraph is clearly a data structure which demands a lot of cyclic references...
Does it? The easiest data structure is a 2d array with rows corresponding to nodes and columns corresponding to edges. If nodes aren't allowed to touch an edge more than once, it's just a matrix of bools. No references needed!
Internally both the hyperedges and the vertices are stored as an AutoArrayHashmap with the associated data and the relations (
https://github.com/yamafaktory/hypergraphz/blob/9f87e705afd7...). Then the implementation diverge since a given hyperedge can hold zero to n vertices, with self-loops (ArrayList). For vertices, we just need to keep track of the hyperedges (AutoArrayHashmap).
samatman|1 year ago
I've found that Zig is an excellent tool for implementing data-structure-oriented libraries. Comptime genericity is simple to understand and use, providing a C interface is very easy, and libraries take an allocator, so any memory-safety issues are the consumer's problem. If you want to use it from a memory-safe language, well, all of those have C FFIs so far as I know, Rust very much included, so you can.
A hypergraph is clearly a data structure which demands a lot of cyclic references, no getting around that, so I'm curious: can you compare and contrast the experience of implementing this in Rust vs. Zig?
yamafaktory|1 year ago
n42|1 year ago
klyrs|1 year ago
Does it? The easiest data structure is a 2d array with rows corresponding to nodes and columns corresponding to edges. If nodes aren't allowed to touch an edge more than once, it's just a matrix of bools. No references needed!
unknown|1 year ago
[deleted]
reaanb2|1 year ago
yamafaktory|1 year ago
bigtuna711|1 year ago
redbell|1 year ago
yamafaktory|1 year ago
FjordWarden|1 year ago
yamafaktory|1 year ago