Skip to content

Commit 48e877a

Browse files
ericktgraydon
authored andcommitted
Rewrite int/uint helper functions to use refs
This lets us pass them to generic functions.
1 parent 4335ce4 commit 48e877a

File tree

5 files changed

+36
-42
lines changed

5 files changed

+36
-42
lines changed

src/libcore/int-template.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ export ord, eq, num;
1616
const min_value: T = -1 as T << (inst::bits - 1 as T);
1717
const max_value: T = min_value - 1 as T;
1818

19-
pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
20-
pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
21-
22-
pure fn add(x: T, y: T) -> T { x + y }
23-
pure fn sub(x: T, y: T) -> T { x - y }
24-
pure fn mul(x: T, y: T) -> T { x * y }
25-
pure fn div(x: T, y: T) -> T { x / y }
26-
pure fn rem(x: T, y: T) -> T { x % y }
27-
28-
pure fn lt(x: T, y: T) -> bool { x < y }
29-
pure fn le(x: T, y: T) -> bool { x <= y }
30-
pure fn eq(x: T, y: T) -> bool { x == y }
31-
pure fn ne(x: T, y: T) -> bool { x != y }
32-
pure fn ge(x: T, y: T) -> bool { x >= y }
33-
pure fn gt(x: T, y: T) -> bool { x > y }
19+
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
20+
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }
21+
22+
pure fn add(&&x: T, &&y: T) -> T { x + y }
23+
pure fn sub(&&x: T, &&y: T) -> T { x - y }
24+
pure fn mul(&&x: T, &&y: T) -> T { x * y }
25+
pure fn div(&&x: T, &&y: T) -> T { x / y }
26+
pure fn rem(&&x: T, &&y: T) -> T { x % y }
27+
28+
pure fn lt(&&x: T, &&y: T) -> bool { x < y }
29+
pure fn le(&&x: T, &&y: T) -> bool { x <= y }
30+
pure fn eq(&&x: T, &&y: T) -> bool { x == y }
31+
pure fn ne(&&x: T, &&y: T) -> bool { x != y }
32+
pure fn ge(&&x: T, &&y: T) -> bool { x >= y }
33+
pure fn gt(&&x: T, &&y: T) -> bool { x > y }
3434

3535
pure fn is_positive(x: T) -> bool { x > 0 as T }
3636
pure fn is_negative(x: T) -> bool { x < 0 as T }

src/libcore/int-template/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const bits: T = 32 as T;
77
const bits: T = 64 as T;
88

99
#[doc = "Produce a uint suitable for use in a hash table"]
10-
pure fn hash(x: int) -> uint { ret x as uint; }
10+
pure fn hash(&&x: int) -> uint { ret x as uint; }
1111

1212
#[doc = "Returns `base` raised to the power of `exponent`"]
1313
fn pow(base: int, exponent: uint) -> int {

src/libcore/uint-template.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ export ord, eq, num;
1616
const min_value: T = 0 as T;
1717
const max_value: T = 0 as T - 1 as T;
1818

19-
pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
20-
pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
21-
22-
pure fn add(x: T, y: T) -> T { x + y }
23-
pure fn sub(x: T, y: T) -> T { x - y }
24-
pure fn mul(x: T, y: T) -> T { x * y }
25-
pure fn div(x: T, y: T) -> T { x / y }
26-
pure fn rem(x: T, y: T) -> T { x % y }
27-
28-
pure fn lt(x: T, y: T) -> bool { x < y }
29-
pure fn le(x: T, y: T) -> bool { x <= y }
30-
pure fn eq(x: T, y: T) -> bool { x == y }
31-
pure fn ne(x: T, y: T) -> bool { x != y }
32-
pure fn ge(x: T, y: T) -> bool { x >= y }
33-
pure fn gt(x: T, y: T) -> bool { x > y }
19+
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
20+
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }
21+
22+
pure fn add(&&x: T, &&y: T) -> T { x + y }
23+
pure fn sub(&&x: T, &&y: T) -> T { x - y }
24+
pure fn mul(&&x: T, &&y: T) -> T { x * y }
25+
pure fn div(&&x: T, &&y: T) -> T { x / y }
26+
pure fn rem(&&x: T, &&y: T) -> T { x % y }
27+
28+
pure fn lt(&&x: T, &&y: T) -> bool { x < y }
29+
pure fn le(&&x: T, &&y: T) -> bool { x <= y }
30+
pure fn eq(&&x: T, &&y: T) -> bool { x == y }
31+
pure fn ne(&&x: T, &&y: T) -> bool { x != y }
32+
pure fn ge(&&x: T, &&y: T) -> bool { x >= y }
33+
pure fn gt(&&x: T, &&y: T) -> bool { x > y }
3434

3535
pure fn is_positive(x: T) -> bool { x > 0 as T }
3636
pure fn is_negative(x: T) -> bool { x < 0 as T }

src/libcore/uint-template/uint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ is either `x/y` or `x/y + 1`.
5454
pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; }
5555

5656
#[doc = "Produce a uint suitable for use in a hash table"]
57-
pure fn hash(x: uint) -> uint { ret x; }
57+
pure fn hash(&&x: uint) -> uint { ret x; }
5858

5959
#[doc = "
6060
Iterate over the range [`lo`..`hi`), or stop when requested

src/libstd/map.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,14 @@ fn bytes_hash<V: copy>() -> hashmap<[u8], V> {
297297
ret hashmap(vec::u8::hash, vec::u8::eq);
298298
}
299299

300-
fn hash_int(&&x: int) -> uint { int::hash(x) }
301-
fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; }
302-
303300
#[doc = "Construct a hashmap for int keys"]
304301
fn int_hash<V: copy>() -> hashmap<int, V> {
305-
ret hashmap(hash_int, eq_int);
302+
ret hashmap(int::hash, int::eq);
306303
}
307304

308-
fn hash_uint(&&x: uint) -> uint { uint::hash(x) }
309-
fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; }
310-
311305
#[doc = "Construct a hashmap for uint keys"]
312306
fn uint_hash<V: copy>() -> hashmap<uint, V> {
313-
ret hashmap(hash_uint, eq_uint);
307+
ret hashmap(uint::hash, uint::eq);
314308
}
315309

316310
#[doc = "
@@ -355,12 +349,12 @@ fn hash_from_bytes<V: copy>(items: [([u8], V)]) -> hashmap<[u8], V> {
355349

356350
#[doc = "Construct a hashmap from a vector with int keys"]
357351
fn hash_from_ints<V: copy>(items: [(int, V)]) -> hashmap<int, V> {
358-
hash_from_vec(hash_int, eq_int, items)
352+
hash_from_vec(int::hash, int::eq, items)
359353
}
360354

361355
#[doc = "Construct a hashmap from a vector with uint keys"]
362356
fn hash_from_uints<V: copy>(items: [(uint, V)]) -> hashmap<uint, V> {
363-
hash_from_vec(hash_uint, eq_uint, items)
357+
hash_from_vec(uint::hash, uint::eq, items)
364358
}
365359

366360
#[cfg(test)]

0 commit comments

Comments
 (0)