Is there a Lazy HashTable

I am solving AoC 2015 and I came across this task: Day 7 - Advent of Code 2015

After implementing token parsing and evaluation I realized that the these operations are not in order. It looks like I need something like a lazy hashtable. Here's what I mean:

--- FIND `b`:---

/* (`->` means "assign to") 
!a -> b
table[b] = !table[a] // table[a] isn't defined yet
c || d -> e
table[e] = table[c] & table[d]
e << 2 -> a
table[a] = table[e] << 2
10 -> e
table[e] = 10 // now since table[e] is defined, I can find table[a] and thus the value of b

If I use a HashTable<&str, i32>, it'll immidiately complain that the value of table[a] wasn't defined yet. If I use a HashTable<&str, Option<i32>> and None, when I change the value of e , the HashTable should transitively change the value of a thus b.

How should I approach this?

I would figure out which wires depend on which and then do a topological sort. If you compute them in that order, this guarantees that no wire changes after you have computed its value.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.