Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor lookup logic #11

Open
frisitano opened this issue Feb 26, 2023 · 0 comments · May be fixed by #18
Open

Refactor lookup logic #11

frisitano opened this issue Feb 26, 2023 · 0 comments · May be fixed by #18
Assignees
Labels
enhancement New feature or request

Comments

@frisitano
Copy link
Owner

frisitano commented Feb 26, 2023

The lookup logic heavily overlaps between both TreeDB and TreeDBMut, specifically lookup(..) and lookup_leaf_node(..) methods. We should extract the logic to a separate module such that the logic can be shared. In the module we should create a struct that implements both these methods. The struct should look something like:

pub struct Lookup<'db, const D: usize, H: Hasher> {
    storage: NodeStorage<H>,
    db: &'db mut dyn HashDB<H, DBValue>,
    root: NodeHash<H>,
    null_nodes: HashMap<H::Out, Node<H>>,
    recorder: Option<core::cell::RefCell<&'db mut dyn TreeRecorder<H>>>,
}

We should then modify both TreeDB and TreeDBMut to leverage the methods exposed from this struct.

It may be useful to implement the From trait on TreeDB and TreeDBMut for Lookup such that we can easily construct a Lookup struct using Lookup::from(..) when doing lookups.

@fizikarubi fizikarubi linked a pull request Feb 28, 2023 that will close this issue
@frisitano frisitano added the enhancement New feature or request label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants