hypergraph/core/
indexes.rs

1use std::fmt::{
2    Display,
3    Formatter,
4    Result,
5};
6
7/// Vertex stable index representation as usize.
8/// Uses the newtype index pattern.
9/// <https://matklad.github.io/2018/06/04/newtype-index-pattern.html>
10#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
11pub struct VertexIndex(pub usize);
12
13impl Display for VertexIndex {
14    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
15        write!(formatter, "{}", self.0)
16    }
17}
18
19impl From<usize> for VertexIndex {
20    fn from(index: usize) -> Self {
21        VertexIndex(index)
22    }
23}
24
25/// Hyperedge stable index representation as usize.
26/// Uses the newtype index pattern.
27/// <https://matklad.github.io/2018/06/04/newtype-index-pattern.html>
28#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
29pub struct HyperedgeIndex(pub usize);
30
31impl Display for HyperedgeIndex {
32    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
33        write!(f, "{}", self.0)
34    }
35}
36
37impl From<usize> for HyperedgeIndex {
38    fn from(index: usize) -> Self {
39        HyperedgeIndex(index)
40    }
41}