pub struct VectorFst<A: Arc> { /* private fields */ }Expand description
A simple, mutable FST whose states and arcs are stored in standard Vecs.
Implementations§
Source§impl<A: Arc> VectorFst<A>
impl<A: Arc> VectorFst<A>
Sourcepub fn read<R: Read>(
reader: &mut R,
opts: &FstReadOptions,
) -> Result<Self, OpenFstError>
pub fn read<R: Read>( reader: &mut R, opts: &FstReadOptions, ) -> Result<Self, OpenFstError>
Reads a VectorFst from a stream.
Unlike ConstFst, the states and
arcs are written field by field rather than as a block of memory, so
there is nothing here that could be mapped and nothing that depends on
how a struct happens to be laid out.
Sourcepub fn write_fst<F: Fst<A>, W: Write>(
fst: &F,
writer: &mut W,
opts: &FstWriteOptions,
) -> Result<(), OpenFstError>
pub fn write_fst<F: Fst<A>, W: Write>( fst: &F, writer: &mut W, opts: &FstWriteOptions, ) -> Result<(), OpenFstError>
Writes any FST out in this format.
SICADA-DIVERGE: upstream writes a header saying it does not know the
state count when the stream cannot seek, then seeks back to correct it
when it can. This always counts first; see
ConstFst::write_fst,
which makes the same trade for the same reason.
Sourcepub fn write<W: Write>(
&self,
writer: &mut W,
opts: &FstWriteOptions,
) -> Result<(), OpenFstError>
pub fn write<W: Write>( &self, writer: &mut W, opts: &FstWriteOptions, ) -> Result<(), OpenFstError>
Writes this FST out.
Trait Implementations§
Source§impl<A: Arc> ContiguousArcsFst<A> for VectorFst<A>
impl<A: Arc> ContiguousArcsFst<A> for VectorFst<A>
Source§fn arcs_slice(&self, state: A::StateId) -> &[A]
fn arcs_slice(&self, state: A::StateId) -> &[A]
Returns a contiguous slice of arcs leaving the given state.
Source§impl<A: Arc> ExpandedFst<A> for VectorFst<A>
impl<A: Arc> ExpandedFst<A> for VectorFst<A>
Source§fn num_states(&self) -> usize
fn num_states(&self) -> usize
Returns the total number of states in the FST.
Source§impl<A: Arc> Fst<A> for VectorFst<A>
impl<A: Arc> Fst<A> for VectorFst<A>
Source§type StateIter<'a> = VectorFstStateIter<'a, A>
where
A: 'a
type StateIter<'a> = VectorFstStateIter<'a, A> where A: 'a
An iterator over the states of the FST.
Source§type ArcIter<'a> = Cloned<Iter<'a, A>>
where
A: 'a
type ArcIter<'a> = Cloned<Iter<'a, A>> where A: 'a
An iterator over the outgoing arcs of a state.
Clone is required to allow multi-pass algorithms (e.g., matchers in Compose)
to save and restore iteration positions effortlessly without C++ Seek or Reset.Source§fn start(&self) -> Option<A::StateId>
fn start(&self) -> Option<A::StateId>
Returns the initial state ID, or
None if the FST is empty.Source§fn final_weight(&self, state: A::StateId) -> A::Weight
fn final_weight(&self, state: A::StateId) -> A::Weight
Returns the final weight of the given state.
If the state is not final, this must return
Weight::zero().Source§fn num_arcs(&self, state: A::StateId) -> usize
fn num_arcs(&self, state: A::StateId) -> usize
Returns the number of arcs leaving the given state.
Source§fn num_input_epsilons(&self, state: A::StateId) -> usize
fn num_input_epsilons(&self, state: A::StateId) -> usize
Returns the number of input epsilon arcs leaving the given state.
Source§fn num_output_epsilons(&self, state: A::StateId) -> usize
fn num_output_epsilons(&self, state: A::StateId) -> usize
Returns the number of output epsilon arcs leaving the given state.
Source§fn num_states_if_known(&self) -> Option<usize>
fn num_states_if_known(&self) -> Option<usize>
Returns the number of states if it is finite and can be computed in O(1) time.
Otherwise returns
None.Source§fn properties(&self, mask: u64, test: bool) -> u64
fn properties(&self, mask: u64, test: bool) -> u64
Property bits.
If
test is false, returns stored properties bits (some possibly unknown).
If test is true, computes the properties if they are unknown.Source§fn input_symbols(&self) -> Option<AtomicRc<SymbolTable>>
fn input_symbols(&self) -> Option<AtomicRc<SymbolTable>>
Returns the input label symbol table, if any.
Using
Arc allows cheap sharing across FST operations.Source§fn output_symbols(&self) -> Option<AtomicRc<SymbolTable>>
fn output_symbols(&self) -> Option<AtomicRc<SymbolTable>>
Returns the output label symbol table, if any.
Source§fn states<'a>(&'a self) -> Self::StateIter<'a>
fn states<'a>(&'a self) -> Self::StateIter<'a>
Returns an iterator over all state IDs in the FST.
Source§fn arcs<'a>(&'a self, state: A::StateId) -> Self::ArcIter<'a>
fn arcs<'a>(&'a self, state: A::StateId) -> Self::ArcIter<'a>
Returns an iterator over the outgoing arcs of the given state.
Source§fn count_states(&self) -> usize
fn count_states(&self) -> usize
Computes the exact number of states in the FST.
If the state count is known in O(1) (i.e.
num_states_if_known returns Some),
it uses that. Otherwise, it iterates through all states in O(V) time.Source§fn count_arcs(&self) -> usize
fn count_arcs(&self) -> usize
Computes the exact number of arcs in the FST in O(V) time.
Source§impl<A: Arc> MutableFst<A> for VectorFst<A>
impl<A: Arc> MutableFst<A> for VectorFst<A>
Source§fn set_final(&mut self, state: A::StateId, weight: A::Weight)
fn set_final(&mut self, state: A::StateId, weight: A::Weight)
Sets the final weight of a given state.
Setting it to
Weight::zero() effectively marks the state as non-final.Source§fn set_properties(&mut self, props: u64, mask: u64)
fn set_properties(&mut self, props: u64, mask: u64)
Explicitly updates the properties mask.
Source§fn add_states(&mut self, n: usize)
fn add_states(&mut self, n: usize)
Adds
n new states to the FST.Source§fn arcs_mut(&mut self, state: A::StateId) -> &mut [A]
fn arcs_mut(&mut self, state: A::StateId) -> &mut [A]
The arcs leaving
state, to be rearranged in place. Read moreSource§fn delete_arcs_n(&mut self, state: A::StateId, n: usize)
fn delete_arcs_n(&mut self, state: A::StateId, n: usize)
Deletes
n outgoing arcs from a given state.Source§fn delete_arcs(&mut self, state: A::StateId)
fn delete_arcs(&mut self, state: A::StateId)
Deletes all outgoing arcs from a given state.
Source§fn delete_all_states(&mut self)
fn delete_all_states(&mut self)
Deletes all states and arcs, leaving the FST empty.
Source§fn delete_states(&mut self, dstates: &[A::StateId])
fn delete_states(&mut self, dstates: &[A::StateId])
Deletes specific states.
Note: This renumbers the remaining states and invalidates existing Arc nextstates.
Source§fn reserve_states(&mut self, n: usize)
fn reserve_states(&mut self, n: usize)
Hints the underlying allocation to reserve space for
n total states.Source§fn reserve_arcs(&mut self, state: A::StateId, n: usize)
fn reserve_arcs(&mut self, state: A::StateId, n: usize)
Hints the underlying allocation to reserve space for
n arcs on a specific state.Source§fn set_input_symbols(&mut self, syms: Option<AtomicRc<SymbolTable>>)
fn set_input_symbols(&mut self, syms: Option<AtomicRc<SymbolTable>>)
Attaches an input symbol table.
Source§fn set_output_symbols(&mut self, syms: Option<AtomicRc<SymbolTable>>)
fn set_output_symbols(&mut self, syms: Option<AtomicRc<SymbolTable>>)
Attaches an output symbol table.
Source§fn mutable_input_symbols(&mut self) -> Option<&mut SymbolTable>
fn mutable_input_symbols(&mut self) -> Option<&mut SymbolTable>
The input symbol table, to be changed in place. Read more
Source§fn mutable_output_symbols(&mut self) -> Option<&mut SymbolTable>
fn mutable_output_symbols(&mut self) -> Option<&mut SymbolTable>
The output symbol table, to be changed in place. See
mutable_input_symbols.Auto Trait Implementations§
impl<A> !Freeze for VectorFst<A>
impl<A> RefUnwindSafe for VectorFst<A>
impl<A> Send for VectorFst<A>
impl<A> Sync for VectorFst<A>
impl<A> Unpin for VectorFst<A>
impl<A> UnsafeUnpin for VectorFst<A>
impl<A> UnwindSafe for VectorFst<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more