From 5e417395620f6d6ce45761d9ea72376c792ef60a Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 19 Sep 2012 16:35:28 -0700 Subject: [PATCH] Remove final bits of residual hokey-hash functions. Close #1616. --- src/libcore/core.rc | 8 +- src/libcore/hash.rs | 87 +++++-------------- src/libcore/int-template/int.rs | 6 -- src/libcore/str.rs | 5 -- src/libcore/uint-template/uint.rs | 5 -- src/libcore/vec.rs | 6 -- src/libstd/map.rs | 6 -- src/rustc/lib/llvm.rs | 2 - .../bench/task-perf-word-count-generic.rs | 16 +--- 9 files changed, 27 insertions(+), 114 deletions(-) diff --git a/src/libcore/core.rc b/src/libcore/core.rc index e732bcdb2fb..8566c5e1070 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -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"] diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 7446332e261..abc72ddfd31 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -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: Hash { } } -// implementations - pure fn hash_keyed_2(a: &A, b: &B, k0: u64, k1: u64) -> u64 { @@ -153,37 +137,6 @@ pure fn hash_keyed_5 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; diff --git a/src/libcore/int-template/int.rs b/src/libcore/int-template/int.rs index d990ba97afa..7e7cddf9b30 100644 --- a/src/libcore/int-template/int.rs +++ b/src/libcore/int-template/int.rs @@ -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] diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f6baeb91be9..4c01656ba2e 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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 */ diff --git a/src/libcore/uint-template/uint.rs b/src/libcore/uint-template/uint.rs index 8954e5c4a67..a02ce84052e 100644 --- a/src/libcore/uint-template/uint.rs +++ b/src/libcore/uint-template/uint.rs @@ -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 * diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 820e4df647a..c81baf52476 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -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. * diff --git a/src/libstd/map.rs b/src/libstd/map.rs index cdca0aae157..1784a2cac43 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -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)); diff --git a/src/rustc/lib/llvm.rs b/src/rustc/lib/llvm.rs index bd97c896a45..4ec6f36a8eb 100644 --- a/src/rustc/lib/llvm.rs +++ b/src/rustc/lib/llvm.rs @@ -1055,8 +1055,6 @@ fn name_has_type(tn: type_names, s: ~str) -> Option { } 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()} } diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index d1066869f33..606a5aa53b9 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -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 { emit_val(V), done, addref, release } - fn start_mappers( map: mapper, &ctrls: ~[ctrl_proto::server::open], @@ -169,7 +159,7 @@ mod map_reduce { return tasks; } - fn map_task( + fn map_task( map: mapper, ctrl: box>, input: K1) @@ -242,7 +232,7 @@ mod map_reduce { reduce(key, || get(p, ref_count, is_done) ); } - fn map_reduce( + fn map_reduce( map: mapper, reduce: reducer, inputs: ~[K1])