stacks-network / stacks-network/stacks-core

[Chore] Add wrapper types for `hashbrown`'s `HashMap` and `HashSet`

Open
#4,441 1 comment 0 reactions 1 assignee View on GitHub

@cylewitruk is already working on this.

Since Feb 28, 2024.

chore Size: 🐭 XS (< 1 day) stale
Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

As mentioned in PR #4389, the introduction of the hashbrown crate isn't a 100% drop-in replacement when needing to satisfy some trait bounds.

This comes with its own challenges given that both the hashbrown types and the traits required are often implemented in external crates, i.e. we can't implement the traits directly on these types.

Introduce new types StacksHashSet and StacksHashMap in stacks-common which wrap the hashbrown implementations and allow the required traits to be implemented. These types can then be used as drop-in replacements for all instances of HashSet and HashMap (where we want to use hashbrown over std::collections), even in stackslib.

This approach also makes it easy for us to swap-out the implementation with other similarly-compatible types in the future, if we would wish to.

EDIT: After realizing that we may be able to revert to using std::collections::* and just swap out the hasher, this ticket becomes even more important to enable the easy swapping of HashMap/HashSet implementations without needing to change all of the trait implementations and use statements everywhere -- they can be isolated to the StacksHashMap and StacksHashSet wrapper types in stacks_common.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.