A graph library for Rust.

Related tags

Graphics gamma


A graph library for Rust.

Gamma provides primitives and traversals for working with graphs. It is based on ideas presented in A Minimal Graph API.


Add this to your Cargo.toml:

gamma = 0.9.0


ArrayGraph is a reference Graph implementation. Node, neighbor, and edge iteration order are stable and set by the try_from method.

use std::convert::TryFrom;
use gamma::graph::{ Graph, DefaultGraph, Error };

fn main() -> Result<(), Error> {
    let p3 = DefaultGraph::try_from(vec![
        vec![ 1 ],
        vec![ 0, 2 ],
        vec![ 1 ]

    assert_eq!(p3.is_empty(), false);
    assert_eq!(p3.order(), 3);
    assert_eq!(p3.size(), 2);
    assert_eq!(p3.ids().collect::<Vec<_>>(), [ 0, 1, 2 ]);
    assert_eq!(p3.neighbors(1)?.collect::<Vec<_>>(), [ 0, 2 ]);
    assert_eq!(p3.has_id(4), false);
    assert_eq!(p3.degree(0)?, 1);
    assert_eq!(p3.edges().collect::<Vec<_>>(), [
        (0, 1),
        (1, 2)
    assert_eq!(p3.has_edge(1, 2)?, true);

    let result = DefaultGraph::try_from(vec![
        vec![ 1 ]

    assert_eq!(result, Err(Error::UnknownId(1)));


Features include:


Gamma is not yet stable. Patch versions never introduce breaking changes, but minor/major versions probably will.


Gamma is distributed under the terms of the MIT License. See LICENSE-MIT and COPYRIGHT for details.

  • How to construct and return a HashGraph from a function?

    How to construct and return a HashGraph from a function?

    How do you do this when you do not hard code literals. For my crate blossom I generate random graphs like this:

        fn random_graph<'a>(size: usize, rng: &mut dyn RngCore) -> HashGraph<'a, usize, ()> {
            let nodes: Vec<_> = (0..size).collect();
            let mut edges = vec![];
            // Generate some random edges
            for i in 0..size {
                let mut j = i + 1;
                while j < size {
                    let interval = size + 1 - j;
                    let p = (rng.next_u64() as usize) % interval + j;
                    if p < size {
                        edges.push((nodes.index(i), nodes.index(p), ()));
                    j = p + 1;
            // error[E0505]: cannot move out of `nodes` because it is borrowed
            HashGraph::build(nodes, edges).unwrap()

    which gives the indicated error message. If you do not intend to return the graph, you can change the last line to

            let graph = HashGraph::build(nodes.clone(), edges).unwrap();

    However when you want to return graph you get

    error[E0515]: cannot return value referencing local variable `nodes`

    Using new(), add_node() and add_edge() I run into similar problems. An example of how to do this would be very welcome.

    opened by WiebeCnossen 5
  • graphcore vs. petgraph?

    graphcore vs. petgraph?

    It would be nice if you could explain any advantages you see of your crate over the long-standing petgraph crate. (Or, is it just your own attempt for the sake of learning?)

    opened by alexreg 5
  • What happened to the generics?

    What happened to the generics?

    I'm puzzled, because gamma 0.5 defined the Graph trait as generic over node and edge type. StableGraph had similar generic parameters. But now in 0.8, those are all gone, and nodes seem to be hardcoded as usize, even in the Graph trait as well as in DefaultGraph.

    I'm wondering what drove this change and what the recommended practice is to use gamma when the nodes are not usize?


    opened by U007D 4
  • Feat: New trait AppendableGraph

    Feat: New trait AppendableGraph

    This pull request creates a new trait for appendable graphs, aptly named AppendableGraph. The methods on AppendableGraph are for appending to graphs, and are mostly from DefaultGraph. I also refactored DefaultGraph to implement AppendableGraph. This trait is nice to have for the future where there is more than one editable graph representation -- the Graph API itself has no editing methods.

    A corollary to this trait would be DeletableGraph, but I've left that for a future PR.

    opened by skairunner 3
  • Subgraph monomorphism/isomorphism?

    Subgraph monomorphism/isomorphism?

    opened by j6k4m8 3
  • Graph API nodes() should be an iterator?

    Graph API nodes() should be an iterator?

    I am implementing a BTreeMap/Set-backed graph. I noticed that the nodes() method returns a slice of usize (&[usize]). This operation doesn't work very nicely for any graph that's not internally stored as a vector -- I imagine I would have to manually assemble a slice by iterating through the entire graph. I wonder if nodes() should instead return an iterator of usize to allow for flexibility in implementations.

    Existing code that uses nodes() as a slice can probably be trivially migrated by calling .collect() on the iterator.

    Edit: Okay, so it looks like I rediscovered the reason why nodes() & edges() might not be an iterator -- no painless way to return a generic Iterator from trait methods because Generic Associated Types isn't implemented yet. It still isn't very nice to return a slice from a usability perspective so I suppose I will poke around a bit and see if I can get some form of iterator working.

    opened by skairunner 2
Metamolecular, LLC
Metamolecular, LLC
Simple but powerful graph library for Rust

Graphlib Graphlib is a simple and powerful Rust graph library. This library attempts to provide a generic api for building, mutating and iterating ove

Purple Protocol 177 Nov 22, 2022
Rust library for of graph ensembles

Rust library for random graph ensembles Minimal Rust version: 1.55.0 Implements simple sampling and monte carlo (or rather markov-) steps, that can be

Yannick Feld 2 Dec 14, 2022
🦀 Rust Graph Routing runtime for Apollo Federation 🚀

Apollo Router The Apollo Router is a configurable, high-performance graph router for a federated graph. Getting started Follow the quickstart tutorial

Apollo GraphQL 502 Jan 8, 2023
Graph API client writen in Rust

graph-rs Now available on stable Rust at crates.io graph-rs-sdk = "0.1.0" 0.1.0 and above use stable Rust. Anything before 0.1.0 uses nightly Rust. M

Sean Reeise 56 Jan 3, 2023
A Graph implemented using nothing but `Vec`s in rust

VecGraph A Graph implemented using nothing but Vecs in rust. Details The graph is implemented using two Vecs: nodes and edges. nodes stores "nodes". w

null 1 Jan 27, 2022
GraphScope: A One-Stop Large-Scale Graph Computing System from Alibaba

A One-Stop Large-Scale Graph Computing System from Alibaba GraphScope is a unified distributed graph computing platform that provides a one-stop envir

Alibaba 2.2k Jan 1, 2023
A simple and elegant, pipewire graph editor

pw-viz A simple and elegant, pipewire graph editor This is still a WIP, node layouting is kinda jank at the moment. Installation A compiled binary is

null 180 Dec 27, 2022
A graph crate with simplicity in mind

A graph crate with simplicity in mind. Prepona aims to be simple to use (for users of the crate) and develop further (for contributors). Nearly every

Mohamad Amin Rayej 80 Dec 15, 2022
Simple, performant graph generator for Feynman diagrams* ⚛️

Feynman diagram generator ⚛️ A simple generator of "Feynman diagram" permutations (as defined by problem 781). Incrementally builds isomorphically uni

eugene huang 3 Jan 1, 2023
Theorem relational dependencies automatic extraction and visualization as a graph for Lean4.

Lean Graph Interactive visualization of dependencies for any theorem/definitions in your Lean project. How to use In your browser: lean-graph.com Or r

Patrik Číhal 8 Jan 3, 2024
The library provides basic functions to work with Graphviz dot lang from rust code.

Description The library provides the basic access to the graphs in graphviz format with ability to import into or export from it. Base examples: Parse

Boris 28 Dec 16, 2022
Generic framebuffer implementation in Rust for use with embedded-graphics library

Fraramebuffer implementation for Rust's Embedded-graphics Framebuffer approach helps to deal with display flickering when you update multiple parts of

Bernard Kobos 9 Nov 29, 2022
A 2D vector graphics library optimized for GUIs, written in Rust and wgpu

RootVG A 2D vector graphics library optimized for GUIs, written in Rust and wgpu How it Works Unlike other 2D vector graphics libraries which have a s

Meadowlark 14 Jul 10, 2024
An SVG rendering library.

resvg resvg is an SVG rendering library. Purpose resvg can be used as a Rust library, a C library and as a CLI application to render SVG files based o

Evgeniy Reizner 1.8k Jan 7, 2023
Library for Rubik's cube applications.

Rubik Master cube-demo3.mov Do you like to solve Rubik's cube? I do. As a cuber and programmer, I want to build a toolset to build applications like S

Akira Hayakawa 12 Nov 3, 2022
Sub-pixel precision light spot rendering library for astronomy and video tracking applications.

Planetarium Sub-pixel precision light spot rendering library for astronomy and video tracking applications. Example usage use planetarium::{Canvas, Sp

Sergey Kvachonok 5 Mar 27, 2022
Small, lightweight and fast library for rendering text with wgpu.

wgpu-text wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu. This project was inspired by and is similar to wgpu_glyph,

Leon 20 Nov 30, 2022
Python library for embedding large graphs in 2D space, using force-directed layouts.

Graph Force A python/rust library for embedding graphs in 2D space, using force-directed layouts. Installation pip install graph_force Usage The first

Niko Abeler 159 Dec 29, 2022
A toy ray tracer in Rust

tray_rust - A Toy Ray Tracer in Rust tray_rust is a toy physically based ray tracer built off of the techniques discussed in Physically Based Renderin

Will Usher 492 Dec 19, 2022