I want to ask an algorithm question

Can design a hash function so that

hash(77)=0
hash(55)=2


I haven't figured it out yet

How about this?

fn hash(value: u32) -> u32 {
    if value == 77 {
        0
    } else {
        2
    }
}

If this isn't what you are looking for, then your question needs more details.

7 Likes

Seems to be looking for a rule, Different subscripts correspond to the values of different keys above

I would suspect it's something involving "modulo 11" but where 1 isn't a possible result. I.e. we search a function that is returning one of 10 values (0, 2, 3, 4, 5, 6, 7, 8, 9, 10). The inputs given as example are the ones in the line that starts with "K".


But no idea really. @jameszow, this really needs more context to answer properly. I also don't think it's Rust related? More a generic math problem.


In the picture, I see "modulo 12" actually.

1 Like

Maybe: Lagrange polynomial - Wikipedia

1 Like

Thanks it’s math problem

Thanks let me see

I wonder if you're looking for a Perfect Hash?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.