Table of Contents

  1. Getting Started
  2. Features
    1. Dependency related features
  3. Examples
    1. Example #1: Basic Usage

Getting Started

Add this to your Cargo.toml:

[dependencies.rshyper]
features = [
    "hyper_map",
    "macros",
]
version = "0.1.x"

Features

The rshyper library provides several features to enhance and isolate its functionality:

  • hyper_map - A map-based hypergraph implementation.
  • macros - A set of macros to simplify hypergraph creation and manipulation.
  • rand - Parallel processing capabilities for efficient graph operations.
  • rayon - Parallel processing capabilities for efficient graph operations.
  • serde - Support for serialization and deserialization of hypergraphs.
  • wasm - WebAssembly support for running hypergraph operations in the browser.

Examples

For more detailed examples, please refer to the examples directory.

Example #1: Basic Usage

extern crate rshyper;

use rshyper::UnHyperMap;

fn main() -> rshyper::Result<()> {
    // initialize a new instance of a hypergraph
    let mut graph = UnHyperMap::<usize, usize>::undirected();
    // use the macro to insert nodes into the graph
    rshyper::hypergraph! {
        graph {
            nodes: {
                let v0;
                let v1 = 2;
                let v2 = 3;
                let v3 = 4;
            };
            edges: {
                let e0 = [v0, v1];
                let e1 = [v0, v2];
                let e2 = [v1, v2, v3];
            };
        }
    }
    // verify the order (no. of nodes) within the graph
    assert_eq!(graph.order(), 4);
    // verify the size (no. of edges) within the graph
    assert_eq!(graph.size(), 3);

    // Get neighbors of vertex v1
    let neighbors = graph.neighbors(&v1)?;
    println!("Neighbors of {}: {:?}", v1, neighbors);

    // Get degree of vertex v1
    let degree = graph.get_degree_of_node(&v1);
    println!("Degree of {v1}: {degree}");

    // Remove a vertex
    graph.remove_vertex(&v2)?;
    println!("Removed vertex {v2}");

    println!("---------\nFinal graph state: {:?}", graph);
    Ok(())
}