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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// TODO: Use a filter instead of creating a custom iterator
// use crate::fst_traits::{Fst, StateIterator};
// use crate::semirings::Semiring;
// use crate::StateId;
// use std::marker::PhantomData;
//
// #[derive(Debug)]
// pub struct FinalState<W> {
// pub state_id: StateId,
// pub final_weight: W,
// }
//
// /// Trait to iterate over the final states of a wFST.
// pub trait FinalStatesIterator<W>
// where W: Semiring
// {
// type Iter: Iterator<Item = FinalState<W>>;
// fn final_states_iter(&self) -> Self::Iter;
// }
//
// impl<'f, W, F> FinalStatesIterator<W> for F
// where
// W: Semiring + 'f,
// F: 'f + Fst<W>,
// {
// type Iter = StructFinalStatesIterator<'f, W, F>;
// fn final_states_iter(&'f self) -> Self::Iter {
// StructFinalStatesIterator::new(&self)
// }
// }
//
// pub struct StructFinalStatesIterator<'f, W, F>
// where
// W: Semiring + 'f,
// F: 'f + Fst<W>,
// {
// fst: &'f F,
// it: <F as StateIterator<'f>>::Iter,
// w: PhantomData<W>
// }
//
// impl<'f, W, F> StructFinalStatesIterator<'f, W, F>
// where
// W: Semiring + 'f,
// F: 'f + Fst<W>,
// {
// fn new(fst: &'f F) -> StructFinalStatesIterator<W, F> {
// StructFinalStatesIterator {
// fst,
// it: fst.states_iter(),
// w: PhantomData
// }
// }
// }
//
// impl<'f, W, F> Iterator for StructFinalStatesIterator<'f, W, F>
// where
// W: Semiring + 'f,
// F: 'f + Fst<W>,
// {
// type Item = FinalState<W>;
//
// fn next(&mut self) -> Option<Self::Item> {
// while let Some(state_id) = self.it.next() {
// if let Some(final_weight) = unsafe { self.fst.final_weight_unchecked(state_id) } {
// return Some(FinalState {
// state_id,
// final_weight: &final_weight,
// });
// }
// }
// None
// }
// }