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 theHyperMap
implementation, 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 therayon
crateserde
: enables serialization and deserialization of hypergraphs using theserde
crate
§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
algo
module focuses on implementing algorithms and operators for hypergraphs - attrs
- this module implements the
GraphProps
trait and provides a concrete implementation with theAttrs
struct. 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
Edge
implementation, providing additional types, traits, and representations for edges in a hypergraph. - error
- this module implements the
Error
type for thershyper
crate. - 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
idx
module provides theIndexBase
, a generic index type used to establish a solid foundation for all indices used by the hypergraph. Type aliases, such asEdgeId
andVertexId
, are provided for convenience, reducing the need to continually specify the index type when working with hypergraphs. - node
- this module provides the
Node
implmenetation alongisde the several traits such asRawNode
andRawPoint
focused 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
Weight
wrapper type for representing the weights of entries within the hypergraph. Additionally, the module provides theWeightless
type alias for cases where there is no associated weight.
Macros§
- hyperedge
- The
hyperedge
macro 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
Attrs
is a generic implementation of theGraphProps
trait, enabling the definition of hypergraphs with different index types and graph kinds (i.e.,Directed
orUndirected
).- Directed
- A marker type representing a directed graph type
- Edge
- The
Edge
implementation essentially wraps theLink
type with aWeight
- Edge
Index - A kind of index for edges in a graph
- Hyper
Map - The
HyperMap
is 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
IndexBase
implementation used to represent various kinds of indices - Index
Frame - The
IndexFrame
stores 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 theRawIndex
trait. This allows for flexibility in the choice of index representation, enabling the use of different types of indices (e.g.,Udx
or 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
Link
essentially 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 theDomain
trait. - Mode
Iter - An iterator over the variants of Mode
- Node
- The
Node
implementation generically associates aVertexId
with aWeight
. - UnWeighted
- Undirected
- A marker type representing an undirected graph type
- Vertex
Index - A kind of index for vertices in a graph
- Weight
- The
Weight
type is a wrapper around a generic typeT
that provides additional functionality for working with weights in a graph context.
Enums§
- Error
- The error type for this crate
- Grid
- the
Grid
enumerate 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
Mode
enumerates the possible graph variants enabling dynamic dispatch features.
Traits§
- AddStep
AddStep
is a trait that defines a method to add a step to the current value, replacing- Apply
- The
Apply
trait 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
BinaryDomain
trait extends theRawDomain
trait to provide specific methods for binary edges, which are edges that connect exactly two vertices. - Combine
Combine
defines a common interface for merging two edges in a hypergraph.- Concat
Concat
defines an interface for concatenating two entities into another- Contains
Contains
defines a common interface for types able to verify if they contain a given key or index; the trait strives to emulate the behavior of thecontains
method found in standard collections such asHashSet
orBTreeSet
.- Domain
- An
Domain
is a trait is a specialization of theRawDomain
trait 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
GraphProps
trait abstracts several generic types used to define a hyper graph into a single entity. - Graph
Type GraphType
is a marker trait for graph types.- Hash
Index - The
HashIndex
trait extends the [StdIndex
] trait to include additional operations and behaviours commonly expected from indices in a hypergraph. - Hyper
Graph - The
HyperGraph
trait directly extends theRawHyperGraph
trait 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
HyperGraphIter
trait combines theHyperGraphIterNode
andHyperGraphIterEdge
traits to provide a unified interface for iterating over both nodes - Hyper
Graph Iter Edge - The
HyperGraphIterEdge
trait extends theHyperGraph
trait to provide iterators over the edges in the hypergraph. - Hyper
Graph Iter Node - The
HyperGraphIterNode
trait extends theHyperGraph
trait to provide iterators over the nodes in the hypergraph. - Hyper
Index - The
HyperIndex
trait extends theNumIndex
to define contraints for the standard index type for the crate; implementors must also implement following traits: - Indexed
Indexed
describes a common interface for all types which are aware of some associated index. The trait is generic over a typeT
which implements theRawIndex
trait, 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
IterDomain
trait defines the base interface for creating an interator over a domain of vertices. - Merge
Merge
defines a common interface for merging two entities into another- NumIndex
- The
NumIndex
trait extends theRawIndex
trait to include additional operations and behaviours expected from numerical indices in a hypergraph. - RawDomain
RawDomain
is 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 RawHyperGraph
is 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
RawLayout
establishes a common interface for hyperedge representations.- StdGraph
- The
StdGraph
is used to denotes instances in-which the hypergraph contains binary edges meaning that each edge is composed of exactly two vertices. - Step
Self StepSelf
is a trait establishing a common interface for entities that may be progressed, producing someOutput
as a result. The trait is typically used to define generators for indices within the hypergraph.- Step
With StepWith
is a trait defining an interface that can be best described as a more flexibletake
method, 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
TransformInplace
generically describes objects capable of being transformed in-place by another object. - Weighted
Weighted
is 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
HashSet
ofIndexBase
that 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
usize
used 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
VertexId
stored in aBTreeSet
- Vertex
Deque - a type alias for a
VertexId
stored in aVecDeque
- Vertex
Id - a type alias for an [
Index
] whose kind isVertexIndex
- Vertex
Set - a type alias for a
HashSet
ofVertexId
that 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
Vec
ofVertexId
that is generic over the index typeIx
- Weightless
- An
Weightless
types is a type alias for aWeight
that uses the [UnWeight
] marker type to indicate that it has no weight.