Skip to main content

MutableFst

Trait MutableFst 

Source
pub trait MutableFst<A: Arc>: ExpandedFst<A> {
Show 18 methods // Required methods fn set_start(&mut self, state: A::StateId); fn set_final(&mut self, state: A::StateId, weight: A::Weight); fn set_properties(&mut self, props: u64, mask: u64); fn add_state(&mut self) -> A::StateId; fn add_states(&mut self, n: usize); fn add_arc(&mut self, state: A::StateId, arc: A); fn arcs_mut(&mut self, state: A::StateId) -> &mut [A]; fn delete_arcs_n(&mut self, state: A::StateId, n: usize); fn delete_arcs(&mut self, state: A::StateId); fn delete_all_states(&mut self); fn delete_states(&mut self, states: &[A::StateId]); fn reserve_states(&mut self, n: usize); fn reserve_arcs(&mut self, state: A::StateId, n: usize); fn set_input_symbols(&mut self, syms: Option<AtomicRc<SymbolTable>>); fn set_output_symbols(&mut self, syms: Option<AtomicRc<SymbolTable>>); fn mutable_input_symbols(&mut self) -> Option<&mut SymbolTable>; fn mutable_output_symbols(&mut self) -> Option<&mut SymbolTable>; fn mutate_arcs<F>(&mut self, state: A::StateId, mutator: F) where F: FnMut(&mut A);
}
Expand description

An FST that can be mutated (states and arcs added/removed).

Required Methods§

Source

fn set_start(&mut self, state: A::StateId)

Sets the initial state.

Passing ArcStateId::no_state clears it, so that Fst::start reports None.

Source

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)

Explicitly updates the properties mask.

Source

fn add_state(&mut self) -> A::StateId

Adds a new state to the FST and returns its ID.

Source

fn add_states(&mut self, n: usize)

Adds n new states to the FST.

Source

fn add_arc(&mut self, state: A::StateId, arc: A)

Adds an outgoing arc to a given state.

Source

fn arcs_mut(&mut self, state: A::StateId) -> &mut [A]

The arcs leaving state, to be rearranged in place.

Empty for a state that does not exist. Port of upstream’s MutableArcIterator, which exists for the same reason: rewriting a state’s arcs by deleting them and adding them back costs a pass over them per step, and makes every add_arc re-derive the property bits one arc at a time.

The property bits are not updated. Rearranging arcs cannot change them, which is why a sort can use this and leave them alone; a caller that rewrites a label, a weight or a destination has to set them afterwards.

Source

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)

Deletes all outgoing arcs from a given state.

Source

fn delete_all_states(&mut self)

Deletes all states and arcs, leaving the FST empty.

Source

fn delete_states(&mut self, states: &[A::StateId])

Deletes specific states. Note: This renumbers the remaining states and invalidates existing Arc nextstates.

Source

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)

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>>)

Attaches an input symbol table.

Source

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>

The input symbol table, to be changed in place.

Returns None when there is no table. The table is copied first if it is shared, so changing it here never reaches another FST holding the same one.

Source

fn mutable_output_symbols(&mut self) -> Option<&mut SymbolTable>

The output symbol table, to be changed in place. See mutable_input_symbols.

Source

fn mutate_arcs<F>(&mut self, state: A::StateId, mutator: F)
where F: FnMut(&mut A),

Rewrites every arc leaving state.

SICADA-DIVERGE: upstream exposes a MutableArcIterator whose SetValue writes back through the iterator, and warns that adding or removing arcs while one is open invalidates it. Handing the arcs to a closure says the same thing with no way to get it wrong, and lets the FST recompute its property bits once at the end rather than per arc.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<A: Arc> MutableFst<A> for VectorFst<A>