honeycomb_core/cmap/dim2/links/
mod.rs

1mod one;
2mod two;
3
4use crate::cmap::{CMap2, DartIdType, LinkError};
5use crate::geometry::CoordsFloat;
6use crate::stm::{Transaction, TransactionClosureResult};
7
8/// # **Link operations**
9impl<T: CoordsFloat> CMap2<T> {
10    /// `I`-link operator.
11    ///
12    /// # Description
13    ///
14    /// This operation corresponds to coherently linking two darts via their *β* images. Unlike
15    /// sewing, this does not alter associated attributes. For a thorough explanation of this
16    /// operation, its hypothesis & consequences, refer to the [user guide][UG].
17    ///
18    /// [UG]: https://lihpc-computational-geometry.github.io/honeycomb/user-guide/definitions/sew.html
19    ///
20    /// # Arguments
21    ///
22    /// - `const I: u8` -- Link dimension.
23    /// - `trans: &mut Transaction` -- Transaction associated to the operation.
24    /// - `ld: DartIdType` -- First dart ID.
25    /// - `rd: DartIdType` -- Second dart ID.
26    ///
27    /// # Errors
28    ///
29    /// This method should be called in a transactional context. The `Result` is then used to
30    /// validate the transaction; Errors should not be processed manually, only processed via the
31    /// `?` operator. The policy in case of failure can be defined when creating the transaction,
32    /// using `Transaction::with_control`.
33    ///
34    /// # Panics
35    ///
36    /// The method may panic if:
37    /// - `I >= 3` or `I == 0`,
38    /// - the two darts are not `I`-linkable.
39    pub fn link<const I: u8>(
40        &self,
41        trans: &mut Transaction,
42        ld: DartIdType,
43        rd: DartIdType,
44    ) -> TransactionClosureResult<(), LinkError> {
45        // these assertions + match on a const are optimized away
46        assert!(I < 3);
47        assert_ne!(I, 0);
48        match I {
49            1 => self.one_link(trans, ld, rd),
50            2 => self.two_link(trans, ld, rd),
51            _ => unreachable!(),
52        }
53    }
54
55    /// `I`-unlink operator.
56    ///
57    /// # Description
58    ///
59    /// This operation corresponds to unlinking two darts by resetting their *β* images. Unlike
60    /// unsewing, this does not alter associated attributes. For a thorough explanation of this
61    /// operation, its hypothesis & consequences, refer to the [user guide][UG].
62    ///
63    /// [UG]: https://lihpc-computational-geometry.github.io/honeycomb/user-guide/definitions/sew.html
64    ///
65    /// # Arguments
66    ///
67    /// - `const I: u8` -- Unlink dimension.
68    /// - `trans: &mut Transaction` -- Transaction associated to the operation.
69    /// - `ld: DartIdType` -- First dart ID.
70    ///
71    /// The second dart ID is fetched using `I` and `ld`.
72    ///
73    /// # Errors
74    ///
75    /// This method should be called in a transactional context. The `Result` is then used to
76    /// validate the transaction; Errors should not be processed manually, only processed via the
77    /// `?` operator. The policy in case of failure can be defined when creating the transaction,
78    /// using `Transaction::with_control`.
79    ///
80    /// # Panics
81    ///
82    /// The method may panic if:
83    /// - `I >= 3` or `I == 0`,
84    /// - `ld` is already `I`-free.
85    pub fn unlink<const I: u8>(
86        &self,
87        trans: &mut Transaction,
88        ld: DartIdType,
89    ) -> TransactionClosureResult<(), LinkError> {
90        // these assertions + match on a const are optimized away
91        assert!(I < 3);
92        assert_ne!(I, 0);
93        match I {
94            1 => self.one_unlink(trans, ld),
95            2 => self.two_unlink(trans, ld),
96            _ => unreachable!(),
97        }
98    }
99
100    #[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
101    /// `I`-link operator.
102    ///
103    /// This variant is equivalent to [`link`][Self::link], but internally uses a transaction that
104    /// will be retried until validated.
105    pub fn force_link<const I: u8>(&self, ld: DartIdType, rd: DartIdType) -> Result<(), LinkError> {
106        // these assertions + match on a const are optimized away
107        assert!(I < 3);
108        assert_ne!(I, 0);
109        match I {
110            1 => self.force_one_link(ld, rd),
111            2 => self.force_two_link(ld, rd),
112            _ => unreachable!(),
113        }
114    }
115
116    #[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
117    /// # `I`-unlink operator.
118    ///
119    /// This variant is equivalent to [`unlink`][Self::unlink], but internally uses a transaction
120    /// that will be retried until validated.
121    pub fn force_unlink<const I: u8>(&self, ld: DartIdType) -> Result<(), LinkError> {
122        // these assertions + match on a const are optimized away
123        assert!(I < 3);
124        assert_ne!(I, 0);
125        match I {
126            1 => self.force_one_unlink(ld),
127            2 => self.force_two_unlink(ld),
128            _ => unreachable!(),
129        }
130    }
131}