use super::{
domain::{CanonicalPreimage, DomainDigest},
output::GroundTermDigest,
sink::PreimageSink,
};
use crate::{GroundAtom, GroundTerm};
impl GroundTerm {
#[must_use]
pub fn digest(&self) -> GroundTermDigest {
DomainDigest::digest(self)
}
}
impl DomainDigest for GroundTerm {
const DOMAIN: &'static str = "datalog-structural-model/ground-term-digest/v1";
type Output = GroundTermDigest;
}
impl CanonicalPreimage for GroundTerm {
fn write_preimage(&self, sink: &mut PreimageSink) {
match self {
Self::Constant(constant) => {
sink.tag(0);
constant.write_preimage(sink);
}
Self::TripleTerm(atom) => {
sink.tag(1);
atom.write_preimage(sink);
}
}
}
}
impl CanonicalPreimage for GroundAtom {
fn write_preimage(&self, sink: &mut PreimageSink) {
self.predicate.write_preimage(sink);
GroundTerm::write_sequence(&self.args, sink);
}
}