datalog_structural_model/digest/
ground_preimage.rs1use super::{
4 domain::{CanonicalPreimage, DomainDigest},
5 output::GroundTermDigest,
6 sink::PreimageSink,
7};
8use crate::{GroundAtom, GroundTerm};
9
10impl GroundTerm {
11 #[must_use]
19 pub fn digest(&self) -> GroundTermDigest {
20 DomainDigest::digest(self)
21 }
22}
23
24impl DomainDigest for GroundTerm {
25 const DOMAIN: &'static str = "datalog-structural-model/ground-term-digest/v1";
26 type Output = GroundTermDigest;
27}
28
29impl CanonicalPreimage for GroundTerm {
30 fn write_preimage(&self, sink: &mut PreimageSink) {
31 match self {
32 Self::Constant(constant) => {
33 sink.tag(0);
34 constant.write_preimage(sink);
35 }
36 Self::TripleTerm(atom) => {
37 sink.tag(1);
38 atom.write_preimage(sink);
39 }
40 }
41 }
42}
43
44impl CanonicalPreimage for GroundAtom {
45 fn write_preimage(&self, sink: &mut PreimageSink) {
46 self.predicate.write_preimage(sink);
47 GroundTerm::write_sequence(&self.args, sink);
48 }
49}