rust-lang / rust-lang/hashbrown

Explain Bitwise hack

Open
#322 2 comments 0 reactions 1 assignee View on GitHub

@ThatSealgair is already working on this.

Since Oct 3, 2022.

Dominant language
Rust
Stars
3k
Forks
358
Avg merge
11h 57m
Merged PRs (30d)
2

Description

It took me watching this part of a video and reading this article to figure out the bitwise operation is just acting as a pseudo modulus exploiting the fact that n % x = n & (x -1) where n = (2^i - 1) and i is a non-negative integer. Perhaps add a note for anybody else who finds themself in the same rabbit-hole to save them time.

https://github.com/rust-lang/hashbrown/blob/21bfd9aff79ebcfec29143a14b18d8c7bb2bac5c/src/raw/mod.rs#L1249

Contributor guide

No contributing guide indexed for this repository

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.