use super::AstarAgenda;
use crate::StateId;
use crate::algebras::{SpanAstarLeftIndex, SpanProductSiblingFinder};
use std::cmp::Ordering;
use std::collections::BinaryHeap;
#[derive(Clone, Copy, Debug)]
pub(super) struct SiblingEntry {
pub(super) merit: f64,
pub(super) sibling_index: u32,
}
impl PartialEq for SiblingEntry {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl Eq for SiblingEntry {}
impl PartialOrd for SiblingEntry {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SiblingEntry {
fn cmp(&self, other: &Self) -> Ordering {
self.merit
.total_cmp(&other.merit)
.then_with(|| other.sibling_index.cmp(&self.sibling_index))
}
}
pub(super) struct SpanGenerator {
pub(super) trigger: StateId,
pub(super) trigger_right: StateId,
pub(super) trigger_left: StateId,
pub(super) position: u8,
pub(super) group_idx: u32,
pub(super) pending: BinaryHeap<SiblingEntry>,
}
#[derive(Default)]
pub(super) struct SpanLazyFrontier {
pub(super) finder: SpanProductSiblingFinder,
pub(super) generators: Vec<SpanGenerator>,
pub(super) frontier: AstarAgenda,
}
impl SpanLazyFrontier {
pub(super) fn new() -> Self {
Self::default()
}
}
pub(super) struct LazyStringAstarSource<'a> {
pub(super) left_index: &'a SpanAstarLeftIndex,
pub(super) frontier: SpanLazyFrontier,
}
impl<'a> LazyStringAstarSource<'a> {
pub(super) fn new(left_index: &'a SpanAstarLeftIndex) -> Self {
Self {
left_index,
frontier: SpanLazyFrontier::new(),
}
}
}