harn-vm 0.10.127

Async bytecode virtual machine for the Harn programming language
Documentation
pub(in crate::llm) fn stable_hash(val: &serde_json::Value) -> u64 {
    use std::hash::{Hash, Hasher};
    let mut hasher = std::collections::hash_map::DefaultHasher::new();
    // Keep the historical String hash domain while making object order
    // independent of the caller's JSON representation.
    let canonical = crate::canonical_json::to_string(val);
    canonical.hash(&mut hasher);
    hasher.finish()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn stable_hash_ignores_object_key_order() {
        let first: serde_json::Value = serde_json::from_str(r#"{"zeta":1,"alpha":2}"#).unwrap();
        let second: serde_json::Value = serde_json::from_str(r#"{"alpha":2,"zeta":1}"#).unwrap();

        assert_eq!(stable_hash(&first), stable_hash(&second));
    }
}