Skip to content

Commit 5e41739

Browse files
committed
Remove final bits of residual hokey-hash functions. Close #1616.
1 parent 10e760e commit 5e41739

File tree

9 files changed

+27
-114
lines changed

9 files changed

+27
-114
lines changed

src/libcore/core.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export private;
8080
/// Operations and constants for `int`
8181
#[path = "int-template"]
8282
mod int {
83-
use inst::{ hash, pow };
84-
export hash, pow;
83+
use inst::{ pow };
84+
export pow;
8585
#[path = "int.rs"]
8686
mod inst;
8787
}
@@ -118,10 +118,10 @@ mod i64 {
118118
#[path = "uint-template"]
119119
mod uint {
120120
use inst::{
121-
div_ceil, div_round, div_floor, hash, iterate,
121+
div_ceil, div_round, div_floor, iterate,
122122
next_power_of_two
123123
};
124-
export div_ceil, div_round, div_floor, hash, iterate,
124+
export div_ceil, div_round, div_floor, iterate,
125125
next_power_of_two;
126126

127127
#[path = "uint.rs"]

src/libcore/hash.rs

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ use to_bytes::IterBytes;
1919

2020
export Streaming, State, Hash, HashUtil;
2121
export default_state;
22-
export hash_bytes_keyed;
23-
export hash_str_keyed;
24-
export hash_u64_keyed;
25-
export hash_u32_keyed;
26-
export hash_u16_keyed;
27-
export hash_u8_keyed;
28-
export hash_uint_keyed;
29-
export hash_bytes;
30-
export hash_str;
31-
export hash_u64;
32-
export hash_u32;
33-
export hash_u16;
34-
export hash_u8;
35-
export hash_uint;
3622

3723
/**
3824
* Types that can meaningfully be hashed should implement this.
@@ -95,8 +81,6 @@ impl <A: IterBytes> A: Hash {
9581
}
9682
}
9783

98-
// implementations
99-
10084
pure fn hash_keyed_2<A: IterBytes,
10185
B: IterBytes>(a: &A, b: &B,
10286
k0: u64, k1: u64) -> u64 {
@@ -153,37 +137,6 @@ pure fn hash_keyed_5<A: IterBytes,
153137
}
154138
}
155139

156-
pure fn hash_bytes_keyed(val: &[u8], k0: u64, k1: u64) -> u64 {
157-
val.hash_keyed(k0, k1)
158-
}
159-
pure fn hash_str_keyed(val: &str, k0: u64, k1: u64) -> u64 {
160-
val.hash_keyed(k0, k1)
161-
}
162-
pure fn hash_u64_keyed(val: u64, k0: u64, k1: u64) -> u64 {
163-
val.hash_keyed(k0, k1)
164-
}
165-
pure fn hash_u32_keyed(val: u32, k0: u64, k1: u64) -> u64 {
166-
val.hash_keyed(k0, k1)
167-
}
168-
pure fn hash_u16_keyed(val: u16, k0: u64, k1: u64) -> u64 {
169-
val.hash_keyed(k0, k1)
170-
}
171-
pure fn hash_u8_keyed(val: u8, k0: u64, k1: u64) -> u64 {
172-
val.hash_keyed(k0, k1)
173-
}
174-
pure fn hash_uint_keyed(val: uint, k0: u64, k1: u64) -> u64 {
175-
val.hash_keyed(k0, k1)
176-
}
177-
178-
pure fn hash_bytes(val: &[u8]) -> u64 { hash_bytes_keyed(val, 0, 0) }
179-
pure fn hash_str(val: &str) -> u64 { hash_str_keyed(val, 0, 0) }
180-
pure fn hash_u64(val: u64) -> u64 { hash_u64_keyed(val, 0, 0) }
181-
pure fn hash_u32(val: u32) -> u64 { hash_u32_keyed(val, 0, 0) }
182-
pure fn hash_u16(val: u16) -> u64 { hash_u16_keyed(val, 0, 0) }
183-
pure fn hash_u8(val: u8) -> u64 { hash_u8_keyed(val, 0, 0) }
184-
pure fn hash_uint(val: uint) -> u64 { hash_uint_keyed(val, 0, 0) }
185-
186-
187140
// Implement State as SipState
188141

189142
type State = SipState;
@@ -517,42 +470,42 @@ fn test_siphash() {
517470
#[test] #[cfg(target_arch = "arm")]
518471
fn test_hash_uint() {
519472
let val = 0xdeadbeef_deadbeef_u64;
520-
assert hash_u64(val as u64) == hash_uint(val as uint);
521-
assert hash_u32(val as u32) != hash_uint(val as uint);
473+
assert (val as u64).hash() != (val as uint).hash();
474+
assert (val as u32).hash() == (val as uint).hash();
522475
}
523476
#[test] #[cfg(target_arch = "x86_64")]
524477
fn test_hash_uint() {
525478
let val = 0xdeadbeef_deadbeef_u64;
526-
assert hash_u64(val as u64) == hash_uint(val as uint);
527-
assert hash_u32(val as u32) != hash_uint(val as uint);
479+
assert (val as u64).hash() == (val as uint).hash();
480+
assert (val as u32).hash() != (val as uint).hash();
528481
}
529482
#[test] #[cfg(target_arch = "x86")]
530483
fn test_hash_uint() {
531484
let val = 0xdeadbeef_deadbeef_u64;
532-
assert hash_u64(val as u64) != hash_uint(val as uint);
533-
assert hash_u32(val as u32) == hash_uint(val as uint);
485+
assert (val as u64).hash() != (val as uint).hash();
486+
assert (val as u32).hash() == (val as uint).hash();
534487
}
535488

536489
#[test]
537490
fn test_hash_idempotent() {
538491
let val64 = 0xdeadbeef_deadbeef_u64;
539-
assert hash_u64(val64) == hash_u64(val64);
492+
val64.hash() == val64.hash();
540493
let val32 = 0xdeadbeef_u32;
541-
assert hash_u32(val32) == hash_u32(val32);
494+
val32.hash() == val32.hash();
542495
}
543496

544497
#[test]
545498
fn test_hash_no_bytes_dropped_64() {
546499
let val = 0xdeadbeef_deadbeef_u64;
547500

548-
assert hash_u64(val) != hash_u64(zero_byte(val, 0));
549-
assert hash_u64(val) != hash_u64(zero_byte(val, 1));
550-
assert hash_u64(val) != hash_u64(zero_byte(val, 2));
551-
assert hash_u64(val) != hash_u64(zero_byte(val, 3));
552-
assert hash_u64(val) != hash_u64(zero_byte(val, 4));
553-
assert hash_u64(val) != hash_u64(zero_byte(val, 5));
554-
assert hash_u64(val) != hash_u64(zero_byte(val, 6));
555-
assert hash_u64(val) != hash_u64(zero_byte(val, 7));
501+
assert val.hash() != zero_byte(val, 0).hash();
502+
assert val.hash() != zero_byte(val, 1).hash();
503+
assert val.hash() != zero_byte(val, 2).hash();
504+
assert val.hash() != zero_byte(val, 3).hash();
505+
assert val.hash() != zero_byte(val, 4).hash();
506+
assert val.hash() != zero_byte(val, 5).hash();
507+
assert val.hash() != zero_byte(val, 6).hash();
508+
assert val.hash() != zero_byte(val, 7).hash();
556509

557510
fn zero_byte(val: u64, byte: uint) -> u64 {
558511
assert 0 <= byte; assert byte < 8;
@@ -564,10 +517,10 @@ fn test_hash_no_bytes_dropped_64() {
564517
fn test_hash_no_bytes_dropped_32() {
565518
let val = 0xdeadbeef_u32;
566519

567-
assert hash_u32(val) != hash_u32(zero_byte(val, 0));
568-
assert hash_u32(val) != hash_u32(zero_byte(val, 1));
569-
assert hash_u32(val) != hash_u32(zero_byte(val, 2));
570-
assert hash_u32(val) != hash_u32(zero_byte(val, 3));
520+
assert val.hash() != zero_byte(val, 0).hash();
521+
assert val.hash() != zero_byte(val, 1).hash();
522+
assert val.hash() != zero_byte(val, 2).hash();
523+
assert val.hash() != zero_byte(val, 3).hash();
571524

572525
fn zero_byte(val: u32, byte: uint) -> u32 {
573526
assert 0 <= byte; assert byte < 4;

src/libcore/int-template/int.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
type T = int;
22
const bits: uint = uint::bits;
33

4-
/// Produce a uint suitable for use in a hash table
5-
pure fn hash(x: int) -> uint {
6-
let u : uint = x as uint;
7-
uint::hash(u)
8-
}
9-
104
/// Returns `base` raised to the power of `exponent`
115
fn pow(base: int, exponent: uint) -> int {
126
if exponent == 0u { return 1; } //Not mathemtically true if ~[base == 0]

src/libcore/str.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,11 +853,6 @@ impl @str : Ord {
853853
pure fn gt(&&other: @str) -> bool { gt(self, other) }
854854
}
855855

856-
/// String hash function
857-
pure fn hash(s: &~str) -> uint {
858-
hash::hash_str(*s) as uint
859-
}
860-
861856
/*
862857
Section: Iterating through strings
863858
*/

src/libcore/uint-template/uint.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ pure fn div_round(x: uint, y: uint) -> uint {
6060
*/
6161
pure fn div_floor(x: uint, y: uint) -> uint { return x / y; }
6262

63-
/// Produce a uint suitable for use in a hash table
64-
pure fn hash(x: uint) -> uint {
65-
hash::hash_uint(x) as uint
66-
}
67-
6863
/**
6964
* Iterate over the range [`lo`..`hi`), or stop when requested
7065
*

src/libcore/vec.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,6 @@ mod raw {
17991799
mod bytes {
18001800
export cmp;
18011801
export lt, le, eq, ne, ge, gt;
1802-
export hash;
18031802
export memcpy, memmove;
18041803

18051804
/// Bytewise string comparison
@@ -1841,11 +1840,6 @@ mod bytes {
18411840
/// Bytewise greater than
18421841
pure fn gt(a: &~[u8], b: &~[u8]) -> bool { cmp(a, b) > 0 }
18431842

1844-
/// Byte-vec hash function
1845-
pure fn hash(s: &~[u8]) -> uint {
1846-
hash::hash_bytes(*s) as uint
1847-
}
1848-
18491843
/**
18501844
* Copies data from one vector to another.
18511845
*

src/libstd/map.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,6 @@ mod tests {
658658
fn test_removal() {
659659
debug!("*** starting test_removal");
660660
let num_to_insert: uint = 64u;
661-
fn eq(x: &uint, y: &uint) -> bool { *x == *y }
662-
fn hash(u: &uint) -> uint {
663-
// This hash function intentionally causes collisions between
664-
// consecutive integer pairs.
665-
*u / 2u * 2u
666-
}
667661
assert (hash(&0u) == hash(&1u));
668662
assert (hash(&2u) == hash(&3u));
669663
assert (hash(&0u) != hash(&2u));

src/rustc/lib/llvm.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,6 @@ fn name_has_type(tn: type_names, s: ~str) -> Option<TypeRef> {
10551055
}
10561056

10571057
fn mk_type_names() -> type_names {
1058-
pure fn hash(t: &TypeRef) -> uint { *t as uint }
1059-
pure fn eq(a: &TypeRef, b: &TypeRef) -> bool { *a == *b }
10601058
@{type_names: std::map::HashMap(),
10611059
named_types: std::map::HashMap()}
10621060
}

src/test/bench/task-perf-word-count-generic.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ trait word_reader {
3939
fn read_word() -> Option<~str>;
4040
}
4141

42-
trait hash_key {
43-
pure fn hash() -> uint;
44-
pure fn eq(&&k: self) -> bool;
45-
}
46-
47-
impl ~str: hash_key {
48-
pure fn hash() -> uint { str::hash(&self) }
49-
pure fn eq(&&x: ~str) -> bool { self == x }
50-
}
51-
5242
// These used to be in task, but they disappeard.
5343
type joinable_task = Port<()>;
5444
fn spawn_joinable(+f: fn~()) -> joinable_task {
@@ -152,7 +142,7 @@ mod map_reduce {
152142

153143
enum reduce_proto<V: Copy Send> { emit_val(V), done, addref, release }
154144

155-
fn start_mappers<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send hash_key,
145+
fn start_mappers<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send,
156146
V: Copy Send>(
157147
map: mapper<K1, K2, V>,
158148
&ctrls: ~[ctrl_proto::server::open<K2, V>],
@@ -169,7 +159,7 @@ mod map_reduce {
169159
return tasks;
170160
}
171161

172-
fn map_task<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send hash_key, V: Copy Send>(
162+
fn map_task<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send, V: Copy Send>(
173163
map: mapper<K1, K2, V>,
174164
ctrl: box<ctrl_proto::client::open<K2, V>>,
175165
input: K1)
@@ -242,7 +232,7 @@ mod map_reduce {
242232
reduce(key, || get(p, ref_count, is_done) );
243233
}
244234

245-
fn map_reduce<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send hash_key, V: Copy Send>(
235+
fn map_reduce<K1: Copy Send, K2: Hash IterBytes Eq Const Copy Send, V: Copy Send>(
246236
map: mapper<K1, K2, V>,
247237
reduce: reducer<K2, V>,
248238
inputs: ~[K1])

0 commit comments

Comments
 (0)