mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.
This commit is contained in:
parent
ff8cbff810
commit
95fc29fa0d
255 changed files with 3550 additions and 3362 deletions
|
@ -4,7 +4,8 @@
|
|||
|
||||
//! This file stolen wholesale from rustc/src/librustc/util/nodemap.rs
|
||||
|
||||
pub use std::hash::{Hash, Hasher, Writer};
|
||||
use std::default::Default;
|
||||
use std::hash::{Hasher, Writer};
|
||||
|
||||
/// A speedy hash algorithm for node ids and def ids. The hashmap in
|
||||
/// libcollections by default uses SipHash which isn't quite as speedy as we
|
||||
|
@ -13,33 +14,26 @@ pub use std::hash::{Hash, Hasher, Writer};
|
|||
///
|
||||
/// This uses FNV hashing, as described here:
|
||||
/// http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
#[deriving(Clone)]
|
||||
pub struct FnvHasher;
|
||||
#[allow(missing_copy_implementations)]
|
||||
pub struct FnvHasher(u64);
|
||||
|
||||
pub struct FnvState(u64);
|
||||
|
||||
impl Hasher<FnvState> for FnvHasher {
|
||||
fn hash<Sized? T: Hash<FnvState>>(&self, t: &T) -> u64 {
|
||||
let mut state = FnvState(0xcbf29ce484222325);
|
||||
t.hash(&mut state);
|
||||
let FnvState(ret) = state;
|
||||
return ret;
|
||||
}
|
||||
impl Default for FnvHasher {
|
||||
fn default() -> FnvHasher { FnvHasher(0xcbf29ce484222325) }
|
||||
}
|
||||
|
||||
impl Writer for FnvState {
|
||||
impl Hasher for FnvHasher {
|
||||
type Output = u64;
|
||||
fn reset(&mut self) { *self = Default::default(); }
|
||||
fn finish(&self) -> u64 { self.0 }
|
||||
}
|
||||
|
||||
impl Writer for FnvHasher {
|
||||
fn write(&mut self, bytes: &[u8]) {
|
||||
let FnvState(mut hash) = *self;
|
||||
let FnvHasher(mut hash) = *self;
|
||||
for byte in bytes.iter() {
|
||||
hash = hash ^ (*byte as u64);
|
||||
hash = hash * 0x100000001b3;
|
||||
}
|
||||
*self = FnvState(hash);
|
||||
*self = FnvHasher(hash);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn hash<T: Hash<FnvState>>(t: &T) -> u64 {
|
||||
let s = FnvHasher;
|
||||
s.hash(t)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue