Remove final bits of residual hokey-hash functions. Close #1616.

This commit is contained in:
Graydon Hoare 2012-09-19 16:35:28 -07:00
parent 10e760efc8
commit 5e41739562
9 changed files with 27 additions and 114 deletions

View File

@ -80,8 +80,8 @@ export private;
/// Operations and constants for `int`
#[path = "int-template"]
mod int {
use inst::{ hash, pow };
export hash, pow;
use inst::{ pow };
export pow;
#[path = "int.rs"]
mod inst;
}
@ -118,10 +118,10 @@ mod i64 {
#[path = "uint-template"]
mod uint {
use inst::{
div_ceil, div_round, div_floor, hash, iterate,
div_ceil, div_round, div_floor, iterate,
next_power_of_two
};
export div_ceil, div_round, div_floor, hash, iterate,
export div_ceil, div_round, div_floor, iterate,
next_power_of_two;
#[path = "uint.rs"]

View File

@ -19,20 +19,6 @@ use to_bytes::IterBytes;
export Streaming, State, Hash, HashUtil;
export default_state;
export hash_bytes_keyed;
export hash_str_keyed;
export hash_u64_keyed;
export hash_u32_keyed;
export hash_u16_keyed;
export hash_u8_keyed;
export hash_uint_keyed;
export hash_bytes;
export hash_str;
export hash_u64;
export hash_u32;
export hash_u16;
export hash_u8;
export hash_uint;
/**
* Types that can meaningfully be hashed should implement this.
@ -95,8 +81,6 @@ impl <A: IterBytes> A: Hash {
}
}
// implementations
pure fn hash_keyed_2<A: IterBytes,
B: IterBytes>(a: &A, b: &B,
k0: u64, k1: u64) -> u64 {
@ -153,37 +137,6 @@ pure fn hash_keyed_5<A: IterBytes,
}
}
pure fn hash_bytes_keyed(val: &[u8], k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_str_keyed(val: &str, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_u64_keyed(val: u64, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_u32_keyed(val: u32, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_u16_keyed(val: u16, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_u8_keyed(val: u8, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_uint_keyed(val: uint, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_bytes(val: &[u8]) -> u64 { hash_bytes_keyed(val, 0, 0) }
pure fn hash_str(val: &str) -> u64 { hash_str_keyed(val, 0, 0) }
pure fn hash_u64(val: u64) -> u64 { hash_u64_keyed(val, 0, 0) }
pure fn hash_u32(val: u32) -> u64 { hash_u32_keyed(val, 0, 0) }
pure fn hash_u16(val: u16) -> u64 { hash_u16_keyed(val, 0, 0) }
pure fn hash_u8(val: u8) -> u64 { hash_u8_keyed(val, 0, 0) }
pure fn hash_uint(val: uint) -> u64 { hash_uint_keyed(val, 0, 0) }
// Implement State as SipState
type State = SipState;
@ -517,42 +470,42 @@ fn test_siphash() {
#[test] #[cfg(target_arch = "arm")]
fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
assert hash_u64(val as u64) == hash_uint(val as uint);
assert hash_u32(val as u32) != hash_uint(val as uint);
assert (val as u64).hash() != (val as uint).hash();
assert (val as u32).hash() == (val as uint).hash();
}
#[test] #[cfg(target_arch = "x86_64")]
fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
assert hash_u64(val as u64) == hash_uint(val as uint);
assert hash_u32(val as u32) != hash_uint(val as uint);
assert (val as u64).hash() == (val as uint).hash();
assert (val as u32).hash() != (val as uint).hash();
}
#[test] #[cfg(target_arch = "x86")]
fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
assert hash_u64(val as u64) != hash_uint(val as uint);
assert hash_u32(val as u32) == hash_uint(val as uint);
assert (val as u64).hash() != (val as uint).hash();
assert (val as u32).hash() == (val as uint).hash();
}
#[test]
fn test_hash_idempotent() {
let val64 = 0xdeadbeef_deadbeef_u64;
assert hash_u64(val64) == hash_u64(val64);
val64.hash() == val64.hash();
let val32 = 0xdeadbeef_u32;
assert hash_u32(val32) == hash_u32(val32);
val32.hash() == val32.hash();
}
#[test]
fn test_hash_no_bytes_dropped_64() {
let val = 0xdeadbeef_deadbeef_u64;
assert hash_u64(val) != hash_u64(zero_byte(val, 0));
assert hash_u64(val) != hash_u64(zero_byte(val, 1));
assert hash_u64(val) != hash_u64(zero_byte(val, 2));
assert hash_u64(val) != hash_u64(zero_byte(val, 3));
assert hash_u64(val) != hash_u64(zero_byte(val, 4));
assert hash_u64(val) != hash_u64(zero_byte(val, 5));
assert hash_u64(val) != hash_u64(zero_byte(val, 6));
assert hash_u64(val) != hash_u64(zero_byte(val, 7));
assert val.hash() != zero_byte(val, 0).hash();
assert val.hash() != zero_byte(val, 1).hash();
assert val.hash() != zero_byte(val, 2).hash();
assert val.hash() != zero_byte(val, 3).hash();
assert val.hash() != zero_byte(val, 4).hash();
assert val.hash() != zero_byte(val, 5).hash();
assert val.hash() != zero_byte(val, 6).hash();
assert val.hash() != zero_byte(val, 7).hash();
fn zero_byte(val: u64, byte: uint) -> u64 {
assert 0 <= byte; assert byte < 8;
@ -564,10 +517,10 @@ fn test_hash_no_bytes_dropped_64() {
fn test_hash_no_bytes_dropped_32() {
let val = 0xdeadbeef_u32;
assert hash_u32(val) != hash_u32(zero_byte(val, 0));
assert hash_u32(val) != hash_u32(zero_byte(val, 1));
assert hash_u32(val) != hash_u32(zero_byte(val, 2));
assert hash_u32(val) != hash_u32(zero_byte(val, 3));
assert val.hash() != zero_byte(val, 0).hash();
assert val.hash() != zero_byte(val, 1).hash();
assert val.hash() != zero_byte(val, 2).hash();
assert val.hash() != zero_byte(val, 3).hash();
fn zero_byte(val: u32, byte: uint) -> u32 {
assert 0 <= byte; assert byte < 4;

View File

@ -1,12 +1,6 @@
type T = int;
const bits: uint = uint::bits;
/// Produce a uint suitable for use in a hash table
pure fn hash(x: int) -> uint {
let u : uint = x as uint;
uint::hash(u)
}
/// Returns `base` raised to the power of `exponent`
fn pow(base: int, exponent: uint) -> int {
if exponent == 0u { return 1; } //Not mathemtically true if ~[base == 0]

View File

@ -853,11 +853,6 @@ impl @str : Ord {
pure fn gt(&&other: @str) -> bool { gt(self, other) }
}
/// String hash function
pure fn hash(s: &~str) -> uint {
hash::hash_str(*s) as uint
}
/*
Section: Iterating through strings
*/

View File

@ -60,11 +60,6 @@ pure fn div_round(x: uint, y: uint) -> uint {
*/
pure fn div_floor(x: uint, y: uint) -> uint { return x / y; }
/// Produce a uint suitable for use in a hash table
pure fn hash(x: uint) -> uint {
hash::hash_uint(x) as uint
}
/**
* Iterate over the range [`lo`..`hi`), or stop when requested
*

View File

@ -1799,7 +1799,6 @@ mod raw {
mod bytes {
export cmp;
export lt, le, eq, ne, ge, gt;
export hash;
export memcpy, memmove;
/// Bytewise string comparison
@ -1841,11 +1840,6 @@ mod bytes {
/// Bytewise greater than
pure fn gt(a: &~[u8], b: &~[u8]) -> bool { cmp(a, b) > 0 }
/// Byte-vec hash function
pure fn hash(s: &~[u8]) -> uint {
hash::hash_bytes(*s) as uint
}
/**
* Copies data from one vector to another.
*

View File

@ -658,12 +658,6 @@ mod tests {
fn test_removal() {
debug!("*** starting test_removal");
let num_to_insert: uint = 64u;
fn eq(x: &uint, y: &uint) -> bool { *x == *y }
fn hash(u: &uint) -> uint {
// This hash function intentionally causes collisions between
// consecutive integer pairs.
*u / 2u * 2u
}
assert (hash(&0u) == hash(&1u));
assert (hash(&2u) == hash(&3u));
assert (hash(&0u) != hash(&2u));

View File

@ -1055,8 +1055,6 @@ fn name_has_type(tn: type_names, s: ~str) -> Option<TypeRef> {
}
fn mk_type_names() -> type_names {
pure fn hash(t: &TypeRef) -> uint { *t as uint }
pure fn eq(a: &TypeRef, b: &TypeRef) -> bool { *a == *b }
@{type_names: std::map::HashMap(),
named_types: std::map::HashMap()}
}

View File

@ -39,16 +39,6 @@ trait word_reader {
fn read_word() -> Option<~str>;
}
trait hash_key {
pure fn hash() -> uint;
pure fn eq(&&k: self) -> bool;
}
impl ~str: hash_key {
pure fn hash() -> uint { str::hash(&self) }
pure fn eq(&&x: ~str) -> bool { self == x }
}
// These used to be in task, but they disappeard.
type joinable_task = Port<()>;
fn spawn_joinable(+f: fn~()) -> joinable_task {
@ -152,7 +142,7 @@ mod map_reduce {
enum reduce_proto<V: Copy Send> { emit_val(V), done, addref, release }
fn start_mappers<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send hash_key,
fn start_mappers<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send,
V: Copy Send>(
map: mapper<K1, K2, V>,
&ctrls: ~[ctrl_proto::server::open<K2, V>],
@ -169,7 +159,7 @@ mod map_reduce {
return tasks;
}
fn map_task<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send hash_key, V: Copy Send>(
fn map_task<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send, V: Copy Send>(
map: mapper<K1, K2, V>,
ctrl: box<ctrl_proto::client::open<K2, V>>,
input: K1)
@ -242,7 +232,7 @@ mod map_reduce {
reduce(key, || get(p, ref_count, is_done) );
}
fn map_reduce<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send hash_key, V: Copy Send>(
fn map_reduce<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send, V: Copy Send>(
map: mapper<K1, K2, V>,
reduce: reducer<K2, V>,
inputs: ~[K1])