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

Add HashMap collection #4241

Closed
NikitaMasych opened this issue Feb 2, 2024 · 0 comments · Fixed by #4242
Closed

Add HashMap collection #4241

NikitaMasych opened this issue Feb 2, 2024 · 0 comments · Fixed by #4242
Labels
enhancement New feature or request

Comments

@NikitaMasych
Copy link
Contributor

Problem

It is an essential attribute of each language to have an opportunity to utilize hash table for distinct purposes. Furthermore, it would be a valuable asset to have in ZK environment, considering integration boost with other protocols due to increased feasibility to implement state tries - latter as graphs, may be stored and operated efficiently in hash table form internally.

Happy Case

Basic trait declaring the set of essential operations may look the following way:

trait Map<K, V> {
    fn len(self) -> u64;
    fn get(self, key: K) -> Option<V>;
    fn insert(&mut self, key: K, value: V);
    fn remove(&mut self, key: K);
}

Alternatives Considered

No response

Additional Context

Since Noir is heavily inspired by Rust, in this contribution one port distinct hash-related traits, such as BuildHasher, Hasher and Hash to add flexibility in HashMap implementation.

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@NikitaMasych NikitaMasych added the enhancement New feature or request label Feb 2, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Feb 2, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 23, 2024
# Description

This PR shall bring HashMap into the `stdlib` of Noir.

## Problem\*

Resolves #4241

## Summary\*

Implementation of `HashMap` with open addressing and quadratic probing
scheme. Since Noir requires knowing loop bounds (and recursive calls) at
compile time, `HashMap` is of fixed capacity and **no** dynamic resize
is accomplished with regard to load factor.

Furthermore, contribution includes implementation of `PedersenHasher` to
be used for now. One can examine potentially better and less heavy
prehash functions.

I tried to conform with best practices of engineering, however since
Noir is in rapid development, there are certain things which may be
optimized in future, both from the code style and performance point of
view.


## Additional Context

I put the `PedersenHasher` among the `poseidon.nr` and `mimc.nr`, so one
can consider moving declaration of other pedersen-related functionality
there, however that would be a breaking change.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [x] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Feb 23, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 14, 2024
# Description

## Problem\*

Resolves a TODO in #4241 

## Summary\*

Adds the remaining Hash impls for primitive types in the stdlib

## Additional Context

I've marked this as "no documentation needed" but we should probably
document somewhere that these types are hashable. Where should this go?
The existing "hash methods" page doesn't seem to fit.

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
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
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant