use super::LearnedRule;
use crate::rule::Rule;
use rstm_core::{Direction, Head, Tail};
use rstm_state::RawState;
impl<T, Q, S> LearnedRule<T, Q, S>
where
Q: RawState,
{
pub const fn new(head: Head<Q, S>, tail: Tail<Q, S>, confidence: T) -> Self {
Self {
confidence,
head,
tail,
}
}
pub fn from_rule(rule: Rule<Q, S>, confidence: T) -> Self {
Self::new(rule.head, rule.tail, confidence)
}
pub const fn from_parts(
state: Q,
symbol: S,
direction: Direction,
next_state: Q,
write_symbol: S,
confidence: T,
) -> Self {
let head = Head::new(state, symbol);
let tail = Tail::new(direction, next_state, write_symbol);
Self::new(head, tail, confidence)
}
pub const fn confidence(&self) -> &T {
&self.confidence
}
pub const fn head(&self) -> Head<&Q, &S> {
self.head.view()
}
pub const fn head_mut(&mut self) -> Head<&mut Q, &mut S> {
self.head.view_mut()
}
pub const fn tail(&self) -> Tail<&Q, &S> {
self.tail.view()
}
pub const fn tail_mut(&mut self) -> Tail<&mut Q, &mut S> {
self.tail.view_mut()
}
}
impl<Q, S, T> From<Rule<Q, S>> for LearnedRule<T, Q, S>
where
Q: RawState,
T: Default,
{
fn from(rule: Rule<Q, S>) -> Self {
Self::new(rule.head, rule.tail, <T>::default())
}
}