forked from rust-phf/rust-phf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements @glennw's PR rust-phf#5 to move the hashing code used by both phf and phf_mac into a module imported by both crates. It breaks the hard dependency of phf_mac on phf, which means phf doesn't have to be compiled for the host architecture as well as the target. It also means we can have a dev-dependency from phf to phf_mac for tests.
- Loading branch information
Showing
6 changed files
with
49 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,3 @@ version = "0.0.0" | |
name = "phf_mac" | ||
path = "src/lib.rs" | ||
plugin = true | ||
|
||
[dependencies.phf] | ||
|
||
path = "../phf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::hash::{Hash, Hasher}; | ||
use std::hash::sip::SipHasher; | ||
|
||
static LOG_MAX_SIZE: uint = 21; | ||
|
||
pub static MAX_SIZE: uint = 1 << LOG_MAX_SIZE; | ||
|
||
pub fn hash<T: Hash>(s: &T, k1: u64, k2: u64) -> (uint, uint, uint) { | ||
let hash = SipHasher::new_with_keys(k1, k2).hash(s); | ||
let mask = (MAX_SIZE - 1) as u64; | ||
|
||
((hash & mask) as uint, | ||
((hash >> LOG_MAX_SIZE) & mask) as uint, | ||
((hash >> (2 * LOG_MAX_SIZE)) & mask) as uint) | ||
} | ||
|
||
pub fn displace(f1: uint, f2: uint, d1: uint, d2: uint) -> uint { | ||
d2 + f1 * d1 + f2 | ||
} |