pub struct Fsm { /* private fields */ }Expand description
A mutable finite-state machine.
Implementations§
Source§impl Fsm
impl Fsm
Sourcepub fn to_compact(&self) -> CompactFsm
pub fn to_compact(&self) -> CompactFsm
Sort edges and pack into the CSR CompactFsm form.
Source§impl Fsm
impl Fsm
Sourcepub fn with_states(num_states: usize) -> Self
pub fn with_states(num_states: usize) -> Self
Create an FSM with num_states states and no edges.
Sourcepub fn from_edges(edges: Vec<Vec<FsmEdge>>, edge_aux_data: Vec<i32>) -> Self
pub fn from_edges(edges: Vec<Vec<FsmEdge>>, edge_aux_data: Vec<i32>) -> Self
Create an FSM from a ready-made adjacency list.
Sourcepub fn num_states(&self) -> usize
pub fn num_states(&self) -> usize
Number of states.
Sourcepub fn edges_mut(&mut self, state: usize) -> &mut Vec<FsmEdge>
pub fn edges_mut(&mut self, state: usize) -> &mut Vec<FsmEdge>
Mutable outgoing edges of state.
Sourcepub fn edge_aux_data(&self) -> &[i32]
pub fn edge_aux_data(&self) -> &[i32]
The repeat-edge auxiliary data buffer.
Sourcepub fn set_edge_aux_data(&mut self, data: Vec<i32>)
pub fn set_edge_aux_data(&mut self, data: Vec<i32>)
Replace the repeat-edge auxiliary data buffer.
Sourcepub fn repeat_edge_info(&self, idx: i16) -> RepeatEdgeRef
pub fn repeat_edge_info(&self, idx: i16) -> RepeatEdgeRef
Decode the repeat-edge info stored at aux index idx.
Sourcepub fn add_edge(&mut self, from: usize, to: usize, min: i16, max: i16)
pub fn add_edge(&mut self, from: usize, to: usize, min: i16, max: i16)
Add a character-range edge from -[min,max]-> to.
Sourcepub fn add_typed_edge(
&mut self,
from: usize,
to: usize,
edge_type: i16,
value: i16,
)
pub fn add_typed_edge( &mut self, from: usize, to: usize, edge_type: i16, value: i16, )
Add a raw typed edge (type is one of edge_type, value
goes into max).
Sourcepub fn add_epsilon_edge(&mut self, from: usize, to: usize)
pub fn add_epsilon_edge(&mut self, from: usize, to: usize)
Add an epsilon transition.
Sourcepub fn add_rule_edge(&mut self, from: usize, to: usize, rule_id: i16)
pub fn add_rule_edge(&mut self, from: usize, to: usize, rule_id: i16)
Add a rule-reference edge for rule_id.
Sourcepub fn add_eos_edge(&mut self, from: usize, to: usize)
pub fn add_eos_edge(&mut self, from: usize, to: usize)
Add an EOS edge.
Sourcepub fn add_repeat_edge(
&mut self,
from: usize,
to: usize,
rule_id: i32,
lower: i32,
upper: i32,
)
pub fn add_repeat_edge( &mut self, from: usize, to: usize, rule_id: i32, lower: i32, upper: i32, )
Add a repeat-reference edge, allocating [rule_id, lower, upper]
into edge_aux_data. The source state must have no other edges.
Sourcepub fn add_fsm(&mut self, other: &Fsm) -> Vec<usize>
pub fn add_fsm(&mut self, other: &Fsm) -> Vec<usize>
Splice other into self, offsetting all of other’s state ids.
Returns the state mapping other_id -> new_id.
Sourcepub fn sort_edges(&mut self)
pub fn sort_edges(&mut self)
Sort every state’s edges by (min, max, target).
Sourcepub fn rebuild_with_mapping(
&self,
state_mapping: &[usize],
new_num_states: usize,
) -> Fsm
pub fn rebuild_with_mapping( &self, state_mapping: &[usize], new_num_states: usize, ) -> Fsm
Rebuild with remapped state ids. Epsilon self-loops created by the mapping are dropped; duplicate edges per row are removed.
Source§impl Fsm
impl Fsm
Sourcepub fn next_state(&self, from: usize, value: i32, edge_type: i16) -> i32
pub fn next_state(&self, from: usize, value: i32, edge_type: i16) -> i32
Single-character / typed transition. Returns the first matching
target, or NO_NEXT_STATE. edge_type must not be epsilon.
Sourcepub fn epsilon_closure(&self, state_set: &mut AHashSet<i32>)
pub fn epsilon_closure(&self, state_set: &mut AHashSet<i32>)
Epsilon closure (in place); state_set is not cleared first.
Sourcepub fn advance(
&self,
from: &AHashSet<i32>,
value: i32,
result: &mut AHashSet<i32>,
edge_type: i16,
from_is_closure: bool,
)
pub fn advance( &self, from: &AHashSet<i32>, value: i32, result: &mut AHashSet<i32>, edge_type: i16, from_is_closure: bool, )
Advance a set of states by value along edge_type edges.
result is cleared first; the epsilon closure of the result is
included. Set from_is_closure if from is already closed.
Sourcepub fn possible_rules(&self, state: usize, rules: &mut AHashSet<i32>)
pub fn possible_rules(&self, state: usize, rules: &mut AHashSet<i32>)
All rule ids referenced by state’s outgoing edges.
Sourcepub fn reachable_states(&self, from: &[i32], result: &mut AHashSet<i32>)
pub fn reachable_states(&self, from: &[i32], result: &mut AHashSet<i32>)
All states reachable from from (including from). result is
cleared first.
Trait Implementations§
impl Eq for Fsm
impl StructuralPartialEq for Fsm
Auto Trait Implementations§
impl Freeze for Fsm
impl RefUnwindSafe for Fsm
impl Send for Fsm
impl Sync for Fsm
impl Unpin for Fsm
impl UnwindSafe for Fsm
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.