Rewrite int/uint helper functions to use refs

This lets us pass them to generic functions.
This commit is contained in:
Erick Tryzelaar 2012-06-12 16:16:47 -07:00 committed by Graydon Hoare
parent 4335ce47f3
commit 48e877a435
5 changed files with 32 additions and 38 deletions

View File

@ -16,21 +16,21 @@ export ord, eq, num;
const min_value: T = -1 as T << (inst::bits - 1 as T);
const max_value: T = min_value - 1 as T;
pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }
pure fn add(x: T, y: T) -> T { x + y }
pure fn sub(x: T, y: T) -> T { x - y }
pure fn mul(x: T, y: T) -> T { x * y }
pure fn div(x: T, y: T) -> T { x / y }
pure fn rem(x: T, y: T) -> T { x % y }
pure fn add(&&x: T, &&y: T) -> T { x + y }
pure fn sub(&&x: T, &&y: T) -> T { x - y }
pure fn mul(&&x: T, &&y: T) -> T { x * y }
pure fn div(&&x: T, &&y: T) -> T { x / y }
pure fn rem(&&x: T, &&y: T) -> T { x % y }
pure fn lt(x: T, y: T) -> bool { x < y }
pure fn le(x: T, y: T) -> bool { x <= y }
pure fn eq(x: T, y: T) -> bool { x == y }
pure fn ne(x: T, y: T) -> bool { x != y }
pure fn ge(x: T, y: T) -> bool { x >= y }
pure fn gt(x: T, y: T) -> bool { x > y }
pure fn lt(&&x: T, &&y: T) -> bool { x < y }
pure fn le(&&x: T, &&y: T) -> bool { x <= y }
pure fn eq(&&x: T, &&y: T) -> bool { x == y }
pure fn ne(&&x: T, &&y: T) -> bool { x != y }
pure fn ge(&&x: T, &&y: T) -> bool { x >= y }
pure fn gt(&&x: T, &&y: T) -> bool { x > y }
pure fn is_positive(x: T) -> bool { x > 0 as T }
pure fn is_negative(x: T) -> bool { x < 0 as T }

View File

@ -7,7 +7,7 @@ const bits: T = 32 as T;
const bits: T = 64 as T;
#[doc = "Produce a uint suitable for use in a hash table"]
pure fn hash(x: int) -> uint { ret x as uint; }
pure fn hash(&&x: int) -> uint { ret x as uint; }
#[doc = "Returns `base` raised to the power of `exponent`"]
fn pow(base: int, exponent: uint) -> int {

View File

@ -16,21 +16,21 @@ export ord, eq, num;
const min_value: T = 0 as T;
const max_value: T = 0 as T - 1 as T;
pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }
pure fn add(x: T, y: T) -> T { x + y }
pure fn sub(x: T, y: T) -> T { x - y }
pure fn mul(x: T, y: T) -> T { x * y }
pure fn div(x: T, y: T) -> T { x / y }
pure fn rem(x: T, y: T) -> T { x % y }
pure fn add(&&x: T, &&y: T) -> T { x + y }
pure fn sub(&&x: T, &&y: T) -> T { x - y }
pure fn mul(&&x: T, &&y: T) -> T { x * y }
pure fn div(&&x: T, &&y: T) -> T { x / y }
pure fn rem(&&x: T, &&y: T) -> T { x % y }
pure fn lt(x: T, y: T) -> bool { x < y }
pure fn le(x: T, y: T) -> bool { x <= y }
pure fn eq(x: T, y: T) -> bool { x == y }
pure fn ne(x: T, y: T) -> bool { x != y }
pure fn ge(x: T, y: T) -> bool { x >= y }
pure fn gt(x: T, y: T) -> bool { x > y }
pure fn lt(&&x: T, &&y: T) -> bool { x < y }
pure fn le(&&x: T, &&y: T) -> bool { x <= y }
pure fn eq(&&x: T, &&y: T) -> bool { x == y }
pure fn ne(&&x: T, &&y: T) -> bool { x != y }
pure fn ge(&&x: T, &&y: T) -> bool { x >= y }
pure fn gt(&&x: T, &&y: T) -> bool { x > y }
pure fn is_positive(x: T) -> bool { x > 0 as T }
pure fn is_negative(x: T) -> bool { x < 0 as T }

View File

@ -54,7 +54,7 @@ is either `x/y` or `x/y + 1`.
pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; }
#[doc = "Produce a uint suitable for use in a hash table"]
pure fn hash(x: uint) -> uint { ret x; }
pure fn hash(&&x: uint) -> uint { ret x; }
#[doc = "
Iterate over the range [`lo`..`hi`), or stop when requested

View File

@ -297,20 +297,14 @@ fn bytes_hash<V: copy>() -> hashmap<[u8], V> {
ret hashmap(vec::u8::hash, vec::u8::eq);
}
fn hash_int(&&x: int) -> uint { int::hash(x) }
fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; }
#[doc = "Construct a hashmap for int keys"]
fn int_hash<V: copy>() -> hashmap<int, V> {
ret hashmap(hash_int, eq_int);
ret hashmap(int::hash, int::eq);
}
fn hash_uint(&&x: uint) -> uint { uint::hash(x) }
fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; }
#[doc = "Construct a hashmap for uint keys"]
fn uint_hash<V: copy>() -> hashmap<uint, V> {
ret hashmap(hash_uint, eq_uint);
ret hashmap(uint::hash, uint::eq);
}
#[doc = "
@ -355,12 +349,12 @@ fn hash_from_bytes<V: copy>(items: [([u8], V)]) -> hashmap<[u8], V> {
#[doc = "Construct a hashmap from a vector with int keys"]
fn hash_from_ints<V: copy>(items: [(int, V)]) -> hashmap<int, V> {
hash_from_vec(hash_int, eq_int, items)
hash_from_vec(int::hash, int::eq, items)
}
#[doc = "Construct a hashmap from a vector with uint keys"]
fn hash_from_uints<V: copy>(items: [(uint, V)]) -> hashmap<uint, V> {
hash_from_vec(hash_uint, eq_uint, items)
hash_from_vec(uint::hash, uint::eq, items)
}
#[cfg(test)]