Skip to content

BigInt and BigUint should implement Hash #16551

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

Closed
vks opened this issue Aug 17, 2014 · 2 comments · Fixed by #16558
Closed

BigInt and BigUint should implement Hash #16551

vks opened this issue Aug 17, 2014 · 2 comments · Fixed by #16558

Comments

@vks
Copy link
Contributor

vks commented Aug 17, 2014

Something along the lines of

impl<H: std::hash::Writer> std::hash::Hash<H> for BigInt {
    #[inline]
    fn hash(&self, hasher: &mut H) {
        self.data.as_slice().hash(hasher)
    }
}

should work.

@Gankra
Copy link
Contributor

Gankra commented Aug 17, 2014

#[deriving(Hash)] should be sufficient in this case, I think.

@Gankra
Copy link
Contributor

Gankra commented Aug 17, 2014

Hmm, nope, neither of our solutions are sufficient. Presumably 100 should hash to the same as 000100, but that doesn't hold if you naively hash the whole Vec. Need to truncate blocks that are all 0's at the end of the slice.

Gankra added a commit to Gankra/rust that referenced this issue Aug 17, 2014
bors added a commit that referenced this issue Aug 17, 2014
Pretty self-explanatory. Only annoying thing is that it *seems* that I had to add `#![feature(default_type_params)]` to libnum because of Hasher. Don't know if there's a way around that.

Fix #16551
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 a pull request may close this issue.

2 participants