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

Assignment #9

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Assignment #9

wants to merge 2 commits into from

Conversation

shubham-kanodia
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@shubham-kanodia shubham-kanodia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment looks good. Left some feedback comment!

let mut hash = INITIAL_STATE;
let transformedu8 = u32_to_u8(num);
for i in 0 ..transformedu8.len() {
let product = (((hash * PRIME as u64)) % SIZE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also do something like this to avoid using u64 and mod operation

fn calculate_hash(num: u32) -> u32 {

    let mut hash: u32 = INITIAL_STATE as u32;
    let transformedu8 = u32_to_u8(num);
    for i in 0 ..transformedu8.len() {
        let product = hash * PRIME;
        hash = product ^ (transformedu8[i] as u32);
    }
    hash as u32
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants