[HN Gopher] Show HN: HypergraphZ - A Hypergraph Implementation i...
       ___________________________________________________________________
        
       Show HN: HypergraphZ - A Hypergraph Implementation in Zig
        
       Author : yamafaktory
       Score  : 47 points
       Date   : 2024-09-09 14:09 UTC (2 days ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | samatman wrote:
       | I see that this is a second implementation, the first being in
       | Rust: https://github.com/yamafaktory/hypergraph
       | 
       | 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 wrote:
         | 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.
        
         | n42 wrote:
         | 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
        
       | reaanb2 wrote:
       | How does this compare to a relational database, where hyperedges
       | are represented by tables and vertices by values?
        
         | yamafaktory wrote:
         | 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).
        
       | FjordWarden wrote:
       | Do you think this can be useful for a computational algebra
       | system?
        
         | yamafaktory wrote:
         | I'm honestly not sure if I can answer that question. There's
         | plenty of applications for hypergraphs (e.g. https://www.scienc
         | edirect.com/science/article/pii/S209580992...), so I'd say why
         | not?
        
           | emmanueloga_ wrote:
           | Are you implementing this to solve any particular
           | application?
        
       | bigtuna711 wrote:
       | Really cool! I would be interested in seeing a hypergraph
       | isomorphism algorithm implemented in Zig.
        
       ___________________________________________________________________
       (page generated 2024-09-11 23:00 UTC)