catlog/one/
computad.rs

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