1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::mem::swap;
use crate::fst_traits::{ExpandedFst, MutableFst};
/// This operation inverts the transduction corresponding to an FST
/// by exchanging the FST's input and output labels.
///
/// # Example 1
/// ```
/// # use rustfst::fst;
/// # use rustfst::utils::{acceptor, transducer};
/// # use rustfst::semirings::{Semiring, IntegerWeight};
/// # use rustfst::fst_impls::VectorFst;
/// # use rustfst::algorithms::invert;
/// let mut fst : VectorFst<IntegerWeight> = fst![2 => 3];
/// invert(&mut fst);
///
/// assert_eq!(fst, fst![3 => 2]);
/// ```
///
/// # Example 2
///
/// ## Input
///
/// 
///
/// ## Invert
///
/// 
///
pub fn invert<F: ExpandedFst + MutableFst>(fst: &mut F) {
for state in 0..fst.num_states() {
for arc in unsafe { fst.arcs_iter_unchecked_mut(state) } {
swap(&mut arc.ilabel, &mut arc.olabel);
}
}
}