luiswirth/lifeash

use hashset instead of hashmap and &Node instead of Id

Opened this issue · 2 comments

The current implementation of hasherlife uses IDs as handles to the actual Nodes in the HashMap<ID, Node>. Instead it would be sufficient to use references (&Node) into a HashSet<Node>.

The largest problem with this refactoring lies in satisfying the borrowck because there are a lot of lifetimes involved. I'm not sure if it is even feasible to do a trivial refactoring or if it's necessary to use different data structures altogether. Maybe there is unsafe code necessary.

Another problem is the immutability of the hashset entries. We need a different way to memoize the computed Inode::result because we can't mutate the Nodes.

I'm not quite sure but I think we just need to store Refcell<Node> instead of &Node in the structs to eliminate lifetime problems.

Here are some references or ideas, which might help in solving this problem:

For now we should probably switch to bimap because we map in both directions.