catlog/one/
computad.rs

1/*! Computads in dimension one.
2
3A 1-computad, in the strictest sense of the term, is the generating data for a
4free category, which is just a [graph](super::graph). This module provides
5simple data structures to aid in defining computads for categories with extra
6structure. For example, a computad for monoidal categories is called a "tensor
7scheme" by Joyal and Street and a "pre-net" in the Petri net literature.
8 */
9
10use std::hash::{BuildHasher, Hash, RandomState};
11
12use derivative::Derivative;
13use derive_more::Constructor;
14
15use super::graph::ColumnarGraph;
16use crate::zero::*;
17
18/** Top-dimensional data of a 1-computad.
19
20Intended for use with [`Computad`].
21 */
22#[derive(Clone, Debug, Derivative)]
23#[derivative(Default(bound = "S: Default"))]
24pub struct ComputadTop<Ob, E, S = RandomState> {
25    /// Set of edges in the computad.
26    pub edge_set: HashFinSet<E, S>,
27
28    /// Source map of the computad.
29    pub src_map: HashColumn<E, Ob, S>,
30
31    /// Target map of the computad.
32    pub tgt_map: HashColumn<E, Ob, S>,
33}
34
35impl<Ob, E, S> ComputadTop<Ob, E, S>
36where
37    Ob: Eq + Clone,
38    E: Eq + Clone + Hash,
39    S: BuildHasher,
40{
41    /// Adds an edge to the computad.
42    pub fn add_edge(&mut self, e: E, src: Ob, tgt: Ob) -> bool {
43        self.src_map.set(e.clone(), src);
44        self.tgt_map.set(e.clone(), tgt);
45        self.edge_set.insert(e)
46    }
47}
48
49/** A 1-computad.
50
51The set of objects is assumed already constructed, possibly from other
52generating data, while the top-dimensional generating data is provided directly.
53 */
54#[derive(Constructor)]
55pub struct Computad<'a, Ob, ObSet, E, S = RandomState> {
56    objects: &'a ObSet,
57    computad: &'a ComputadTop<Ob, E, S>,
58}
59
60impl<'a, Ob, ObSet, E, S> ColumnarGraph for Computad<'a, Ob, ObSet, E, S>
61where
62    Ob: Eq + Clone,
63    ObSet: Set<Elem = Ob>,
64    E: Eq + Clone + Hash,
65    S: BuildHasher,
66{
67    type V = Ob;
68    type E = E;
69    type Vertices = ObSet;
70    type Edges = HashFinSet<E, S>;
71    type Src = HashColumn<E, Ob, S>;
72    type Tgt = HashColumn<E, Ob, S>;
73
74    fn vertex_set(&self) -> &Self::Vertices {
75        self.objects
76    }
77    fn edge_set(&self) -> &Self::Edges {
78        &self.computad.edge_set
79    }
80    fn src_map(&self) -> &Self::Src {
81        &self.computad.src_map
82    }
83    fn tgt_map(&self) -> &Self::Tgt {
84        &self.computad.tgt_map
85    }
86}