//! pattern 15: hash โ€” structural hash via H (dispatched by hash function)
//! returns hash noun: cell(cell(h0,h1), cell(h2,h3))

use crate::noun::{Order, NounId};
use crate::reduce::{Outcome, ErrorKind, evaluate};
use crate::call::CallProvider;

pub fn hash<const N: usize>(
    order: &mut Order<N>, object: NounId, body: NounId, budget: u64, hints: &dyn CallProvider<N>,
) -> Outcome {
    let (input, budget) = match evaluate(order, object, body, budget, hints) { Ok(v) => v, Err(o) => return o };
    let digest = *order.digest(input);
    match order.hash_noun(&digest) {
        Some(r) => Outcome::Ok(r, budget),
        None => Outcome::Error(ErrorKind::Unavailable),
    }
}

Dimensions

trident/src/cli/hash.rs
nox/rs/noun/hash.rs
hemera/bench/benches/hash.rs

Local Graph