use std::{collections::BTreeMap, sync::Arc};
use super::{op::Uuf, term::Term, term_type::TermType};
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct Udf {
pub arg: TermType,
pub out: TermType,
pub table: Arc<BTreeMap<Term, Term>>,
pub default: Term,
}
impl Udf {
pub fn is_literal(&self) -> bool {
self.default.is_literal()
&& self
.table
.iter()
.all(|(k, v)| v.is_literal() && k.is_literal())
}
}
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub enum UnaryFunction {
Uuf(Arc<Uuf>),
Udf(Arc<Udf>),
}
impl UnaryFunction {
pub fn arg_type(&self) -> &TermType {
match self {
UnaryFunction::Uuf(f) => &f.arg,
UnaryFunction::Udf(f) => &f.arg,
}
}
pub fn out_type(&self) -> &TermType {
match self {
UnaryFunction::Uuf(f) => &f.out,
UnaryFunction::Udf(f) => &f.out,
}
}
pub fn is_literal(&self) -> bool {
match self {
UnaryFunction::Uuf(_) => false,
UnaryFunction::Udf(f) => f.is_literal(),
}
}
}