diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-09-19 16:35:28 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-09-19 16:35:53 -0700 |
| commit | 5e417395620f6d6ce45761d9ea72376c792ef60a (patch) | |
| tree | 70df9a87a0ab61f5b8b55e9bd5d50be5077fe9ba /src/libcore | |
| parent | 10e760efc8c99e15c50b925a48f7df4fdd704a48 (diff) | |
Remove final bits of residual hokey-hash functions. Close #1616.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/core.rc | 8 | ||||
| -rw-r--r-- | src/libcore/hash.rs | 87 | ||||
| -rw-r--r-- | src/libcore/int-template/int.rs | 6 | ||||
| -rw-r--r-- | src/libcore/str.rs | 5 | ||||
| -rw-r--r-- | src/libcore/uint-template/uint.rs | 5 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 6 |
6 files changed, 24 insertions, 93 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: 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; 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. * |
