luiswirth / lifeash

A Hashlife (Gosper's algorithm) implementation written in Rust
MIT License
4 stars 1 forks source link

use hashset instead of hashmap and &Node instead of Id #2

Open luiswirth opened 4 years ago

luiswirth commented 4 years ago

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.

luiswirth commented 4 years ago

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:

luiswirth commented 4 years ago

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