@@ -1,4 +1,6 @@
2+ borrow::{Borrow, BorrowMut},
2 cmp::{self, Ordering},
4 cmp::{self, Ordering},
4 str::FromStr,
6 str::FromStr,
@@ -18,7 +20,7 @@ pub enum Noun {
19 p: Rc<Noun>,
21 p: Rc<Noun>,
20 q: Rc<Noun>,
22 q: Rc<Noun>,
21− hash: Hash,
23+ hash: Cell<Option<Hash>>,
@@ -151,7 +153,14 @@ impl Noun {
152 pub fn hash(self: &Self) -> Hash {
154 pub fn hash(self: &Self) -> Hash {
153 match self {
155 match self {
154− Noun::Cell { hash, .. } => *hash,
156+ Noun::Cell { hash, p, q } => match hash.get() {
157+ Some(x) => x.clone(),
159+ let hash_value = hash_pair(p.clone(), q.clone());
160+ hash.replace(Some(hash_value));
155 Noun::Atom(a) => xxh3_128(&*a.to_bytes_le()),
164 Noun::Atom(a) => xxh3_128(&*a.to_bytes_le()),
@@ -348,7 +357,7 @@ pub fn cell(p: Rc<Noun>, q: Rc<Noun>) -> Rc<Noun> {
348 Rc::new(Noun::Cell {
357 Rc::new(Noun::Cell {
349 p: p.clone(),
358 p: p.clone(),
350 q: q.clone(),
359 q: q.clone(),
351− hash: hash_pair(p, q),
360+ hash: Cell::new(None),