use std::ops::{Shl, Shr};
use bitflags::bitflags;
pub(crate) const EXPANDED: u64 = 0x0000_0000_0000_0001;
pub(crate) const MUTABLE: u64 = 0x0000_0000_0000_0002;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FstProperties: u64 {
const ACCEPTOR = 0x0000_0000_0001_0000;
const NOT_ACCEPTOR = 0x0000_0000_0002_0000;
const I_DETERMINISTIC = 0x0000_0000_0004_0000;
const NOT_I_DETERMINISTIC = 0x0000_0000_0008_0000;
const O_DETERMINISTIC = 0x0000_0000_0010_0000;
const NOT_O_DETERMINISTIC = 0x0000_0000_0020_0000;
const EPSILONS = 0x0000_0000_0040_0000;
const NO_EPSILONS = 0x0000_0000_0080_0000;
const I_EPSILONS = 0x0000_0000_0100_0000;
const NO_I_EPSILONS = 0x0000_0000_0200_0000;
const O_EPSILONS = 0x0000_0000_0400_0000;
const NO_O_EPSILONS = 0x0000_0000_0800_0000;
const I_LABEL_SORTED = 0x0000_0000_1000_0000;
const NOT_I_LABEL_SORTED = 0x0000_0000_2000_0000;
const O_LABEL_SORTED = 0x0000_0000_4000_0000;
const NOT_O_LABEL_SORTED = 0x0000_0000_8000_0000;
const WEIGHTED = 0x0000_0001_0000_0000;
const UNWEIGHTED = 0x0000_0002_0000_0000;
const CYCLIC = 0x0000_0004_0000_0000;
const ACYCLIC = 0x0000_0008_0000_0000;
const INITIAL_CYCLIC = 0x0000_0010_0000_0000;
const INITIAL_ACYCLIC = 0x0000_0020_0000_0000;
const TOP_SORTED = 0x0000_0040_0000_0000;
const NOT_TOP_SORTED = 0x0000_0080_0000_0000;
const ACCESSIBLE = 0x0000_0100_0000_0000;
const NOT_ACCESSIBLE = 0x0000_0200_0000_0000;
const COACCESSIBLE = 0x0000_0400_0000_0000;
const NOT_COACCESSIBLE = 0x0000_0800_0000_0000;
const STRING = 0x0000_1000_0000_0000;
const NOT_STRING = 0x0000_2000_0000_0000;
const WEIGHTED_CYCLES = 0x0000_4000_0000_0000;
const UNWEIGHTED_CYCLES = 0x0000_8000_0000_0000;
}
}
impl FstProperties {
pub(crate) fn null_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NO_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::UNWEIGHTED
| FstProperties::ACYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::STRING
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn copy_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::STRING
| FstProperties::NOT_STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn set_start_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn set_final_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn add_state_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::NOT_ACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::NOT_STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn add_arc_properties() -> FstProperties {
FstProperties::NOT_ACCEPTOR
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::CYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::WEIGHTED_CYCLES
}
pub(crate) fn set_arc_properties() -> FstProperties {
FstProperties::empty()
}
pub(crate) fn delete_states_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NO_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::UNWEIGHTED
| FstProperties::ACYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn delete_arcs_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NO_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::UNWEIGHTED
| FstProperties::ACYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_ACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn statesort_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn arcsort_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::STRING
| FstProperties::NOT_STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn i_label_invariant_properties() -> FstProperties {
FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::STRING
| FstProperties::NOT_STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn o_label_invariant_properties() -> FstProperties {
FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::STRING
| FstProperties::NOT_STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn weight_invariant_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::NO_EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::NOT_TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::STRING
| FstProperties::NOT_STRING
}
pub(crate) fn add_super_final_properties() -> FstProperties {
FstProperties::NOT_ACCEPTOR
| FstProperties::NOT_I_DETERMINISTIC
| FstProperties::NOT_O_DETERMINISTIC
| FstProperties::EPSILONS
| FstProperties::I_EPSILONS
| FstProperties::O_EPSILONS
| FstProperties::NOT_I_LABEL_SORTED
| FstProperties::NOT_O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::NOT_TOP_SORTED
| FstProperties::NOT_ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::NOT_STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn rm_super_final_properties() -> FstProperties {
FstProperties::ACCEPTOR
| FstProperties::NOT_ACCEPTOR
| FstProperties::I_DETERMINISTIC
| FstProperties::O_DETERMINISTIC
| FstProperties::NO_EPSILONS
| FstProperties::NO_I_EPSILONS
| FstProperties::NO_O_EPSILONS
| FstProperties::I_LABEL_SORTED
| FstProperties::O_LABEL_SORTED
| FstProperties::WEIGHTED
| FstProperties::UNWEIGHTED
| FstProperties::CYCLIC
| FstProperties::ACYCLIC
| FstProperties::INITIAL_CYCLIC
| FstProperties::INITIAL_ACYCLIC
| FstProperties::TOP_SORTED
| FstProperties::ACCESSIBLE
| FstProperties::COACCESSIBLE
| FstProperties::NOT_COACCESSIBLE
| FstProperties::STRING
| FstProperties::WEIGHTED_CYCLES
| FstProperties::UNWEIGHTED_CYCLES
}
pub(crate) fn binary_properties() -> FstProperties {
FstProperties::from_bits_truncate(0x0000_0000_0000_0007)
}
pub(crate) fn trinary_properties() -> FstProperties {
FstProperties::from_bits_truncate(0x0000_ffff_ffff_0000)
}
pub(crate) fn pos_trinary_properties() -> FstProperties {
FstProperties::trinary_properties()
& FstProperties::from_bits_truncate(0x5555_5555_5555_5555)
}
pub(crate) fn neg_trinary_properties() -> FstProperties {
FstProperties::trinary_properties()
& FstProperties::from_bits_truncate(0xaaaa_aaaa_aaaa_aaaa)
}
pub(crate) fn all_properties() -> FstProperties {
FstProperties::binary_properties() | FstProperties::trinary_properties()
}
}
impl Shl<usize> for FstProperties {
type Output = FstProperties;
fn shl(self, rhs: usize) -> Self::Output {
Self::from_bits_truncate(self.bits() << rhs)
}
}
impl Shr<usize> for FstProperties {
type Output = FstProperties;
fn shr(self, rhs: usize) -> Self::Output {
Self::from_bits_truncate(self.bits() >> rhs)
}
}