Update some comments about StableHasher.
This commit is contained in:
parent
89909c76a3
commit
54818b3e99
1 changed files with 6 additions and 20 deletions
|
@ -13,24 +13,13 @@ use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use sip128::SipHasher128;
|
use sip128::SipHasher128;
|
||||||
|
|
||||||
/// When hashing something that ends up affecting properties like symbol names. We
|
/// When hashing something that ends up affecting properties like symbol names,
|
||||||
/// want these symbol names to be calculated independent of other factors like
|
/// we want these symbol names to be calculated independently of other factors
|
||||||
/// what architecture you're compiling *from*.
|
/// like what architecture you're compiling *from*.
|
||||||
///
|
///
|
||||||
/// The hashing just uses the standard `Hash` trait, but the implementations of
|
/// To that end we always convert integers to little-endian format before
|
||||||
/// `Hash` for the `usize` and `isize` types are *not* architecture independent
|
/// hashing and the architecture dependent `isize` and `usize` types are
|
||||||
/// (e.g. they has 4 or 8 bytes). As a result we want to avoid `usize` and
|
/// extended to 64 bits if needed.
|
||||||
/// `isize` completely when hashing.
|
|
||||||
///
|
|
||||||
/// To do that, we encode all integers to be hashed with some
|
|
||||||
/// arch-independent encoding.
|
|
||||||
///
|
|
||||||
/// At the moment, we pass i8/u8 straight through and encode
|
|
||||||
/// all other integers using leb128.
|
|
||||||
///
|
|
||||||
/// This hasher currently always uses the stable Blake2b algorithm
|
|
||||||
/// and allows for variable output lengths through its type
|
|
||||||
/// parameter.
|
|
||||||
pub struct StableHasher<W> {
|
pub struct StableHasher<W> {
|
||||||
state: SipHasher128,
|
state: SipHasher128,
|
||||||
bytes_hashed: u64,
|
bytes_hashed: u64,
|
||||||
|
@ -86,9 +75,6 @@ impl<W> StableHasher<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For the non-u8 integer cases we leb128 encode them first. Because small
|
|
||||||
// integers dominate, this significantly and cheaply reduces the number of
|
|
||||||
// bytes hashed, which is good because blake2b is expensive.
|
|
||||||
impl<W> Hasher for StableHasher<W> {
|
impl<W> Hasher for StableHasher<W> {
|
||||||
fn finish(&self) -> u64 {
|
fn finish(&self) -> u64 {
|
||||||
panic!("use StableHasher::finalize instead");
|
panic!("use StableHasher::finalize instead");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue