libstd: Remove all uses of pure from libstd. rs=depure

This commit is contained in:
Patrick Walton 2013-03-21 21:34:30 -07:00
parent be9bddd463
commit c1084091d4
25 changed files with 353 additions and 353 deletions

View File

@ -123,7 +123,7 @@ pub fn Arena() -> Arena {
}
#[inline(always)]
pure fn round_up_to(base: uint, align: uint) -> uint {
fn round_up_to(base: uint, align: uint) -> uint {
(base + (align - 1)) & !(align - 1)
}

View File

@ -13,11 +13,11 @@ use core::str;
use core::vec;
pub trait ToBase64 {
pure fn to_base64(&self) -> ~str;
fn to_base64(&self) -> ~str;
}
impl ToBase64 for &'self [u8] {
pure fn to_base64(&self) -> ~str {
fn to_base64(&self) -> ~str {
let chars = str::chars(
~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
);
@ -70,17 +70,17 @@ impl ToBase64 for &'self [u8] {
}
impl ToBase64 for &'self str {
pure fn to_base64(&self) -> ~str {
fn to_base64(&self) -> ~str {
str::to_bytes(*self).to_base64()
}
}
pub trait FromBase64 {
pure fn from_base64(&self) -> ~[u8];
fn from_base64(&self) -> ~[u8];
}
impl FromBase64 for ~[u8] {
pure fn from_base64(&self) -> ~[u8] {
fn from_base64(&self) -> ~[u8] {
if self.len() % 4u != 0u { fail!(~"invalid base64 length"); }
let len = self.len();
@ -142,7 +142,7 @@ impl FromBase64 for ~[u8] {
}
impl FromBase64 for ~str {
pure fn from_base64(&self) -> ~[u8] {
fn from_base64(&self) -> ~[u8] {
str::to_bytes(*self).from_base64()
}
}

View File

@ -53,16 +53,16 @@ pub mod BigDigit {
priv const hi_mask: uint = (-1 as uint) << bits;
priv const lo_mask: uint = (-1 as uint) >> bits;
priv pure fn get_hi(n: uint) -> BigDigit { (n >> bits) as BigDigit }
priv pure fn get_lo(n: uint) -> BigDigit { (n & lo_mask) as BigDigit }
priv fn get_hi(n: uint) -> BigDigit { (n >> bits) as BigDigit }
priv fn get_lo(n: uint) -> BigDigit { (n & lo_mask) as BigDigit }
/// Split one machine sized unsigned integer into two BigDigits.
pub pure fn from_uint(n: uint) -> (BigDigit, BigDigit) {
pub fn from_uint(n: uint) -> (BigDigit, BigDigit) {
(get_hi(n), get_lo(n))
}
/// Join two BigDigits into one machine sized unsigned integer
pub pure fn to_uint(hi: BigDigit, lo: BigDigit) -> uint {
pub fn to_uint(hi: BigDigit, lo: BigDigit) -> uint {
(lo as uint) | ((hi as uint) << bits)
}
}
@ -78,29 +78,29 @@ pub struct BigUint {
}
impl Eq for BigUint {
pure fn eq(&self, other: &BigUint) -> bool { self.cmp(other) == 0 }
pure fn ne(&self, other: &BigUint) -> bool { self.cmp(other) != 0 }
fn eq(&self, other: &BigUint) -> bool { self.cmp(other) == 0 }
fn ne(&self, other: &BigUint) -> bool { self.cmp(other) != 0 }
}
impl Ord for BigUint {
pure fn lt(&self, other: &BigUint) -> bool { self.cmp(other) < 0 }
pure fn le(&self, other: &BigUint) -> bool { self.cmp(other) <= 0 }
pure fn ge(&self, other: &BigUint) -> bool { self.cmp(other) >= 0 }
pure fn gt(&self, other: &BigUint) -> bool { self.cmp(other) > 0 }
fn lt(&self, other: &BigUint) -> bool { self.cmp(other) < 0 }
fn le(&self, other: &BigUint) -> bool { self.cmp(other) <= 0 }
fn ge(&self, other: &BigUint) -> bool { self.cmp(other) >= 0 }
fn gt(&self, other: &BigUint) -> bool { self.cmp(other) > 0 }
}
impl ToStr for BigUint {
pure fn to_str(&self) -> ~str { self.to_str_radix(10) }
fn to_str(&self) -> ~str { self.to_str_radix(10) }
}
impl from_str::FromStr for BigUint {
pure fn from_str(s: &str) -> Option<BigUint> {
fn from_str(s: &str) -> Option<BigUint> {
BigUint::from_str_radix(s, 10)
}
}
impl Shl<uint, BigUint> for BigUint {
pure fn shl(&self, rhs: &uint) -> BigUint {
fn shl(&self, rhs: &uint) -> BigUint {
let n_unit = *rhs / BigDigit::bits;
let n_bits = *rhs % BigDigit::bits;
return self.shl_unit(n_unit).shl_bits(n_bits);
@ -108,7 +108,7 @@ impl Shl<uint, BigUint> for BigUint {
}
impl Shr<uint, BigUint> for BigUint {
pure fn shr(&self, rhs: &uint) -> BigUint {
fn shr(&self, rhs: &uint) -> BigUint {
let n_unit = *rhs / BigDigit::bits;
let n_bits = *rhs % BigDigit::bits;
return self.shr_unit(n_unit).shr_bits(n_bits);
@ -116,15 +116,15 @@ impl Shr<uint, BigUint> for BigUint {
}
impl Zero for BigUint {
pure fn zero() -> BigUint { BigUint::new(~[]) }
fn zero() -> BigUint { BigUint::new(~[]) }
}
impl One for BigUint {
pub pure fn one() -> BigUint { BigUint::new(~[1]) }
pub fn one() -> BigUint { BigUint::new(~[1]) }
}
impl Add<BigUint, BigUint> for BigUint {
pure fn add(&self, other: &BigUint) -> BigUint {
fn add(&self, other: &BigUint) -> BigUint {
let new_len = uint::max(self.data.len(), other.data.len());
let mut carry = 0;
@ -143,7 +143,7 @@ impl Add<BigUint, BigUint> for BigUint {
}
impl Sub<BigUint, BigUint> for BigUint {
pure fn sub(&self, other: &BigUint) -> BigUint {
fn sub(&self, other: &BigUint) -> BigUint {
let new_len = uint::max(self.data.len(), other.data.len());
let mut borrow = 0;
@ -168,7 +168,7 @@ impl Sub<BigUint, BigUint> for BigUint {
}
impl Mul<BigUint, BigUint> for BigUint {
pure fn mul(&self, other: &BigUint) -> BigUint {
fn mul(&self, other: &BigUint) -> BigUint {
if self.is_zero() || other.is_zero() { return Zero::zero(); }
let s_len = self.data.len(), o_len = other.data.len();
@ -200,7 +200,7 @@ impl Mul<BigUint, BigUint> for BigUint {
return ll + mm.shl_unit(half_len) + hh.shl_unit(half_len * 2);
pure fn mul_digit(a: &BigUint, n: BigDigit) -> BigUint {
fn mul_digit(a: &BigUint, n: BigDigit) -> BigUint {
if n == 0 { return Zero::zero(); }
if n == 1 { return copy *a; }
@ -216,14 +216,14 @@ impl Mul<BigUint, BigUint> for BigUint {
return BigUint::new(prod + [carry]);
}
pure fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
let mid = uint::min(a.data.len(), n);
return (BigUint::from_slice(vec::slice(a.data, mid,
a.data.len())),
BigUint::from_slice(vec::slice(a.data, 0, mid)));
}
pure fn sub_sign(a: BigUint, b: BigUint) -> (int, BigUint) {
fn sub_sign(a: BigUint, b: BigUint) -> (int, BigUint) {
match a.cmp(&b) {
s if s < 0 => (s, b - a),
s if s > 0 => (s, a - b),
@ -234,36 +234,36 @@ impl Mul<BigUint, BigUint> for BigUint {
}
impl Div<BigUint, BigUint> for BigUint {
pure fn div(&self, other: &BigUint) -> BigUint {
fn div(&self, other: &BigUint) -> BigUint {
let (d, _) = self.divmod(other);
return d;
}
}
impl Modulo<BigUint, BigUint> for BigUint {
pure fn modulo(&self, other: &BigUint) -> BigUint {
fn modulo(&self, other: &BigUint) -> BigUint {
let (_, m) = self.divmod(other);
return m;
}
}
impl Neg<BigUint> for BigUint {
pure fn neg(&self) -> BigUint { fail!() }
fn neg(&self) -> BigUint { fail!() }
}
impl IntConvertible for BigUint {
pure fn to_int(&self) -> int {
fn to_int(&self) -> int {
uint::min(self.to_uint(), int::max_value as uint) as int
}
pure fn from_int(n: int) -> BigUint {
fn from_int(n: int) -> BigUint {
if (n < 0) { Zero::zero() } else { BigUint::from_uint(n as uint) }
}
}
pub impl BigUint {
/// Creates and initializes an BigUint.
pub pure fn new(v: ~[BigDigit]) -> BigUint {
pub fn new(v: ~[BigDigit]) -> BigUint {
// omit trailing zeros
let new_len = v.rposition(|n| *n != 0).map_default(0, |p| *p + 1);
@ -274,7 +274,7 @@ pub impl BigUint {
}
/// Creates and initializes an BigUint.
pub pure fn from_uint(n: uint) -> BigUint {
pub fn from_uint(n: uint) -> BigUint {
match BigDigit::from_uint(n) {
(0, 0) => Zero::zero(),
(0, n0) => BigUint::new(~[n0]),
@ -283,18 +283,18 @@ pub impl BigUint {
}
/// Creates and initializes an BigUint.
pub pure fn from_slice(slice: &[BigDigit]) -> BigUint {
pub fn from_slice(slice: &[BigDigit]) -> BigUint {
return BigUint::new(vec::from_slice(slice));
}
/// Creates and initializes an BigUint.
pub pure fn from_str_radix(s: &str, radix: uint)
pub fn from_str_radix(s: &str, radix: uint)
-> Option<BigUint> {
BigUint::parse_bytes(str::to_bytes(s), radix)
}
/// Creates and initializes an BigUint.
pub pure fn parse_bytes(buf: &[u8], radix: uint)
pub fn parse_bytes(buf: &[u8], radix: uint)
-> Option<BigUint> {
let (base, unit_len) = get_radix_base(radix);
let base_num: BigUint = BigUint::from_uint(base);
@ -316,10 +316,10 @@ pub impl BigUint {
}
}
pure fn abs(&self) -> BigUint { copy *self }
fn abs(&self) -> BigUint { copy *self }
/// Compare two BigUint value.
pure fn cmp(&self, other: &BigUint) -> int {
fn cmp(&self, other: &BigUint) -> int {
let s_len = self.data.len(), o_len = other.data.len();
if s_len < o_len { return -1; }
if s_len > o_len { return 1; }
@ -334,7 +334,7 @@ pub impl BigUint {
return 0;
}
pure fn divmod(&self, other: &BigUint) -> (BigUint, BigUint) {
fn divmod(&self, other: &BigUint) -> (BigUint, BigUint) {
if other.is_zero() { fail!() }
if self.is_zero() { return (Zero::zero(), Zero::zero()); }
if *other == One::one() { return (copy *self, Zero::zero()); }
@ -355,7 +355,7 @@ pub impl BigUint {
let (d, m) = divmod_inner(self << shift, other << shift);
return (d, m >> shift);
pure fn divmod_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
fn divmod_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
let mut r = a;
let mut d = Zero::zero::<BigUint>();
let mut n = 1;
@ -377,7 +377,7 @@ pub impl BigUint {
return (d, r);
}
pure fn div_estimate(a: &BigUint, b: &BigUint, n: uint)
fn div_estimate(a: &BigUint, b: &BigUint, n: uint)
-> (BigUint, BigUint, BigUint) {
if a.data.len() < n {
return (Zero::zero(), Zero::zero(), copy *a);
@ -405,26 +405,26 @@ pub impl BigUint {
}
}
pure fn quot(&self, other: &BigUint) -> BigUint {
fn quot(&self, other: &BigUint) -> BigUint {
let (q, _) = self.quotrem(other);
return q;
}
pure fn rem(&self, other: &BigUint) -> BigUint {
fn rem(&self, other: &BigUint) -> BigUint {
let (_, r) = self.quotrem(other);
return r;
}
pure fn quotrem(&self, other: &BigUint) -> (BigUint, BigUint) {
fn quotrem(&self, other: &BigUint) -> (BigUint, BigUint) {
self.divmod(other)
}
pure fn is_zero(&self) -> bool { self.data.is_empty() }
pure fn is_not_zero(&self) -> bool { !self.data.is_empty() }
pure fn is_positive(&self) -> bool { self.is_not_zero() }
pure fn is_negative(&self) -> bool { false }
pure fn is_nonpositive(&self) -> bool { self.is_zero() }
pure fn is_nonnegative(&self) -> bool { true }
fn is_zero(&self) -> bool { self.data.is_empty() }
fn is_not_zero(&self) -> bool { !self.data.is_empty() }
fn is_positive(&self) -> bool { self.is_not_zero() }
fn is_negative(&self) -> bool { false }
fn is_nonpositive(&self) -> bool { self.is_zero() }
fn is_nonnegative(&self) -> bool { true }
pure fn to_uint(&self) -> uint {
fn to_uint(&self) -> uint {
match self.data.len() {
0 => 0,
1 => self.data[0] as uint,
@ -433,7 +433,7 @@ pub impl BigUint {
}
}
pure fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> ~str {
fail_unless!(1 < radix && radix <= 16);
let (base, max_len) = get_radix_base(radix);
if base == BigDigit::base {
@ -441,7 +441,7 @@ pub impl BigUint {
}
return fill_concat(convert_base(copy *self, base), radix, max_len);
pure fn convert_base(n: BigUint, base: uint) -> ~[BigDigit] {
fn convert_base(n: BigUint, base: uint) -> ~[BigDigit] {
let divider = BigUint::from_uint(base);
let mut result = ~[];
let mut r = n;
@ -456,7 +456,7 @@ pub impl BigUint {
return result;
}
pure fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
if v.is_empty() { return ~"0" }
let s = str::concat(vec::reversed(v).map(|n| {
let s = uint::to_str_radix(*n as uint, radix);
@ -466,13 +466,13 @@ pub impl BigUint {
}
}
priv pure fn shl_unit(self, n_unit: uint) -> BigUint {
priv fn shl_unit(self, n_unit: uint) -> BigUint {
if n_unit == 0 || self.is_zero() { return self; }
return BigUint::new(vec::from_elem(n_unit, 0) + self.data);
}
priv pure fn shl_bits(self, n_bits: uint) -> BigUint {
priv fn shl_bits(self, n_bits: uint) -> BigUint {
if n_bits == 0 || self.is_zero() { return self; }
let mut carry = 0;
@ -487,7 +487,7 @@ pub impl BigUint {
return BigUint::new(shifted + [carry]);
}
priv pure fn shr_unit(self, n_unit: uint) -> BigUint {
priv fn shr_unit(self, n_unit: uint) -> BigUint {
if n_unit == 0 { return self; }
if self.data.len() < n_unit { return Zero::zero(); }
return BigUint::from_slice(
@ -495,7 +495,7 @@ pub impl BigUint {
);
}
priv pure fn shr_bits(self, n_bits: uint) -> BigUint {
priv fn shr_bits(self, n_bits: uint) -> BigUint {
if n_bits == 0 || self.data.is_empty() { return self; }
let mut borrow = 0;
@ -509,7 +509,7 @@ pub impl BigUint {
}
#[cfg(target_arch = "x86_64")]
priv pure fn get_radix_base(radix: uint) -> (uint, uint) {
priv fn get_radix_base(radix: uint) -> (uint, uint) {
fail_unless!(1 < radix && radix <= 16);
match radix {
2 => (4294967296, 32),
@ -534,7 +534,7 @@ priv pure fn get_radix_base(radix: uint) -> (uint, uint) {
#[cfg(target_arch = "arm")]
#[cfg(target_arch = "x86")]
#[cfg(target_arch = "mips")]
priv pure fn get_radix_base(radix: uint) -> (uint, uint) {
priv fn get_radix_base(radix: uint) -> (uint, uint) {
fail_unless!(1 < radix && radix <= 16);
match radix {
2 => (65536, 16),
@ -560,20 +560,20 @@ priv pure fn get_radix_base(radix: uint) -> (uint, uint) {
pub enum Sign { Minus, Zero, Plus }
impl Eq for Sign {
pure fn eq(&self, other: &Sign) -> bool { self.cmp(other) == 0 }
pure fn ne(&self, other: &Sign) -> bool { self.cmp(other) != 0 }
fn eq(&self, other: &Sign) -> bool { self.cmp(other) == 0 }
fn ne(&self, other: &Sign) -> bool { self.cmp(other) != 0 }
}
impl Ord for Sign {
pure fn lt(&self, other: &Sign) -> bool { self.cmp(other) < 0 }
pure fn le(&self, other: &Sign) -> bool { self.cmp(other) <= 0 }
pure fn ge(&self, other: &Sign) -> bool { self.cmp(other) >= 0 }
pure fn gt(&self, other: &Sign) -> bool { self.cmp(other) > 0 }
fn lt(&self, other: &Sign) -> bool { self.cmp(other) < 0 }
fn le(&self, other: &Sign) -> bool { self.cmp(other) <= 0 }
fn ge(&self, other: &Sign) -> bool { self.cmp(other) >= 0 }
fn gt(&self, other: &Sign) -> bool { self.cmp(other) > 0 }
}
pub impl Sign {
/// Compare two Sign.
pure fn cmp(&self, other: &Sign) -> int {
fn cmp(&self, other: &Sign) -> int {
match (*self, *other) {
(Minus, Minus) | (Zero, Zero) | (Plus, Plus) => 0,
(Minus, Zero) | (Minus, Plus) | (Zero, Plus) => -1,
@ -582,7 +582,7 @@ pub impl Sign {
}
/// Negate Sign value.
pure fn neg(&self) -> Sign {
fn neg(&self) -> Sign {
match *self {
Minus => Plus,
Zero => Zero,
@ -598,53 +598,53 @@ pub struct BigInt {
}
impl Eq for BigInt {
pure fn eq(&self, other: &BigInt) -> bool { self.cmp(other) == 0 }
pure fn ne(&self, other: &BigInt) -> bool { self.cmp(other) != 0 }
fn eq(&self, other: &BigInt) -> bool { self.cmp(other) == 0 }
fn ne(&self, other: &BigInt) -> bool { self.cmp(other) != 0 }
}
impl Ord for BigInt {
pure fn lt(&self, other: &BigInt) -> bool { self.cmp(other) < 0 }
pure fn le(&self, other: &BigInt) -> bool { self.cmp(other) <= 0 }
pure fn ge(&self, other: &BigInt) -> bool { self.cmp(other) >= 0 }
pure fn gt(&self, other: &BigInt) -> bool { self.cmp(other) > 0 }
fn lt(&self, other: &BigInt) -> bool { self.cmp(other) < 0 }
fn le(&self, other: &BigInt) -> bool { self.cmp(other) <= 0 }
fn ge(&self, other: &BigInt) -> bool { self.cmp(other) >= 0 }
fn gt(&self, other: &BigInt) -> bool { self.cmp(other) > 0 }
}
impl ToStr for BigInt {
pure fn to_str(&self) -> ~str { self.to_str_radix(10) }
fn to_str(&self) -> ~str { self.to_str_radix(10) }
}
impl from_str::FromStr for BigInt {
pure fn from_str(s: &str) -> Option<BigInt> {
fn from_str(s: &str) -> Option<BigInt> {
BigInt::from_str_radix(s, 10)
}
}
impl Shl<uint, BigInt> for BigInt {
pure fn shl(&self, rhs: &uint) -> BigInt {
fn shl(&self, rhs: &uint) -> BigInt {
BigInt::from_biguint(self.sign, self.data << *rhs)
}
}
impl Shr<uint, BigInt> for BigInt {
pure fn shr(&self, rhs: &uint) -> BigInt {
fn shr(&self, rhs: &uint) -> BigInt {
BigInt::from_biguint(self.sign, self.data >> *rhs)
}
}
impl Zero for BigInt {
pub pure fn zero() -> BigInt {
pub fn zero() -> BigInt {
BigInt::from_biguint(Zero, Zero::zero())
}
}
impl One for BigInt {
pub pure fn one() -> BigInt {
pub fn one() -> BigInt {
BigInt::from_biguint(Plus, One::one())
}
}
impl Add<BigInt, BigInt> for BigInt {
pure fn add(&self, other: &BigInt) -> BigInt {
fn add(&self, other: &BigInt) -> BigInt {
match (self.sign, other.sign) {
(Zero, _) => copy *other,
(_, Zero) => copy *self,
@ -658,7 +658,7 @@ impl Add<BigInt, BigInt> for BigInt {
}
impl Sub<BigInt, BigInt> for BigInt {
pure fn sub(&self, other: &BigInt) -> BigInt {
fn sub(&self, other: &BigInt) -> BigInt {
match (self.sign, other.sign) {
(Zero, _) => -other,
(_, Zero) => copy *self,
@ -678,7 +678,7 @@ impl Sub<BigInt, BigInt> for BigInt {
}
impl Mul<BigInt, BigInt> for BigInt {
pure fn mul(&self, other: &BigInt) -> BigInt {
fn mul(&self, other: &BigInt) -> BigInt {
match (self.sign, other.sign) {
(Zero, _) | (_, Zero) => Zero::zero(),
(Plus, Plus) | (Minus, Minus) => {
@ -692,27 +692,27 @@ impl Mul<BigInt, BigInt> for BigInt {
}
impl Div<BigInt, BigInt> for BigInt {
pure fn div(&self, other: &BigInt) -> BigInt {
fn div(&self, other: &BigInt) -> BigInt {
let (d, _) = self.divmod(other);
return d;
}
}
impl Modulo<BigInt, BigInt> for BigInt {
pure fn modulo(&self, other: &BigInt) -> BigInt {
fn modulo(&self, other: &BigInt) -> BigInt {
let (_, m) = self.divmod(other);
return m;
}
}
impl Neg<BigInt> for BigInt {
pure fn neg(&self) -> BigInt {
fn neg(&self) -> BigInt {
BigInt::from_biguint(self.sign.neg(), copy self.data)
}
}
impl IntConvertible for BigInt {
pure fn to_int(&self) -> int {
fn to_int(&self) -> int {
match self.sign {
Plus => uint::min(self.to_uint(), int::max_value as uint) as int,
Zero => 0,
@ -721,7 +721,7 @@ impl IntConvertible for BigInt {
}
}
pure fn from_int(n: int) -> BigInt {
fn from_int(n: int) -> BigInt {
if n > 0 {
return BigInt::from_biguint(Plus, BigUint::from_uint(n as uint));
}
@ -736,12 +736,12 @@ impl IntConvertible for BigInt {
pub impl BigInt {
/// Creates and initializes an BigInt.
pub pure fn new(sign: Sign, v: ~[BigDigit]) -> BigInt {
pub fn new(sign: Sign, v: ~[BigDigit]) -> BigInt {
BigInt::from_biguint(sign, BigUint::new(v))
}
/// Creates and initializes an BigInt.
pub pure fn from_biguint(sign: Sign, data: BigUint) -> BigInt {
pub fn from_biguint(sign: Sign, data: BigUint) -> BigInt {
if sign == Zero || data.is_zero() {
return BigInt { sign: Zero, data: Zero::zero() };
}
@ -749,24 +749,24 @@ pub impl BigInt {
}
/// Creates and initializes an BigInt.
pub pure fn from_uint(n: uint) -> BigInt {
pub fn from_uint(n: uint) -> BigInt {
if n == 0 { return Zero::zero(); }
return BigInt::from_biguint(Plus, BigUint::from_uint(n));
}
/// Creates and initializes an BigInt.
pub pure fn from_slice(sign: Sign, slice: &[BigDigit]) -> BigInt {
pub fn from_slice(sign: Sign, slice: &[BigDigit]) -> BigInt {
BigInt::from_biguint(sign, BigUint::from_slice(slice))
}
/// Creates and initializes an BigInt.
pub pure fn from_str_radix(s: &str, radix: uint)
pub fn from_str_radix(s: &str, radix: uint)
-> Option<BigInt> {
BigInt::parse_bytes(str::to_bytes(s), radix)
}
/// Creates and initializes an BigInt.
pub pure fn parse_bytes(buf: &[u8], radix: uint)
pub fn parse_bytes(buf: &[u8], radix: uint)
-> Option<BigInt> {
if buf.is_empty() { return None; }
let mut sign = Plus;
@ -779,11 +779,11 @@ pub impl BigInt {
.map(|bu| BigInt::from_biguint(sign, *bu));
}
pure fn abs(&self) -> BigInt {
fn abs(&self) -> BigInt {
BigInt::from_biguint(Plus, copy self.data)
}
pure fn cmp(&self, other: &BigInt) -> int {
fn cmp(&self, other: &BigInt) -> int {
let ss = self.sign, os = other.sign;
if ss < os { return -1; }
if ss > os { return 1; }
@ -796,7 +796,7 @@ pub impl BigInt {
}
}
pure fn divmod(&self, other: &BigInt) -> (BigInt, BigInt) {
fn divmod(&self, other: &BigInt) -> (BigInt, BigInt) {
// m.sign == other.sign
let (d_ui, m_ui) = self.data.divmod(&other.data);
let d = BigInt::from_biguint(Plus, d_ui),
@ -818,16 +818,16 @@ pub impl BigInt {
}
}
pure fn quot(&self, other: &BigInt) -> BigInt {
fn quot(&self, other: &BigInt) -> BigInt {
let (q, _) = self.quotrem(other);
return q;
}
pure fn rem(&self, other: &BigInt) -> BigInt {
fn rem(&self, other: &BigInt) -> BigInt {
let (_, r) = self.quotrem(other);
return r;
}
pure fn quotrem(&self, other: &BigInt) -> (BigInt, BigInt) {
fn quotrem(&self, other: &BigInt) -> (BigInt, BigInt) {
// r.sign == self.sign
let (q_ui, r_ui) = self.data.quotrem(&other.data);
let q = BigInt::from_biguint(Plus, q_ui);
@ -841,14 +841,14 @@ pub impl BigInt {
}
}
pure fn is_zero(&self) -> bool { self.sign == Zero }
pure fn is_not_zero(&self) -> bool { self.sign != Zero }
pure fn is_positive(&self) -> bool { self.sign == Plus }
pure fn is_negative(&self) -> bool { self.sign == Minus }
pure fn is_nonpositive(&self) -> bool { self.sign != Plus }
pure fn is_nonnegative(&self) -> bool { self.sign != Minus }
fn is_zero(&self) -> bool { self.sign == Zero }
fn is_not_zero(&self) -> bool { self.sign != Zero }
fn is_positive(&self) -> bool { self.sign == Plus }
fn is_negative(&self) -> bool { self.sign == Minus }
fn is_nonpositive(&self) -> bool { self.sign != Plus }
fn is_nonnegative(&self) -> bool { self.sign != Minus }
pure fn to_uint(&self) -> uint {
fn to_uint(&self) -> uint {
match self.sign {
Plus => self.data.to_uint(),
Zero => 0,
@ -856,7 +856,7 @@ pub impl BigInt {
}
}
pure fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> ~str {
match self.sign {
Plus => self.data.to_str_radix(radix),
Zero => ~"0",

View File

@ -62,7 +62,7 @@ pub impl SmallBitv {
}
#[inline(always)]
pure fn get(&self, i: uint) -> bool {
fn get(&self, i: uint) -> bool {
(self.bits & (1 << i)) != 0
}
@ -181,7 +181,7 @@ pub impl BigBitv {
}
#[inline(always)]
pure fn get(&self, i: uint) -> bool {
fn get(&self, i: uint) -> bool {
let w = i / uint::bits;
let b = i % uint::bits;
let x = 1 & self.storage[w] >> b;
@ -299,7 +299,7 @@ pub impl Bitv {
/// Retrieve the value at index `i`
#[inline(always)]
pure fn get(&self, i: uint) -> bool {
fn get(&self, i: uint) -> bool {
fail_unless!((i < self.nbits));
match self.rep {
Big(ref b) => b.get(i),
@ -555,13 +555,13 @@ pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv {
}
impl ops::Index<uint,bool> for Bitv {
pure fn index(&self, i: uint) -> bool {
fn index(&self, i: uint) -> bool {
self.get(i)
}
}
#[inline(always)]
pure fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool {
fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool {
if bits == 0 {
return true;
}
@ -612,7 +612,7 @@ pub impl BitvSet {
/// Returns the capacity in bits for this bit vector. Inserting any
/// element less than this amount will not trigger a resizing.
pure fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits }
fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits }
/// Consumes this set to return the underlying bit vector
fn unwrap(self) -> Bitv {
@ -667,9 +667,9 @@ pub impl BitvSet {
}
impl BaseIter<uint> for BitvSet {
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
pure fn each(&self, blk: &fn(v: &uint) -> bool) {
fn each(&self, blk: &fn(v: &uint) -> bool) {
for self.bitv.storage.eachi |i, &w| {
if !iterate_bits(i * uint::bits, w, |b| blk(&b)) {
return;
@ -679,7 +679,7 @@ impl BaseIter<uint> for BitvSet {
}
impl cmp::Eq for BitvSet {
pure fn eq(&self, other: &BitvSet) -> bool {
fn eq(&self, other: &BitvSet) -> bool {
if self.size != other.size {
return false;
}
@ -696,12 +696,12 @@ impl cmp::Eq for BitvSet {
return true;
}
pure fn ne(&self, other: &BitvSet) -> bool { !self.eq(other) }
fn ne(&self, other: &BitvSet) -> bool { !self.eq(other) }
}
impl Container for BitvSet {
pure fn len(&const self) -> uint { self.size }
pure fn is_empty(&const self) -> bool { self.size == 0 }
fn len(&const self) -> uint { self.size }
fn is_empty(&const self) -> bool { self.size == 0 }
}
impl Mutable for BitvSet {
@ -712,7 +712,7 @@ impl Mutable for BitvSet {
}
impl Set<uint> for BitvSet {
pure fn contains(&self, value: &uint) -> bool {
fn contains(&self, value: &uint) -> bool {
*value < self.bitv.storage.len() * uint::bits && self.bitv.get(*value)
}
@ -748,14 +748,14 @@ impl Set<uint> for BitvSet {
return true;
}
pure fn is_disjoint(&self, other: &BitvSet) -> bool {
fn is_disjoint(&self, other: &BitvSet) -> bool {
for self.intersection(other) |_| {
return false;
}
return true;
}
pure fn is_subset(&self, other: &BitvSet) -> bool {
fn is_subset(&self, other: &BitvSet) -> bool {
for self.each_common(other) |_, w1, w2| {
if w1 & w2 != w1 {
return false;
@ -774,11 +774,11 @@ impl Set<uint> for BitvSet {
return true;
}
pure fn is_superset(&self, other: &BitvSet) -> bool {
fn is_superset(&self, other: &BitvSet) -> bool {
other.is_subset(self)
}
pure fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
return;
@ -790,7 +790,7 @@ impl Set<uint> for BitvSet {
);
}
pure fn symmetric_difference(&self, other: &BitvSet,
fn symmetric_difference(&self, other: &BitvSet,
f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
@ -802,7 +802,7 @@ impl Set<uint> for BitvSet {
);
}
pure fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 & w2, |b| f(&b)) {
return;
@ -810,7 +810,7 @@ impl Set<uint> for BitvSet {
}
}
pure fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 | w2, |b| f(&b)) {
return;
@ -827,7 +827,7 @@ priv impl BitvSet {
/// both have in common. The three yielded arguments are (bit location,
/// w1, w2) where the bit location is the number of bits offset so far,
/// and w1/w2 are the words coming from the two vectors self, other.
pure fn each_common(&self, other: &BitvSet,
fn each_common(&self, other: &BitvSet,
f: &fn(uint, uint, uint) -> bool) {
let min = uint::min(self.bitv.storage.len(),
other.bitv.storage.len());
@ -845,7 +845,7 @@ priv impl BitvSet {
/// The yielded arguments are a bool, the bit offset, and a word. The bool
/// is true if the word comes from 'self', and false if it comes from
/// 'other'.
pure fn each_outlier(&self, other: &BitvSet,
fn each_outlier(&self, other: &BitvSet,
f: &fn(bool, uint, uint) -> bool) {
let len1 = self.bitv.storage.len();
let len2 = other.bitv.storage.len();

View File

@ -141,7 +141,7 @@ pub fn set<T:Copy>(t: CVec<T>, ofs: uint, v: T) {
*/
/// Returns the length of the vector
pub pure fn len<T>(t: CVec<T>) -> uint { t.len }
pub fn len<T>(t: CVec<T>) -> uint { t.len }
/// Returns a pointer to the first element of the vector
pub unsafe fn ptr<T>(t: CVec<T>) -> *mut T { t.base }

View File

@ -17,36 +17,36 @@ use core::float;
pub const FUZZY_EPSILON: float = 1.0e-6;
pub trait FuzzyEq<Eps> {
pure fn fuzzy_eq(&self, other: &Self) -> bool;
pure fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
fn fuzzy_eq(&self, other: &Self) -> bool;
fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
}
impl FuzzyEq<float> for float {
pure fn fuzzy_eq(&self, other: &float) -> bool {
fn fuzzy_eq(&self, other: &float) -> bool {
self.fuzzy_eq_eps(other, &FUZZY_EPSILON)
}
pure fn fuzzy_eq_eps(&self, other: &float, epsilon: &float) -> bool {
fn fuzzy_eq_eps(&self, other: &float, epsilon: &float) -> bool {
float::abs(*self - *other) < *epsilon
}
}
impl FuzzyEq<f32> for f32 {
pure fn fuzzy_eq(&self, other: &f32) -> bool {
fn fuzzy_eq(&self, other: &f32) -> bool {
self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f32))
}
pure fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
f32::abs(*self - *other) < *epsilon
}
}
impl FuzzyEq<f64> for f64 {
pure fn fuzzy_eq(&self, other: &f64) -> bool {
fn fuzzy_eq(&self, other: &f64) -> bool {
self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f64))
}
pure fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
f64::abs(*self - *other) < *epsilon
}
}
@ -71,11 +71,11 @@ mod test_complex{
struct Complex { r: float, i: float }
impl FuzzyEq<float> for Complex {
pure fn fuzzy_eq(&self, other: &Complex) -> bool {
fn fuzzy_eq(&self, other: &Complex) -> bool {
self.fuzzy_eq_eps(other, &FUZZY_EPSILON)
}
pure fn fuzzy_eq_eps(&self, other: &Complex,
fn fuzzy_eq_eps(&self, other: &Complex,
epsilon: &float) -> bool {
self.r.fuzzy_eq_eps(&other.r, epsilon) &&
self.i.fuzzy_eq_eps(&other.i, epsilon)

View File

@ -39,7 +39,7 @@ pub impl<T:Owned,U:Owned> DuplexStream<T, U> {
fn try_recv(&self) -> Option<U> {
self.port.try_recv()
}
pure fn peek(&self) -> bool {
fn peek(&self) -> bool {
self.port.peek()
}
}
@ -67,13 +67,13 @@ impl<T:Owned,U:Owned> GenericPort<U> for DuplexStream<T, U> {
}
impl<T:Owned,U:Owned> Peekable<U> for DuplexStream<T, U> {
pure fn peek(&self) -> bool {
fn peek(&self) -> bool {
self.port.peek()
}
}
impl<T:Owned,U:Owned> Selectable for DuplexStream<T, U> {
pure fn header(&self) -> *pipes::PacketHeader {
fn header(&self) -> *pipes::PacketHeader {
self.port.header()
}
}

View File

@ -25,10 +25,10 @@ pub struct Deque<T> {
impl<T> Container for Deque<T> {
/// Return the number of elements in the deque
pure fn len(&const self) -> uint { self.nelts }
fn len(&const self) -> uint { self.nelts }
/// Return true if the deque contains no elements
pure fn is_empty(&const self) -> bool { self.len() == 0 }
fn is_empty(&const self) -> bool { self.len() == 0 }
}
impl<T> Mutable for Deque<T> {
@ -43,7 +43,7 @@ impl<T> Mutable for Deque<T> {
pub impl<T> Deque<T> {
/// Create an empty Deque
pure fn new() -> Deque<T> {
fn new() -> Deque<T> {
Deque{nelts: 0, lo: 0, hi: 0,
elts: vec::from_fn(initial_capacity, |_| None)}
}

View File

@ -69,7 +69,7 @@ pub mod reader {
// ebml reading
impl ops::Index<uint,Doc> for Doc {
pure fn index(&self, tag: uint) -> Doc {
fn index(&self, tag: uint) -> Doc {
unsafe {
get_doc(*self, tag)
}

View File

@ -56,7 +56,7 @@ pub impl<A:Copy> Future<A> {
pub impl<A> Future<A> {
pure fn get_ref(&self) -> &'self A {
fn get_ref(&self) -> &'self A {
/*!
* Executes the future's closure and then returns a borrowed
* pointer to the result. The borrowed pointer lasts as long as

View File

@ -345,7 +345,7 @@ pub fn to_writer(wr: @io::Writer, json: &Json) {
}
/// Encodes a json value into a string
pub pure fn to_str(json: &Json) -> ~str {
pub fn to_str(json: &Json) -> ~str {
unsafe {
// ugh, should be safe
io::with_str_writer(|wr| to_writer(wr, json))
@ -947,7 +947,7 @@ impl serialize::Decoder for Decoder/&self {
}
impl Eq for Json {
pure fn eq(&self, other: &Json) -> bool {
fn eq(&self, other: &Json) -> bool {
match (self) {
&Number(f0) =>
match other { &Number(f1) => f0 == f1, _ => false },
@ -980,12 +980,12 @@ impl Eq for Json {
}
}
}
pure fn ne(&self, other: &Json) -> bool { !self.eq(other) }
fn ne(&self, other: &Json) -> bool { !self.eq(other) }
}
/// Test if two json values are less than one another
impl Ord for Json {
pure fn lt(&self, other: &Json) -> bool {
fn lt(&self, other: &Json) -> bool {
match (*self) {
Number(f0) => {
match *other {
@ -1055,18 +1055,18 @@ impl Ord for Json {
}
}
}
pure fn le(&self, other: &Json) -> bool { !(*other).lt(&(*self)) }
pure fn ge(&self, other: &Json) -> bool { !(*self).lt(other) }
pure fn gt(&self, other: &Json) -> bool { (*other).lt(&(*self)) }
fn le(&self, other: &Json) -> bool { !(*other).lt(&(*self)) }
fn ge(&self, other: &Json) -> bool { !(*self).lt(other) }
fn gt(&self, other: &Json) -> bool { (*other).lt(&(*self)) }
}
impl Eq for Error {
pure fn eq(&self, other: &Error) -> bool {
fn eq(&self, other: &Error) -> bool {
(*self).line == other.line &&
(*self).col == other.col &&
(*self).msg == other.msg
}
pure fn ne(&self, other: &Error) -> bool { !(*self).eq(other) }
fn ne(&self, other: &Error) -> bool { !(*self).eq(other) }
}
trait ToJson { fn to_json(&self) -> Json; }
@ -1191,11 +1191,11 @@ impl<A:ToJson> ToJson for Option<A> {
}
impl to_str::ToStr for Json {
pure fn to_str(&self) -> ~str { to_str(self) }
fn to_str(&self) -> ~str { to_str(self) }
}
impl to_str::ToStr for Error {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
fmt!("%u:%u: %s", self.line, self.col, *self.msg)
}
}

View File

@ -22,7 +22,7 @@ pub enum List<T> {
}
/// Create a list from a vector
pub pure fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
pub fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
}
@ -52,7 +52,7 @@ pub fn foldl<T:Copy,U>(z: T, ls: @List<U>, f: &fn(&T, &U) -> T) -> T {
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
pub pure fn find<T:Copy>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> {
pub fn find<T:Copy>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> {
let mut ls = ls;
loop {
ls = match *ls {
@ -74,7 +74,7 @@ pub fn has<T:Copy + Eq>(ls: @List<T>, elt: T) -> bool {
}
/// Returns true if the list is empty
pub pure fn is_empty<T:Copy>(ls: @List<T>) -> bool {
pub fn is_empty<T:Copy>(ls: @List<T>) -> bool {
match *ls {
Nil => true,
_ => false
@ -82,14 +82,14 @@ pub pure fn is_empty<T:Copy>(ls: @List<T>) -> bool {
}
/// Returns the length of a list
pub pure fn len<T>(ls: @List<T>) -> uint {
pub fn len<T>(ls: @List<T>) -> uint {
let mut count = 0u;
iter(ls, |_e| count += 1u);
count
}
/// Returns all but the first element of a list
pub pure fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
pub fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
match *ls {
Cons(_, tl) => return tl,
Nil => fail!(~"list empty")
@ -97,7 +97,7 @@ pub pure fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
}
/// Returns the first element of a list
pub pure fn head<T:Copy>(ls: @List<T>) -> T {
pub fn head<T:Copy>(ls: @List<T>) -> T {
match *ls {
Cons(copy hd, _) => hd,
// makes me sad
@ -106,7 +106,7 @@ pub pure fn head<T:Copy>(ls: @List<T>) -> T {
}
/// Appends one list to another
pub pure fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
pub fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
match *l {
Nil => return m,
Cons(copy x, xs) => {
@ -119,13 +119,13 @@ pub pure fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
/*
/// Push one element into the front of a list, returning a new list
/// THIS VERSION DOESN'T ACTUALLY WORK
pure fn push<T:Copy>(ll: &mut @list<T>, vv: T) {
fn push<T:Copy>(ll: &mut @list<T>, vv: T) {
ll = &mut @cons(vv, *ll)
}
*/
/// Iterate over a list
pub pure fn iter<T>(l: @List<T>, f: &fn(&T)) {
pub fn iter<T>(l: @List<T>, f: &fn(&T)) {
let mut cur = l;
loop {
cur = match *cur {
@ -139,7 +139,7 @@ pub pure fn iter<T>(l: @List<T>, f: &fn(&T)) {
}
/// Iterate over a list
pub pure fn each<T>(l: @List<T>, f: &fn(&T) -> bool) {
pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) {
let mut cur = l;
loop {
cur = match *cur {

View File

@ -19,7 +19,7 @@ struct Quad {
d: u32
}
pub pure fn md4(msg: &[u8]) -> Quad {
pub fn md4(msg: &[u8]) -> Quad {
// subtle: if orig_len is merely uint, then the code below
// which performs shifts by 32 bits or more has undefined
// results.
@ -45,7 +45,7 @@ pub pure fn md4(msg: &[u8]) -> Quad {
let mut c = 0x98badcfeu32;
let mut d = 0x10325476u32;
pure fn rot(r: int, x: u32) -> u32 {
fn rot(r: int, x: u32) -> u32 {
let r = r as u32;
(x << r) | (x >> (32u32 - r))
}
@ -103,9 +103,9 @@ pub pure fn md4(msg: &[u8]) -> Quad {
return Quad {a: a, b: b, c: c, d: d};
}
pub pure fn md4_str(msg: &[u8]) -> ~str {
pub fn md4_str(msg: &[u8]) -> ~str {
let Quad {a, b, c, d} = md4(msg);
pure fn app(a: u32, b: u32, c: u32, d: u32, f: &fn(u32)) {
fn app(a: u32, b: u32, c: u32, d: u32, f: &fn(u32)) {
f(a); f(b); f(c); f(d);
}
let mut result = ~"";
@ -121,7 +121,7 @@ pub pure fn md4_str(msg: &[u8]) -> ~str {
result
}
pub pure fn md4_text(msg: &str) -> ~str { md4_str(str::to_bytes(msg)) }
pub fn md4_text(msg: &str) -> ~str { md4_str(str::to_bytes(msg)) }
#[test]
fn test_md4() {

View File

@ -45,7 +45,7 @@ struct UserInfo {
pub type Query = ~[(~str, ~str)];
pub impl Url {
pure fn new(
fn new(
scheme: ~str,
user: Option<UserInfo>,
host: ~str,
@ -67,7 +67,7 @@ pub impl Url {
}
pub impl UserInfo {
pure fn new(user: ~str, pass: Option<~str>) -> UserInfo {
fn new(user: ~str, pass: Option<~str>) -> UserInfo {
UserInfo { user: user, pass: pass }
}
}
@ -117,7 +117,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
*
* This function is compliant with RFC 3986.
*/
pub pure fn encode(s: &str) -> ~str {
pub fn encode(s: &str) -> ~str {
// FIXME(#3722): unsafe only because encode_inner does (string) IO
unsafe {encode_inner(s, true)}
}
@ -129,7 +129,7 @@ pub pure fn encode(s: &str) -> ~str {
* This function is compliant with RFC 3986.
*/
pub pure fn encode_component(s: &str) -> ~str {
pub fn encode_component(s: &str) -> ~str {
// FIXME(#3722): unsafe only because encode_inner does (string) IO
unsafe {encode_inner(s, false)}
}
@ -177,7 +177,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
*
* This will only decode escape sequences generated by encode.
*/
pub pure fn decode(s: &str) -> ~str {
pub fn decode(s: &str) -> ~str {
// FIXME(#3722): unsafe only because decode_inner does (string) IO
unsafe {decode_inner(s, true)}
}
@ -185,7 +185,7 @@ pub pure fn decode(s: &str) -> ~str {
/**
* Decode a string encoded with percent encoding.
*/
pub pure fn decode_component(s: &str) -> ~str {
pub fn decode_component(s: &str) -> ~str {
// FIXME(#3722): unsafe only because decode_inner does (string) IO
unsafe {decode_inner(s, false)}
}
@ -297,7 +297,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> LinearMap<~str, ~[~str]> {
}
pure fn split_char_first(s: &str, c: char) -> (~str, ~str) {
fn split_char_first(s: &str, c: char) -> (~str, ~str) {
let len = str::len(s);
let mut index = len;
let mut mat = 0;
@ -324,7 +324,7 @@ pure fn split_char_first(s: &str, c: char) -> (~str, ~str) {
}
}
pure fn userinfo_from_str(uinfo: &str) -> UserInfo {
fn userinfo_from_str(uinfo: &str) -> UserInfo {
let (user, p) = split_char_first(uinfo, ':');
let pass = if str::len(p) == 0 {
None
@ -334,14 +334,14 @@ pure fn userinfo_from_str(uinfo: &str) -> UserInfo {
return UserInfo::new(user, pass);
}
pure fn userinfo_to_str(userinfo: &UserInfo) -> ~str {
fn userinfo_to_str(userinfo: &UserInfo) -> ~str {
match userinfo.pass {
Some(ref pass) => fmt!("%s:%s@", userinfo.user, *pass),
None => fmt!("%s@", userinfo.user),
}
}
pure fn query_from_str(rawquery: &str) -> Query {
fn query_from_str(rawquery: &str) -> Query {
let mut query: Query = ~[];
if str::len(rawquery) != 0 {
for str::split_char(rawquery, '&').each |p| {
@ -353,7 +353,7 @@ pure fn query_from_str(rawquery: &str) -> Query {
return query;
}
pub pure fn query_to_str(query: &Query) -> ~str {
pub fn query_to_str(query: &Query) -> ~str {
unsafe {
// FIXME(#3722): unsafe only because decode_inner does (string) IO
let mut strvec = ~[];
@ -372,7 +372,7 @@ pub pure fn query_to_str(query: &Query) -> ~str {
}
// returns the scheme and the rest of the url, or a parsing error
pub pure fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> {
pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> {
for str::each_chari(rawurl) |i,c| {
match c {
'A' .. 'Z' | 'a' .. 'z' => loop,
@ -406,7 +406,7 @@ enum Input {
}
// returns userinfo, host, port, and unparsed part, or an error
pure fn get_authority(rawurl: &str) ->
fn get_authority(rawurl: &str) ->
Result<(Option<UserInfo>, ~str, Option<~str>, ~str), ~str> {
if !str::starts_with(rawurl, ~"//") {
// there is no authority.
@ -534,7 +534,7 @@ pure fn get_authority(rawurl: &str) ->
let end = end; // make end immutable so it can be captured
let host_is_end_plus_one: &pure fn() -> bool = || {
let host_is_end_plus_one: &fn() -> bool = || {
end+1 == len
&& !['?', '#', '/'].contains(&(rawurl[end] as char))
};
@ -573,7 +573,7 @@ pure fn get_authority(rawurl: &str) ->
// returns the path and unparsed part of url, or an error
pure fn get_path(rawurl: &str, authority: bool) ->
fn get_path(rawurl: &str, authority: bool) ->
Result<(~str, ~str), ~str> {
let len = str::len(rawurl);
let mut end = len;
@ -604,7 +604,7 @@ pure fn get_path(rawurl: &str, authority: bool) ->
}
// returns the parsed query and the fragment, if present
pure fn get_query_fragment(rawurl: &str) ->
fn get_query_fragment(rawurl: &str) ->
Result<(Query, Option<~str>), ~str> {
if !str::starts_with(rawurl, ~"?") {
if str::starts_with(rawurl, ~"#") {
@ -636,7 +636,7 @@ pure fn get_query_fragment(rawurl: &str) ->
*
*/
pub pure fn from_str(rawurl: &str) -> Result<Url, ~str> {
pub fn from_str(rawurl: &str) -> Result<Url, ~str> {
// scheme
let (scheme, rest) = match get_scheme(rawurl) {
Ok(val) => val,
@ -666,7 +666,7 @@ pub pure fn from_str(rawurl: &str) -> Result<Url, ~str> {
}
impl FromStr for Url {
pure fn from_str(s: &str) -> Option<Url> {
fn from_str(s: &str) -> Option<Url> {
match from_str(s) {
Ok(url) => Some(url),
Err(_) => None
@ -689,7 +689,7 @@ impl FromStr for Url {
* result in just "http://somehost.com".
*
*/
pub pure fn to_str(url: &Url) -> ~str {
pub fn to_str(url: &Url) -> ~str {
let user = match url.user {
Some(ref user) => userinfo_to_str(user),
None => ~"",
@ -716,13 +716,13 @@ pub pure fn to_str(url: &Url) -> ~str {
}
impl to_str::ToStr for Url {
pub pure fn to_str(&self) -> ~str {
pub fn to_str(&self) -> ~str {
to_str(self)
}
}
impl to_bytes::IterBytes for Url {
pure fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
self.to_str().iter_bytes(lsb0, f)
}
}

View File

@ -31,7 +31,7 @@ pub mod util {
den: int,
}
pub pure fn rational_leq(x: Rational, y: Rational) -> bool {
pub fn rational_leq(x: Rational, y: Rational) -> bool {
// NB: Uses the fact that rationals have positive denominators WLOG:
x.num * y.den <= y.num * x.den
@ -74,7 +74,7 @@ pub mod chained {
}
priv impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> {
pure fn search_rem(&self, k: &K, h: uint, idx: uint,
fn search_rem(&self, k: &K, h: uint, idx: uint,
e_root: @Entry<K,V>) -> SearchResult<K,V> {
let mut e0 = e_root;
let mut comp = 1u; // for logging
@ -100,7 +100,7 @@ pub mod chained {
};
}
pure fn search_tbl(&self, k: &K, h: uint) -> SearchResult<K,V> {
fn search_tbl(&self, k: &K, h: uint) -> SearchResult<K,V> {
let idx = h % vec::uniq_len(&const self.chains);
match copy self.chains[idx] {
None => {
@ -134,7 +134,7 @@ pub mod chained {
}
pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> {
pure fn each_entry(&self, blk: &fn(@Entry<K,V>) -> bool) {
fn each_entry(&self, blk: &fn(@Entry<K,V>) -> bool) {
// n.b. we can't use vec::iter() here because self.chains
// is stored in a mutable location.
let mut i = 0u, n = vec::uniq_len(&const self.chains);
@ -161,12 +161,12 @@ pub mod chained {
}
impl<K:Eq + IterBytes + Hash,V> Container for HashMap_<K, V> {
pure fn len(&const self) -> uint { self.count }
pure fn is_empty(&const self) -> bool { self.count == 0 }
fn len(&const self) -> uint { self.count }
fn is_empty(&const self) -> bool { self.count == 0 }
}
pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> {
pure fn contains_key(@self, k: &K) -> bool {
fn contains_key(@self, k: &K) -> bool {
let hash = k.hash_keyed(0,0) as uint;
match self.search_tbl(k, hash) {
NotFound => false,
@ -234,23 +234,23 @@ pub mod chained {
}
}
pure fn each(@self, blk: &fn(key: &K, value: &V) -> bool) {
fn each(@self, blk: &fn(key: &K, value: &V) -> bool) {
for self.each_entry |entry| {
if !blk(&entry.key, &entry.value) { break; }
}
}
pure fn each_key(@self, blk: &fn(key: &K) -> bool) {
fn each_key(@self, blk: &fn(key: &K) -> bool) {
self.each(|k, _v| blk(k))
}
pure fn each_value(@self, blk: &fn(value: &V) -> bool) {
fn each_value(@self, blk: &fn(value: &V) -> bool) {
self.each(|_k, v| blk(v))
}
}
pub impl<K:Eq + IterBytes + Hash + Copy,V:Copy> HashMap_<K, V> {
pure fn find(&self, k: &K) -> Option<V> {
fn find(&self, k: &K) -> Option<V> {
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
NotFound => None,
FoundFirst(_, entry) => Some(entry.value),
@ -314,7 +314,7 @@ pub mod chained {
return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1));
}
pure fn get(&self, k: &K) -> V {
fn get(&self, k: &K) -> V {
let opt_v = self.find(k);
if opt_v.is_none() {
fail!(fmt!("Key not found in table: %?", k));
@ -348,7 +348,7 @@ pub mod chained {
impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> ToStr
for HashMap_<K, V> {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
unsafe {
// Meh -- this should be safe
do io::with_str_writer |wr| { self.to_writer(wr) }
@ -358,7 +358,7 @@ pub mod chained {
impl<K:Eq + IterBytes + Hash + Copy,V:Copy> ops::Index<K, V>
for HashMap_<K, V> {
pure fn index(&self, k: K) -> V {
fn index(&self, k: K) -> V {
self.get(&k)
}
}
@ -391,7 +391,7 @@ pub fn set_add<K:Eq + IterBytes + Hash + Const + Copy>(set: Set<K>, key: K)
}
/// Convert a set into a vector.
pub pure fn vec_from_set<T:Eq + IterBytes + Hash + Copy>(s: Set<T>) -> ~[T] {
pub fn vec_from_set<T:Eq + IterBytes + Hash + Copy>(s: Set<T>) -> ~[T] {
do vec::build_sized(s.len()) |push| {
for s.each_key() |&k| {
push(k);
@ -422,8 +422,8 @@ mod tests {
#[test]
fn test_simple() {
debug!("*** starting test_simple");
pure fn eq_uint(x: &uint, y: &uint) -> bool { *x == *y }
pure fn uint_id(x: &uint) -> uint { *x }
fn eq_uint(x: &uint, y: &uint) -> bool { *x == *y }
fn uint_id(x: &uint) -> uint { *x }
debug!("uint -> uint");
let hm_uu: HashMap<uint, uint> =
HashMap::<uint, uint>();
@ -491,8 +491,8 @@ mod tests {
fn test_growth() {
debug!("*** starting test_growth");
let num_to_insert: uint = 64u;
pure fn eq_uint(x: &uint, y: &uint) -> bool { *x == *y }
pure fn uint_id(x: &uint) -> uint { *x }
fn eq_uint(x: &uint, y: &uint) -> bool { *x == *y }
fn uint_id(x: &uint) -> uint { *x }
debug!("uint -> uint");
let hm_uu: HashMap<uint, uint> =
HashMap::<uint, uint>();

View File

@ -31,16 +31,16 @@ impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
/// Visit all values in the underlying vector.
///
/// The values are **not** visited in order.
pure fn each(&self, f: &fn(&T) -> bool) { self.data.each(f) }
pure fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
fn each(&self, f: &fn(&T) -> bool) { self.data.each(f) }
fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
}
impl<T:Ord> Container for PriorityQueue<T> {
/// Returns the length of the queue
pure fn len(&const self) -> uint { vec::uniq_len(&const self.data) }
fn len(&const self) -> uint { vec::uniq_len(&const self.data) }
/// Returns true if a queue contains no elements
pure fn is_empty(&const self) -> bool { self.len() == 0 }
fn is_empty(&const self) -> bool { self.len() == 0 }
}
impl<T:Ord> Mutable for PriorityQueue<T> {
@ -50,15 +50,15 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
pub impl <T:Ord> PriorityQueue<T> {
/// Returns the greatest item in the queue - fails if empty
pure fn top(&self) -> &'self T { &self.data[0] }
fn top(&self) -> &'self T { &self.data[0] }
/// Returns the greatest item in the queue - None if empty
pure fn maybe_top(&self) -> Option<&'self T> {
fn maybe_top(&self) -> Option<&'self T> {
if self.is_empty() { None } else { Some(self.top()) }
}
/// Returns the number of elements the queue can hold without reallocating
pure fn capacity(&self) -> uint { vec::capacity(&self.data) }
fn capacity(&self) -> uint { vec::capacity(&self.data) }
fn reserve(&mut self, n: uint) { vec::reserve(&mut self.data, n) }
@ -102,11 +102,11 @@ pub impl <T:Ord> PriorityQueue<T> {
}
/// Consume the PriorityQueue and return the underlying vector
pure fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v }
fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v }
/// Consume the PriorityQueue and return a vector in sorted
/// (ascending) order
pure fn to_sorted_vec(self) -> ~[T] {
fn to_sorted_vec(self) -> ~[T] {
let mut q = self;
let mut end = q.len();
while end > 1 {
@ -118,10 +118,10 @@ pub impl <T:Ord> PriorityQueue<T> {
}
/// Create an empty PriorityQueue
pure fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }
fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }
/// Create a PriorityQueue from a vector (heapify)
pure fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
let mut q = PriorityQueue{data: xs,};
let mut n = q.len() / 2;
while n > 0 {

View File

@ -47,7 +47,7 @@ pub type Rope = node::Root;
*/
/// Create an empty rope
pub pure fn empty() -> Rope {
pub fn empty() -> Rope {
return node::Empty;
}
@ -491,7 +491,7 @@ pub mod iterator {
*
* Constant time.
*/
pub pure fn height(rope: Rope) -> uint {
pub fn height(rope: Rope) -> uint {
match (rope) {
node::Empty => return 0u,
node::Content(x) => return node::height(x)
@ -507,7 +507,7 @@ pub pure fn height(rope: Rope) -> uint {
*
* Constant time.
*/
pub pure fn char_len(rope: Rope) -> uint {
pub fn char_len(rope: Rope) -> uint {
match (rope) {
node::Empty => return 0u,
node::Content(x) => return node::char_len(x)
@ -521,7 +521,7 @@ pub pure fn char_len(rope: Rope) -> uint {
*
* Constant time.
*/
pub pure fn byte_len(rope: Rope) -> uint {
pub fn byte_len(rope: Rope) -> uint {
match (rope) {
node::Empty => return 0u,
node::Content(x) => return node::byte_len(x)
@ -761,7 +761,7 @@ pub mod node {
}
}
pub pure fn byte_len(node: @Node) -> uint {
pub fn byte_len(node: @Node) -> uint {
//FIXME (#2744): Could we do this without the pattern-matching?
match (*node) {
Leaf(y) => y.byte_len,
@ -769,7 +769,7 @@ pub mod node {
}
}
pub pure fn char_len(node: @Node) -> uint {
pub fn char_len(node: @Node) -> uint {
match (*node) {
Leaf(y) => y.char_len,
Concat(ref y) => y.char_len
@ -1050,7 +1050,7 @@ pub mod node {
})
}
pub pure fn height(node: @Node) -> uint {
pub fn height(node: @Node) -> uint {
match (*node) {
Leaf(_) => 0u,
Concat(ref x) => x.height,
@ -1131,7 +1131,7 @@ pub mod node {
* proportional to the height of the rope + the (bounded)
* length of the largest leaf.
*/
pub pure fn char_at(node: @Node, pos: uint) -> char {
pub fn char_at(node: @Node, pos: uint) -> char {
let mut node = node;
let mut pos = pos;
loop {

View File

@ -27,7 +27,7 @@ pub enum Identifier {
impl cmp::Ord for Identifier {
#[inline(always)]
pure fn lt(&self, other: &Identifier) -> bool {
fn lt(&self, other: &Identifier) -> bool {
match (self, other) {
(&Numeric(a), &Numeric(b)) => a < b,
(&Numeric(_), _) => true,
@ -36,22 +36,22 @@ impl cmp::Ord for Identifier {
}
}
#[inline(always)]
pure fn le(&self, other: &Identifier) -> bool {
fn le(&self, other: &Identifier) -> bool {
! (other < self)
}
#[inline(always)]
pure fn gt(&self, other: &Identifier) -> bool {
fn gt(&self, other: &Identifier) -> bool {
other < self
}
#[inline(always)]
pure fn ge(&self, other: &Identifier) -> bool {
fn ge(&self, other: &Identifier) -> bool {
! (self < other)
}
}
impl ToStr for Identifier {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
match self {
&Numeric(n) => n.to_str(),
&AlphaNumeric(ref s) => s.to_str()
@ -71,7 +71,7 @@ pub struct Version {
impl ToStr for Version {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
let s = fmt!("%u.%u.%u", self.major, self.minor, self.patch);
let s = if self.pre.is_empty() {
s
@ -88,7 +88,7 @@ impl ToStr for Version {
impl cmp::Ord for Version {
#[inline(always)]
pure fn lt(&self, other: &Version) -> bool {
fn lt(&self, other: &Version) -> bool {
self.major < other.major ||
@ -121,15 +121,15 @@ impl cmp::Ord for Version {
}
#[inline(always)]
pure fn le(&self, other: &Version) -> bool {
fn le(&self, other: &Version) -> bool {
! (other < self)
}
#[inline(always)]
pure fn gt(&self, other: &Version) -> bool {
fn gt(&self, other: &Version) -> bool {
other < self
}
#[inline(always)]
pure fn ge(&self, other: &Version) -> bool {
fn ge(&self, other: &Version) -> bool {
! (self < other)
}
}

View File

@ -24,7 +24,7 @@ pub struct SmallIntMap<T> {
impl<V> BaseIter<(uint, &'self V)> for SmallIntMap<V> {
/// Visit all key-value pairs in order
pure fn each(&self, it: &fn(&(uint, &'self V)) -> bool) {
fn each(&self, it: &fn(&(uint, &'self V)) -> bool) {
for uint::range(0, self.v.len()) |i| {
match self.v[i] {
Some(ref elt) => if !it(&(i, elt)) { break },
@ -33,12 +33,12 @@ impl<V> BaseIter<(uint, &'self V)> for SmallIntMap<V> {
}
}
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> {
/// Visit all key-value pairs in reverse order
pure fn each_reverse(&self, it: &fn(&(uint, &'self V)) -> bool) {
fn each_reverse(&self, it: &fn(&(uint, &'self V)) -> bool) {
for uint::range_rev(self.v.len(), 0) |i| {
match self.v[i - 1] {
Some(ref elt) => if !it(&(i - 1, elt)) { break },
@ -50,7 +50,7 @@ impl<V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> {
impl<V> Container for SmallIntMap<V> {
/// Return the number of elements in the map
pure fn len(&const self) -> uint {
fn len(&const self) -> uint {
let mut sz = 0;
for uint::range(0, vec::uniq_len(&const self.v)) |i| {
match self.v[i] {
@ -62,7 +62,7 @@ impl<V> Container for SmallIntMap<V> {
}
/// Return true if the map contains no elements
pure fn is_empty(&const self) -> bool { self.len() == 0 }
fn is_empty(&const self) -> bool { self.len() == 0 }
}
impl<V> Mutable for SmallIntMap<V> {
@ -72,17 +72,17 @@ impl<V> Mutable for SmallIntMap<V> {
impl<V> Map<uint, V> for SmallIntMap<V> {
/// Return true if the map contains a value for the specified key
pure fn contains_key(&self, key: &uint) -> bool {
fn contains_key(&self, key: &uint) -> bool {
self.find(key).is_some()
}
/// Visit all keys in order
pure fn each_key(&self, blk: &fn(key: &uint) -> bool) {
fn each_key(&self, blk: &fn(key: &uint) -> bool) {
self.each(|&(k, _)| blk(&k))
}
/// Visit all values in order
pure fn each_value(&self, blk: &fn(value: &V) -> bool) {
fn each_value(&self, blk: &fn(value: &V) -> bool) {
self.each(|&(_, v)| blk(v))
}
@ -97,7 +97,7 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
}
/// Iterate over the map and mutate the contained values
pure fn find(&self, key: &uint) -> Option<&'self V> {
fn find(&self, key: &uint) -> Option<&'self V> {
if *key < self.v.len() {
match self.v[*key] {
Some(ref value) => Some(value),
@ -135,9 +135,9 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
pub impl<V> SmallIntMap<V> {
/// Create an empty SmallIntMap
pure fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
pure fn get(&self, key: &uint) -> &'self V {
fn get(&self, key: &uint) -> &'self V {
self.find(key).expect("key not present")
}
}

View File

@ -16,7 +16,7 @@ use core::util;
use core::vec::{len, push};
use core::vec;
type Le<T> = &'self pure fn(v1: &T, v2: &T) -> bool;
type Le<T> = &'self fn(v1: &T, v2: &T) -> bool;
/**
* Merge sort. Returns a new vector containing the sorted list.
@ -24,7 +24,7 @@ type Le<T> = &'self pure fn(v1: &T, v2: &T) -> bool;
* Has worst case O(n log n) performance, best case O(n), but
* is not space efficient. This is a stable sort.
*/
pub pure fn merge_sort<T:Copy>(v: &[const T], le: Le<T>) -> ~[T] {
pub fn merge_sort<T:Copy>(v: &[const T], le: Le<T>) -> ~[T] {
type Slice = (uint, uint);
unsafe {return merge_sort_(v, (0u, len(v)), le);}
@ -259,7 +259,7 @@ fn reverse_slice<T>(v: &mut [T], start: uint, end:uint) {
}
}
pure fn min_run_length(n: uint) -> uint {
fn min_run_length(n: uint) -> uint {
let mut n = n;
let mut r = 0; // becomes 1 if any 1 bits are shifted off
@ -290,7 +290,7 @@ fn count_run_ascending<T:Copy + Ord>(array: &mut [T]) -> uint {
return run;
}
pure fn gallop_left<T:Copy + Ord>(key: &const T, array: &[const T],
fn gallop_left<T:Copy + Ord>(key: &const T, array: &[const T],
hint: uint) -> uint {
let size = array.len();
fail_unless!(size != 0 && hint < size);
@ -339,7 +339,7 @@ pure fn gallop_left<T:Copy + Ord>(key: &const T, array: &[const T],
return ofs;
}
pure fn gallop_right<T:Copy + Ord>(key: &const T, array: &[const T],
fn gallop_right<T:Copy + Ord>(key: &const T, array: &[const T],
hint: uint) -> uint {
let size = array.len();
fail_unless!(size != 0 && hint < size);
@ -779,7 +779,7 @@ mod test_qsort {
pub fn check_sort(v1: &mut [int], v2: &mut [int]) {
let len = vec::len::<int>(v1);
pure fn leual(a: &int, b: &int) -> bool { *a <= *b }
fn leual(a: &int, b: &int) -> bool { *a <= *b }
quick_sort::<int>(v1, leual);
let mut i = 0u;
while i < len {
@ -844,7 +844,7 @@ mod tests {
pub fn check_sort(v1: &[int], v2: &[int]) {
let len = vec::len::<int>(v1);
pub pure fn le(a: &int, b: &int) -> bool { *a <= *b }
pub fn le(a: &int, b: &int) -> bool { *a <= *b }
let f = le;
let v3 = merge_sort::<int>(v1, f);
let mut i = 0u;
@ -874,7 +874,7 @@ mod tests {
#[test]
pub fn test_merge_sort_mutable() {
pub pure fn le(a: &int, b: &int) -> bool { *a <= *b }
pub fn le(a: &int, b: &int) -> bool { *a <= *b }
let mut v1 = ~[3, 2, 1];
let v2 = merge_sort(v1, le);
fail_unless!(v2 == ~[1, 2, 3]);
@ -883,7 +883,7 @@ mod tests {
#[test]
pub fn test_merge_sort_stability() {
// tjc: funny that we have to use parens
pure fn ile(x: &(&'static str), y: &(&'static str)) -> bool
fn ile(x: &(&'static str), y: &(&'static str)) -> bool
{
unsafe // to_lower is not pure...
{
@ -917,16 +917,16 @@ mod test_tim_sort {
}
impl Ord for CVal {
pure fn lt(&self, other: &CVal) -> bool {
fn lt(&self, other: &CVal) -> bool {
unsafe {
let rng = rand::Rng();
if rng.gen_float() > 0.995 { fail!(~"It's happening!!!"); }
}
(*self).val < other.val
}
pure fn le(&self, other: &CVal) -> bool { (*self).val <= other.val }
pure fn gt(&self, other: &CVal) -> bool { (*self).val > other.val }
pure fn ge(&self, other: &CVal) -> bool { (*self).val >= other.val }
fn le(&self, other: &CVal) -> bool { (*self).val <= other.val }
fn gt(&self, other: &CVal) -> bool { (*self).val > other.val }
fn ge(&self, other: &CVal) -> bool { (*self).val >= other.val }
}
fn check_sort(v1: &mut [int], v2: &mut [int]) {
@ -982,10 +982,10 @@ mod test_tim_sort {
struct DVal { val: uint }
impl Ord for DVal {
pure fn lt(&self, _x: &DVal) -> bool { true }
pure fn le(&self, _x: &DVal) -> bool { true }
pure fn gt(&self, _x: &DVal) -> bool { true }
pure fn ge(&self, _x: &DVal) -> bool { true }
fn lt(&self, _x: &DVal) -> bool { true }
fn le(&self, _x: &DVal) -> bool { true }
fn gt(&self, _x: &DVal) -> bool { true }
fn ge(&self, _x: &DVal) -> bool { true }
}
#[test]
@ -1206,16 +1206,16 @@ mod big_tests {
}
impl Ord for LVal/&self {
pure fn lt(&self, other: &'a LVal/&self) -> bool {
fn lt(&self, other: &'a LVal/&self) -> bool {
(*self).val < other.val
}
pure fn le(&self, other: &'a LVal/&self) -> bool {
fn le(&self, other: &'a LVal/&self) -> bool {
(*self).val <= other.val
}
pure fn gt(&self, other: &'a LVal/&self) -> bool {
fn gt(&self, other: &'a LVal/&self) -> bool {
(*self).val > other.val
}
pure fn ge(&self, other: &'a LVal/&self) -> bool {
fn ge(&self, other: &'a LVal/&self) -> bool {
(*self).val >= other.val
}
}

View File

@ -53,7 +53,7 @@ pub enum TestName {
DynTestName(~str)
}
impl ToStr for TestName {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
match self {
&StaticTestName(s) => s.to_str(),
&DynTestName(s) => s.to_str()
@ -536,7 +536,7 @@ pub fn filter_tests(
};
// Sort the tests alphabetically
pure fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool {
fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool {
str::le(t1.desc.name.to_str(), t2.desc.name.to_str())
}
sort::quick_sort(filtered, lteq);

View File

@ -51,27 +51,27 @@ pub struct Timespec { sec: i64, nsec: i32 }
* nsec: 800_000_000_i32 }`.
*/
pub impl Timespec {
pure fn new(sec: i64, nsec: i32) -> Timespec {
fn new(sec: i64, nsec: i32) -> Timespec {
fail_unless!(nsec >= 0 && nsec < NSEC_PER_SEC);
Timespec { sec: sec, nsec: nsec }
}
}
impl Eq for Timespec {
pure fn eq(&self, other: &Timespec) -> bool {
fn eq(&self, other: &Timespec) -> bool {
self.sec == other.sec && self.nsec == other.nsec
}
pure fn ne(&self, other: &Timespec) -> bool { !self.eq(other) }
fn ne(&self, other: &Timespec) -> bool { !self.eq(other) }
}
impl Ord for Timespec {
pure fn lt(&self, other: &Timespec) -> bool {
fn lt(&self, other: &Timespec) -> bool {
self.sec < other.sec ||
(self.sec == other.sec && self.nsec < other.nsec)
}
pure fn le(&self, other: &Timespec) -> bool { !other.lt(self) }
pure fn ge(&self, other: &Timespec) -> bool { !self.lt(other) }
pure fn gt(&self, other: &Timespec) -> bool { !self.le(other) }
fn le(&self, other: &Timespec) -> bool { !other.lt(self) }
fn ge(&self, other: &Timespec) -> bool { !self.lt(other) }
fn gt(&self, other: &Timespec) -> bool { !self.le(other) }
}
/**
@ -133,7 +133,7 @@ pub struct Tm {
}
impl Eq for Tm {
pure fn eq(&self, other: &Tm) -> bool {
fn eq(&self, other: &Tm) -> bool {
self.tm_sec == (*other).tm_sec &&
self.tm_min == (*other).tm_min &&
self.tm_hour == (*other).tm_hour &&
@ -147,10 +147,10 @@ impl Eq for Tm {
self.tm_zone == (*other).tm_zone &&
self.tm_nsec == (*other).tm_nsec
}
pure fn ne(&self, other: &Tm) -> bool { !self.eq(other) }
fn ne(&self, other: &Tm) -> bool { !self.eq(other) }
}
pub pure fn empty_tm() -> Tm {
pub fn empty_tm() -> Tm {
Tm {
tm_sec: 0_i32,
tm_min: 0_i32,
@ -198,14 +198,14 @@ pub fn now() -> Tm {
}
/// Parses the time from the string according to the format string.
pub pure fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
// unsafe only because do_strptime is annoying to make pure
// (it does IO with a str_reader)
unsafe {do_strptime(s, format)}
}
/// Formats the time according to the format string.
pub pure fn strftime(format: &str, tm: &Tm) -> ~str {
pub fn strftime(format: &str, tm: &Tm) -> ~str {
// unsafe only because do_strftime is annoying to make pure
// (it does IO with a str_reader)
unsafe { do_strftime(format, tm) }
@ -239,10 +239,10 @@ pub impl Tm {
* Return a string of the current time in the form
* "Thu Jan 1 00:00:00 1970".
*/
pure fn ctime(&self) -> ~str { self.strftime(~"%c") }
fn ctime(&self) -> ~str { self.strftime(~"%c") }
/// Formats the time according to the format string.
pure fn strftime(&self, format: &str) -> ~str {
fn strftime(&self, format: &str) -> ~str {
strftime(format, self)
}
@ -252,7 +252,7 @@ pub impl Tm {
* local: "Thu, 22 Mar 2012 07:53:18 PST"
* utc: "Thu, 22 Mar 2012 14:53:18 UTC"
*/
pure fn rfc822(&self) -> ~str {
fn rfc822(&self) -> ~str {
if self.tm_gmtoff == 0_i32 {
self.strftime(~"%a, %d %b %Y %T GMT")
} else {
@ -266,7 +266,7 @@ pub impl Tm {
* local: "Thu, 22 Mar 2012 07:53:18 -0700"
* utc: "Thu, 22 Mar 2012 14:53:18 -0000"
*/
pure fn rfc822z(&self) -> ~str {
fn rfc822z(&self) -> ~str {
self.strftime(~"%a, %d %b %Y %T %z")
}
@ -276,7 +276,7 @@ pub impl Tm {
* local: "2012-02-22T07:53:18-07:00"
* utc: "2012-02-22T14:53:18Z"
*/
pure fn rfc3339(&self) -> ~str {
fn rfc3339(&self) -> ~str {
if self.tm_gmtoff == 0_i32 {
self.strftime(~"%Y-%m-%dT%H:%M:%SZ")
} else {

View File

@ -36,7 +36,7 @@ pub struct TreeMap<K, V> {
}
impl<K: Eq + TotalOrd, V: Eq> Eq for TreeMap<K, V> {
pure fn eq(&self, other: &TreeMap<K, V>) -> bool {
fn eq(&self, other: &TreeMap<K, V>) -> bool {
if self.len() != other.len() {
false
} else {
@ -53,11 +53,11 @@ impl<K: Eq + TotalOrd, V: Eq> Eq for TreeMap<K, V> {
true
}
}
pure fn ne(&self, other: &TreeMap<K, V>) -> bool { !self.eq(other) }
fn ne(&self, other: &TreeMap<K, V>) -> bool { !self.eq(other) }
}
// Lexicographical comparison
pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
b: &TreeMap<K, V>) -> bool {
let mut x = a.iter();
let mut y = b.iter();
@ -77,21 +77,21 @@ pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> {
#[inline(always)]
pure fn lt(&self, other: &TreeMap<K, V>) -> bool { lt(self, other) }
fn lt(&self, other: &TreeMap<K, V>) -> bool { lt(self, other) }
#[inline(always)]
pure fn le(&self, other: &TreeMap<K, V>) -> bool { !lt(other, self) }
fn le(&self, other: &TreeMap<K, V>) -> bool { !lt(other, self) }
#[inline(always)]
pure fn ge(&self, other: &TreeMap<K, V>) -> bool { !lt(self, other) }
fn ge(&self, other: &TreeMap<K, V>) -> bool { !lt(self, other) }
#[inline(always)]
pure fn gt(&self, other: &TreeMap<K, V>) -> bool { lt(other, self) }
fn gt(&self, other: &TreeMap<K, V>) -> bool { lt(other, self) }
}
impl<'self, K: TotalOrd, V> BaseIter<(&'self K, &'self V)> for TreeMap<K, V> {
/// Visit all key-value pairs in order
pure fn each(&self, f: &fn(&(&'self K, &'self V)) -> bool) {
fn each(&self, f: &fn(&(&'self K, &'self V)) -> bool) {
each(&self.root, f)
}
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<'self, K: TotalOrd, V>
@ -99,17 +99,17 @@ impl<'self, K: TotalOrd, V>
for TreeMap<K, V>
{
/// Visit all key-value pairs in reverse order
pure fn each_reverse(&self, f: &fn(&(&'self K, &'self V)) -> bool) {
fn each_reverse(&self, f: &fn(&(&'self K, &'self V)) -> bool) {
each_reverse(&self.root, f);
}
}
impl<K: TotalOrd, V> Container for TreeMap<K, V> {
/// Return the number of elements in the map
pure fn len(&const self) -> uint { self.length }
fn len(&const self) -> uint { self.length }
/// Return true if the map contains no elements
pure fn is_empty(&const self) -> bool { self.root.is_none() }
fn is_empty(&const self) -> bool { self.root.is_none() }
}
impl<K: TotalOrd, V> Mutable for TreeMap<K, V> {
@ -122,15 +122,15 @@ impl<K: TotalOrd, V> Mutable for TreeMap<K, V> {
impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
/// Return true if the map contains a value for the specified key
pure fn contains_key(&self, key: &K) -> bool {
fn contains_key(&self, key: &K) -> bool {
self.find(key).is_some()
}
/// Visit all keys in order
pure fn each_key(&self, f: &fn(&K) -> bool) { self.each(|&(k, _)| f(k)) }
fn each_key(&self, f: &fn(&K) -> bool) { self.each(|&(k, _)| f(k)) }
/// Visit all values in order
pure fn each_value(&self, f: &fn(&V) -> bool) {
fn each_value(&self, f: &fn(&V) -> bool) {
self.each(|&(_, v)| f(v))
}
@ -140,7 +140,7 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
}
/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&'self V> {
fn find(&self, key: &K) -> Option<&'self V> {
let mut current: &'self Option<~TreeNode<K, V>> = &self.root;
loop {
match *current {
@ -176,21 +176,21 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
pub impl<K: TotalOrd, V> TreeMap<K, V> {
/// Create an empty TreeMap
pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
/// Visit all keys in reverse order
pure fn each_key_reverse(&self, f: &fn(&K) -> bool) {
fn each_key_reverse(&self, f: &fn(&K) -> bool) {
self.each_reverse(|&(k, _)| f(k))
}
/// Visit all values in reverse order
pure fn each_value_reverse(&self, f: &fn(&V) -> bool) {
fn each_value_reverse(&self, f: &fn(&V) -> bool) {
self.each_reverse(|&(_, v)| f(v))
}
/// Get a lazy iterator over the key-value pairs in the map.
/// Requires that it be frozen (immutable).
pure fn iter(&self) -> TreeMapIterator/&self<K, V> {
fn iter(&self) -> TreeMapIterator/&self<K, V> {
TreeMapIterator{stack: ~[], node: &self.root}
}
}
@ -242,45 +242,45 @@ pub struct TreeSet<T> {
impl<T: TotalOrd> BaseIter<T> for TreeSet<T> {
/// Visit all values in order
#[inline(always)]
pure fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<T: TotalOrd> ReverseIter<T> for TreeSet<T> {
/// Visit all values in reverse order
#[inline(always)]
pure fn each_reverse(&self, f: &fn(&T) -> bool) {
fn each_reverse(&self, f: &fn(&T) -> bool) {
self.map.each_key_reverse(f)
}
}
impl<T: Eq + TotalOrd> Eq for TreeSet<T> {
#[inline(always)]
pure fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
#[inline(always)]
pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
}
impl<T: Ord + TotalOrd> Ord for TreeSet<T> {
#[inline(always)]
pure fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map }
fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map }
#[inline(always)]
pure fn le(&self, other: &TreeSet<T>) -> bool { self.map <= other.map }
fn le(&self, other: &TreeSet<T>) -> bool { self.map <= other.map }
#[inline(always)]
pure fn ge(&self, other: &TreeSet<T>) -> bool { self.map >= other.map }
fn ge(&self, other: &TreeSet<T>) -> bool { self.map >= other.map }
#[inline(always)]
pure fn gt(&self, other: &TreeSet<T>) -> bool { self.map > other.map }
fn gt(&self, other: &TreeSet<T>) -> bool { self.map > other.map }
}
impl<T: TotalOrd> Container for TreeSet<T> {
/// Return the number of elements in the set
#[inline(always)]
pure fn len(&const self) -> uint { self.map.len() }
fn len(&const self) -> uint { self.map.len() }
/// Return true if the set contains no elements
#[inline(always)]
pure fn is_empty(&const self) -> bool { self.map.is_empty() }
fn is_empty(&const self) -> bool { self.map.is_empty() }
}
impl<T: TotalOrd> Mutable for TreeSet<T> {
@ -292,7 +292,7 @@ impl<T: TotalOrd> Mutable for TreeSet<T> {
impl<T: TotalOrd> Set<T> for TreeSet<T> {
/// Return true if the set contains a value
#[inline(always)]
pure fn contains(&self, value: &T) -> bool {
fn contains(&self, value: &T) -> bool {
self.map.contains_key(value)
}
@ -308,7 +308,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure fn is_disjoint(&self, other: &TreeSet<T>) -> bool {
fn is_disjoint(&self, other: &TreeSet<T>) -> bool {
let mut x = self.iter();
let mut y = other.iter();
unsafe { // purity workaround
@ -329,12 +329,12 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
/// Return true if the set is a subset of another
#[inline(always)]
pure fn is_subset(&self, other: &TreeSet<T>) -> bool {
fn is_subset(&self, other: &TreeSet<T>) -> bool {
other.is_superset(self)
}
/// Return true if the set is a superset of another
pure fn is_superset(&self, other: &TreeSet<T>) -> bool {
fn is_superset(&self, other: &TreeSet<T>) -> bool {
let mut x = self.iter();
let mut y = other.iter();
unsafe { // purity workaround
@ -361,7 +361,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the difference
pure fn difference(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
fn difference(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -393,7 +393,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the symmetric difference
pure fn symmetric_difference(&self, other: &TreeSet<T>,
fn symmetric_difference(&self, other: &TreeSet<T>,
f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -433,7 +433,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the intersection
pure fn intersection(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
fn intersection(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -460,7 +460,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the union
pure fn union(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
fn union(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -501,12 +501,12 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
pub impl <T: TotalOrd> TreeSet<T> {
/// Create an empty TreeSet
#[inline(always)]
pure fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
/// Get a lazy iterator over the values in the set.
/// Requires that it be frozen (immutable).
#[inline(always)]
pure fn iter(&self) -> TreeSetIterator/&self<T> {
fn iter(&self) -> TreeSetIterator/&self<T> {
TreeSetIterator{iter: self.map.iter()}
}
}
@ -542,12 +542,12 @@ struct TreeNode<K, V> {
pub impl<K: TotalOrd, V> TreeNode<K, V> {
#[inline(always)]
pure fn new(key: K, value: V) -> TreeNode<K, V> {
fn new(key: K, value: V) -> TreeNode<K, V> {
TreeNode{key: key, value: value, left: None, right: None, level: 1}
}
}
pure fn each<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
fn each<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
f: &fn(&(&'r K, &'r V)) -> bool) {
for node.each |x| {
each(&x.left, f);
@ -555,7 +555,7 @@ pure fn each<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
}
}
pure fn each_reverse<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
fn each_reverse<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
f: &fn(&(&'r K, &'r V)) -> bool) {
for node.each |x| {
each_reverse(&x.right, f);

View File

@ -173,12 +173,12 @@ pub mod icu {
}
}
pub pure fn is_XID_start(c: char) -> bool {
pub fn is_XID_start(c: char) -> bool {
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
== icu::TRUE;
}
pub pure fn is_XID_continue(c: char) -> bool {
pub fn is_XID_continue(c: char) -> bool {
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
== icu::TRUE;
}
@ -188,7 +188,7 @@ Function: is_digit
Returns true if a character is a digit.
*/
pub pure fn is_digit(c: char) -> bool {
pub fn is_digit(c: char) -> bool {
return icu::libicu::u_isdigit(c) == icu::TRUE;
}
@ -197,7 +197,7 @@ Function: is_lower
Returns true if a character is a lowercase letter.
*/
pub pure fn is_lower(c: char) -> bool {
pub fn is_lower(c: char) -> bool {
return icu::libicu::u_islower(c) == icu::TRUE;
}
@ -206,7 +206,7 @@ Function: is_space
Returns true if a character is space.
*/
pub pure fn is_space(c: char) -> bool {
pub fn is_space(c: char) -> bool {
return icu::libicu::u_isspace(c) == icu::TRUE;
}
@ -215,7 +215,7 @@ Function: is_upper
Returns true if a character is an uppercase letter.
*/
pub pure fn is_upper(c: char) -> bool {
pub fn is_upper(c: char) -> bool {
return icu::libicu::u_isupper(c) == icu::TRUE;
}

View File

@ -106,7 +106,7 @@ struct WorkKey {
impl to_bytes::IterBytes for WorkKey {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
let mut flag = true;
self.kind.iter_bytes(lsb0, |bytes| {flag = f(bytes); flag});
if !flag { return; }
@ -115,18 +115,18 @@ impl to_bytes::IterBytes for WorkKey {
}
impl cmp::Ord for WorkKey {
pure fn lt(&self, other: &WorkKey) -> bool {
fn lt(&self, other: &WorkKey) -> bool {
self.kind < other.kind ||
(self.kind == other.kind &&
self.name < other.name)
}
pure fn le(&self, other: &WorkKey) -> bool {
fn le(&self, other: &WorkKey) -> bool {
self.lt(other) || self.eq(other)
}
pure fn ge(&self, other: &WorkKey) -> bool {
fn ge(&self, other: &WorkKey) -> bool {
self.gt(other) || self.eq(other)
}
pure fn gt(&self, other: &WorkKey) -> bool {
fn gt(&self, other: &WorkKey) -> bool {
! self.le(other)
}
}