Expand description
§rshyper
Welcome to the rshyper crate - a Rust package providing a comprehensive framework for
creating, manipulating, and analyzing hypergraphs using a myriad of mathematical and
algorithmic techniques. The crate is designed to be flexible and modular enabled via heavy
feature-gating throughout the framework.
§Background
Before diving in to the technical side of things, let’s start by defining several terms commonly used in the definition and implementation of hypergraphs.
§Terms
- edge: a hyperedge is a generalization of an edge in a graph, allowing it to connect any number of vertices.
- link: here, a link defines the layout of an edge providing a way to connect vertices together.
- node a node is a complete vertex in that it is considered to be weighted.
- point: here, a point is a synonym for a vertex, and is used to define the position of a vertex within the hypergraph.
- surface: a surface is a synonym for an edge, often used here to describe iterators directly yielding (mutable) references to the “Edge Values” of the hypergraph.
- vertex: a vertex is an unweighted node defining a point within the hypergraph.
§Hypergraphs
A hypergraph is an abstraction of a graph that allows edges to connect any number of vertices. This flexible data-strcture is highly mathematical, yet, extremely useful in many applications such as database design, network analysis, combinatorial optimization, modeling topological spaces, and more.
§Definition 1:
Formally, a directed hypergraph is a pair H = (V,E) where V is a set of vertices and
E is a set of hyperedges. Each hyperedge e ∈ E is a subset of V that can contain
§Features
hyper_map: enables theHyperMapimplementation, a hash-based hypergraph structuremacros: enables the implemented macros for streamlining graph management
§Dependencies
Note: While the alloc and std libraries are feature-gated, they are required for
anything useful in this crate; both are enabled by default.
rayon: enables parallel processing capabilities using therayoncrateserde: enables serialization and deserialization of hypergraphs using theserdecrate
§Examples
For more detailed examples, please refer to the examples directory.
§Example 1: Basic Usage
use rshyper::{HyperMap, Weight};
let mut graph = HyperMap::<usize, usize>::undirected();
// add some unweighted vertices
let v0 = graph.add_vertex().expect("failed to add vertex");
let v1 = graph.add_vertex().expect("failed to add vertex");
// add a weighted node
let v2 = graph.add_node(Weight(10)).expect("failed to add node");
// create some edges using those nodes
let e0 = graph.add_link([v0, v1]).expect("failed to add edge");
let e1 = graph.add_link([v1, v2]).expect("failed to add edge");
// create a surface (weighted edge) using the nodes
let e3 = graph.add_edge([v0, v2], Weight(5)).expect("failed to add surface");Modules§
- algo
- the
algomodule focuses on implementing algorithms and operators for hypergraphs - attrs
- this module implements the
GraphPropstrait and provides a concrete implementation with theAttrsstruct. These objects are used to define the attributes of a hypergraph such as the type of index used to identify vertices and edges as well as the type of graph (directed or undirected). - edge
- this module focuses on the
Edgeimplementation, providing additional types, traits, and representations for edges in a hypergraph. - error
- this module implements the
Errortype for thershypercrate. - hyper_
map - this module contains the
HyperMap, a hash-based hypergraph implementation A map-based implementation of a hypergraph providing efficient storage and manipulation of hypernodes and hyperedges. - idx
- the
idxmodule provides theIndexBase, a generic index type used to establish a solid foundation for all indices used by the hypergraph. Type aliases, such asEdgeIdandVertexId, are provided for convenience, reducing the need to continually specify the index type when working with hypergraphs. - node
- this module provides the
Nodeimplmenetation alongisde the several traits such asRawNodeandRawPointfocused on establishing a common, well-defined interface for weighted and unweighted “points” within a hypergraph. - rel
- this module establishes relational traits and implementations for components of a hypergraph.
- traits
- this module contains various traits used throughout to establish common interfaces and behaviors
- types
- this module provides various types used throughout the library
- weight
- this module implements a generic
Weightwrapper type for representing the weights of entries within the hypergraph. Additionally, the module provides theWeightlesstype alias for cases where there is no associated weight.
Macros§
- hyperedge
- The
hyperedgemacro streamlines the definition of hyperedges in a hypergraph. - hypergraph
- the [
hypergraph] macro works to aide the in the creation of hypergraphs by allowing users to define nodes and edges in a hypergraph in a more declarative way. - hypernode
- the [
hypernode] macro streamlines the process of inserting nodes into a hypergraph.
Structs§
- Attrs
Attrsis a generic implementation of theGraphPropstrait, enabling the definition of hypergraphs with different index types and graph kinds (i.e.,DirectedorUndirected).- Directed
- A marker type representing a directed graph type
- Edge
- The
Edgeimplementation essentially wraps theLinktype with aWeight - Edge
Index - A kind of index for edges in a graph
- Hyper
Map - The
HyperMapis a map-based implementation of a hypergraph that provides a flexible and efficient way to store and manipulate hypergraphs. It is designed to be generic over the types of nodes N, edges E, attributes A, and the hasher S used for hashing the nodes and edges. This design allows for a wide range of applications, from simple hypergraphs to more complex structures with custom attributes and hashing strategies. - Index
Base - A generic
IndexBaseimplementation used to represent various kinds of indices - Index
Frame - The
IndexFramestores the current edge and vertex indices in a hypergraph, allowing for efficient traversal and manipulation of the hypergraph structure. Here, when we say current we mean the next indices used to create a new edge or vertex, respectively. It is designed to be used in conjunction with hypergraph operations that require knowledge of the current position within the hypergraph, such as adding or removing edges and vertices, or iterating over the hypergraph’s elements. The cursor is generic over the index typeT, which must implement theRawIndextrait. This allows for flexibility in the choice of index representation, enabling the use of different types of indices (e.g.,Udxor some custom index types) while maintaining the same interface for the cursor. - Index
Kind Iter - An iterator over the variants of IndexKind
- IsWeighted
- Link
- Here, a
Linkessentially defines the layout of an edge within a hypergraph. The implementation is generic over the type of domain it contains, which can be a set of vertices or any other structure that implements theDomaintrait. - Mode
Iter - An iterator over the variants of Mode
- Node
- The
Nodeimplementation generically associates aVertexIdwith aWeight. - UnWeighted
- Undirected
- A marker type representing an undirected graph type
- Vertex
Index - A kind of index for vertices in a graph
- Weight
- The
Weighttype is a wrapper around a generic typeTthat provides additional functionality for working with weights in a graph context.
Enums§
- Error
- The error type for this crate
- Grid
- the
Gridenumerate the possible variations of indicies that can be used within the scope of a hypergraph. This entity is useful for enabling “compoite” collections of indicies for iteration, traversal, etc. - Index
Kind - Auto-generated discriminant enum variants
- Mode
Modeenumerates the possible graph variants enabling dynamic dispatch features.
Traits§
- AddStep
AddStepis a trait that defines a method to add a step to the current value, replacing- Apply
- The
Applytrait defines a generic, transformative operation that can be applied to an object of typeRhs. - AsWeight
- a trait for converting a type into a valid
Weight - Binary
Domain - The
BinaryDomaintrait extends theRawDomaintrait to provide specific methods for binary edges, which are edges that connect exactly two vertices. - Combine
Combinedefines a common interface for merging two edges in a hypergraph.- Concat
Concatdefines an interface for concatenating two entities into another- Contains
Containsdefines a common interface for types able to verify if they contain a given key or index; the trait strives to emulate the behavior of thecontainsmethod found in standard collections such asHashSetorBTreeSet.- Domain
- An
Domainis a trait is a specialization of theRawDomaintrait that represents a store for edges, which are collections of vertices. It is used to define the behavior - Graph
Index - This trait is used to define various kinds of indices that are used to compose graphical structures.
- Graph
Props - The
GraphPropstrait abstracts several generic types used to define a hyper graph into a single entity. - Graph
Type GraphTypeis a marker trait for graph types.- Hash
Index - The
HashIndextrait extends the [StdIndex] trait to include additional operations and behaviours commonly expected from indices in a hypergraph. - Hyper
Graph - The
HyperGraphtrait directly extends theRawHyperGraphtrait to provide additional utilities and constructors for implementors while establishing a more robust interface for hypergraphs. This trait is designed to abstract the basic behaviour of hypergraphs, enabling the generalization of implements algorithms and operators. - Hyper
Graph Iter - The
HyperGraphItertrait combines theHyperGraphIterNodeandHyperGraphIterEdgetraits to provide a unified interface for iterating over both nodes - Hyper
Graph Iter Edge - The
HyperGraphIterEdgetrait extends theHyperGraphtrait to provide iterators over the edges in the hypergraph. - Hyper
Graph Iter Node - The
HyperGraphIterNodetrait extends theHyperGraphtrait to provide iterators over the nodes in the hypergraph. - Hyper
Index - The
HyperIndextrait extends theNumIndexto define contraints for the standard index type for the crate; implementors must also implement following traits: - Indexed
Indexeddescribes a common interface for all types which are aware of some associated index. The trait is generic over a typeTwhich implements theRawIndextrait, allowing for flexibility in the type of index used while ensuring that the index type is compatible with the hypergraph’s indexing system.- Into
Edge Id - a trait for converting a type into a valid
EdgeId - Into
Node Id - a trait for converting a type into a valid
VertexId - Into
Weight - a trait for converting a type into a valid
Weight - Iter
Domain - The
IterDomaintrait defines the base interface for creating an interator over a domain of vertices. - Merge
Mergedefines a common interface for merging two entities into another- NumIndex
- The
NumIndextrait extends theRawIndextrait to include additional operations and behaviours expected from numerical indices in a hypergraph. - RawDomain
RawDomainis a trait that defines the behavior of a store that holds the vertices associated with a hyperedge or hyperfacet. It is used to abstract over different implementations of edge storage, such as arrays, vectors, or sets.- RawHyper
Graph RawHyperGraphis a trait that defines the basic operations for a hypergraph data structure.- RawIndex
- a simple trait for denoting types compatible with to be used as indices in a hypergraph. note: the trait is sealed to prevent external implementations.
- RawLayout
RawLayoutestablishes a common interface for hyperedge representations.- StdGraph
- The
StdGraphis used to denotes instances in-which the hypergraph contains binary edges meaning that each edge is composed of exactly two vertices. - Step
Self StepSelfis a trait establishing a common interface for entities that may be progressed, producing someOutputas a result. The trait is typically used to define generators for indices within the hypergraph.- Step
With StepWithis a trait defining an interface that can be best described as a more flexibletakemethod, however, instead of leaving the default value in place of the previous one, it allows for a generator function to be provided.- Transform
- A trait denoting objects capable of being transformed by another object.
- Transform
Inplace - The
TransformInplacegenerically describes objects capable of being transformed in-place by another object. - Weighted
Weightedis used to define common behaviours for types that have an associated weight.
Type Aliases§
- DiHyper
Map - a type alias for a directed
HyperMap - EdgeId
- a type alias for an [
Index] whose kind isEdgeIndex - Index
Array - a type alias for a fixed sized array of
IndexBase - Index
Set - a type alias for a
HashSetofIndexBasethat is generic over the index typeI, the kindK, and the hash builderS - Index
Slice - a type alias for a slice of
IndexBase - Index
Slice Mut - a type alias for a mutable slice of
IndexBase - Index
Slice Ref - a type alias for a reference to a slice of
IndexBase - Result
- A type alias for a Result with the crate-specific error type
Error - Udx
- a type alias for a
usizeused to define the default index type throughout the crate. - UnHyper
Map - a type alias for an undirected
HyperMap - Vertex
Array - a type alias for a fixed sized array of
VertexId - VertexB
Set - a type alias for a
VertexIdstored in aBTreeSet - Vertex
Deque - a type alias for a
VertexIdstored in aVecDeque - Vertex
Id - a type alias for an [
Index] whose kind isVertexIndex - Vertex
Set - a type alias for a
HashSetofVertexIdthat is generic over the index typeI - Vertex
Slice - a type alias for a slice of
VertexId - Vertex
Slice Mut - a type alias for a mutable slice of
VertexId - Vertex
Slice Ref - a type alias for a reference to a slice of
VertexId - Vertex
Vec - a type alias for a
VecofVertexIdthat is generic over the index typeIx - Weightless
- An
Weightlesstypes is a type alias for aWeightthat uses the [UnWeight] marker type to indicate that it has no weight.