libcore: Remove pure
from libcore. rs=depure
This commit is contained in:
parent
4634f7edae
commit
be9bddd463
57 changed files with 1548 additions and 1573 deletions
|
@ -38,7 +38,7 @@ pub mod rustrt {
|
||||||
|
|
||||||
/// Returns the number of elements the vector can hold without reallocating
|
/// Returns the number of elements the vector can hold without reallocating
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn capacity<T>(v: @[const T]) -> uint {
|
pub fn capacity<T>(v: @[const T]) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
let repr: **raw::VecRepr =
|
let repr: **raw::VecRepr =
|
||||||
::cast::reinterpret_cast(&addr_of(&v));
|
::cast::reinterpret_cast(&addr_of(&v));
|
||||||
|
@ -59,8 +59,7 @@ pub pure fn capacity<T>(v: @[const T]) -> uint {
|
||||||
* onto the vector being constructed.
|
* onto the vector being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn build_sized<A>(size: uint,
|
pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] {
|
||||||
builder: &fn(push: &pure fn(v: A))) -> @[A] {
|
|
||||||
let mut vec: @[const A] = @[];
|
let mut vec: @[const A] = @[];
|
||||||
unsafe { raw::reserve(&mut vec, size); }
|
unsafe { raw::reserve(&mut vec, size); }
|
||||||
builder(|+x| unsafe { raw::push(&mut vec, x) });
|
builder(|+x| unsafe { raw::push(&mut vec, x) });
|
||||||
|
@ -78,7 +77,7 @@ pub pure fn build_sized<A>(size: uint,
|
||||||
* onto the vector being constructed.
|
* onto the vector being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
|
pub fn build<A>(builder: &fn(push: &fn(v: A))) -> @[A] {
|
||||||
build_sized(4, builder)
|
build_sized(4, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +94,15 @@ pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
|
||||||
* onto the vector being constructed.
|
* onto the vector being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn build_sized_opt<A>(size: Option<uint>,
|
pub fn build_sized_opt<A>(size: Option<uint>,
|
||||||
builder: &fn(push: &pure fn(v: A))) -> @[A] {
|
builder: &fn(push: &fn(v: A)))
|
||||||
|
-> @[A] {
|
||||||
build_sized(size.get_or_default(4), builder)
|
build_sized(size.get_or_default(4), builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Appending
|
// Appending
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
|
pub fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
|
||||||
do build_sized(lhs.len() + rhs.len()) |push| {
|
do build_sized(lhs.len() + rhs.len()) |push| {
|
||||||
for vec::each(lhs) |x| { push(*x); }
|
for vec::each(lhs) |x| { push(*x); }
|
||||||
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
|
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
|
||||||
|
@ -111,7 +111,7 @@ pub pure fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
|
||||||
|
|
||||||
|
|
||||||
/// Apply a function to each element of a vector and return the results
|
/// Apply a function to each element of a vector and return the results
|
||||||
pub pure fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
|
pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
|
||||||
do build_sized(v.len()) |push| {
|
do build_sized(v.len()) |push| {
|
||||||
for vec::each(v) |elem| {
|
for vec::each(v) |elem| {
|
||||||
push(f(elem));
|
push(f(elem));
|
||||||
|
@ -125,7 +125,7 @@ pub pure fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
|
||||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||||
* to the value returned by the function `op`.
|
* to the value returned by the function `op`.
|
||||||
*/
|
*/
|
||||||
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
|
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
|
||||||
do build_sized(n_elts) |push| {
|
do build_sized(n_elts) |push| {
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n_elts { push(op(i)); i += 1u; }
|
while i < n_elts { push(op(i)); i += 1u; }
|
||||||
|
@ -138,7 +138,7 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
|
||||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||||
* to the value `t`.
|
* to the value `t`.
|
||||||
*/
|
*/
|
||||||
pub pure fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
|
pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
|
||||||
do build_sized(n_elts) |push| {
|
do build_sized(n_elts) |push| {
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n_elts { push(copy t); i += 1u; }
|
while i < n_elts { push(copy t); i += 1u; }
|
||||||
|
@ -176,7 +176,7 @@ pub mod traits {
|
||||||
|
|
||||||
impl<T:Copy> Add<&'self [const T],@[T]> for @[T] {
|
impl<T:Copy> Add<&'self [const T],@[T]> for @[T] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn add(&self, rhs: & &'self [const T]) -> @[T] {
|
fn add(&self, rhs: & &'self [const T]) -> @[T] {
|
||||||
append(*self, (*rhs))
|
append(*self, (*rhs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,39 +17,39 @@ use from_str::FromStr;
|
||||||
#[cfg(notest)] use cmp;
|
#[cfg(notest)] use cmp;
|
||||||
|
|
||||||
/// Negation / inverse
|
/// Negation / inverse
|
||||||
pub pure fn not(v: bool) -> bool { !v }
|
pub fn not(v: bool) -> bool { !v }
|
||||||
|
|
||||||
/// Conjunction
|
/// Conjunction
|
||||||
pub pure fn and(a: bool, b: bool) -> bool { a && b }
|
pub fn and(a: bool, b: bool) -> bool { a && b }
|
||||||
|
|
||||||
/// Disjunction
|
/// Disjunction
|
||||||
pub pure fn or(a: bool, b: bool) -> bool { a || b }
|
pub fn or(a: bool, b: bool) -> bool { a || b }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exclusive or
|
* Exclusive or
|
||||||
*
|
*
|
||||||
* Identical to `or(and(a, not(b)), and(not(a), b))`
|
* Identical to `or(and(a, not(b)), and(not(a), b))`
|
||||||
*/
|
*/
|
||||||
pub pure fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
|
pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
|
||||||
|
|
||||||
/// Implication in the logic, i.e. from `a` follows `b`
|
/// Implication in the logic, i.e. from `a` follows `b`
|
||||||
pub pure fn implies(a: bool, b: bool) -> bool { !a || b }
|
pub fn implies(a: bool, b: bool) -> bool { !a || b }
|
||||||
|
|
||||||
/// true if truth values `a` and `b` are indistinguishable in the logic
|
/// true if truth values `a` and `b` are indistinguishable in the logic
|
||||||
pub pure fn eq(a: bool, b: bool) -> bool { a == b }
|
pub fn eq(a: bool, b: bool) -> bool { a == b }
|
||||||
|
|
||||||
/// true if truth values `a` and `b` are distinguishable in the logic
|
/// true if truth values `a` and `b` are distinguishable in the logic
|
||||||
pub pure fn ne(a: bool, b: bool) -> bool { a != b }
|
pub fn ne(a: bool, b: bool) -> bool { a != b }
|
||||||
|
|
||||||
/// true if `v` represents truth in the logic
|
/// true if `v` represents truth in the logic
|
||||||
pub pure fn is_true(v: bool) -> bool { v }
|
pub fn is_true(v: bool) -> bool { v }
|
||||||
|
|
||||||
/// true if `v` represents falsehood in the logic
|
/// true if `v` represents falsehood in the logic
|
||||||
pub pure fn is_false(v: bool) -> bool { !v }
|
pub fn is_false(v: bool) -> bool { !v }
|
||||||
|
|
||||||
/// Parse logic value from `s`
|
/// Parse logic value from `s`
|
||||||
impl FromStr for bool {
|
impl FromStr for bool {
|
||||||
pure fn from_str(s: &str) -> Option<bool> {
|
fn from_str(s: &str) -> Option<bool> {
|
||||||
if s == "true" {
|
if s == "true" {
|
||||||
Some(true)
|
Some(true)
|
||||||
} else if s == "false" {
|
} else if s == "false" {
|
||||||
|
@ -61,7 +61,7 @@ impl FromStr for bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert `v` into a string
|
/// Convert `v` into a string
|
||||||
pub pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
|
pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates over all truth values by passing them to `blk` in an unspecified
|
* Iterates over all truth values by passing them to `blk` in an unspecified
|
||||||
|
@ -73,12 +73,12 @@ pub fn all_values(blk: &fn(v: bool)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// converts truth value to an 8 bit byte
|
/// converts truth value to an 8 bit byte
|
||||||
pub pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
|
pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl cmp::Eq for bool {
|
impl cmp::Eq for bool {
|
||||||
pure fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
|
fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
|
||||||
pure fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
|
fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -21,14 +21,14 @@ pub struct Cell<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
|
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
|
||||||
pure fn eq(&self, other: &Cell<T>) -> bool {
|
fn eq(&self, other: &Cell<T>) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let frozen_self: &Option<T> = transmute(&mut self.value);
|
let frozen_self: &Option<T> = transmute(&mut self.value);
|
||||||
let frozen_other: &Option<T> = transmute(&mut other.value);
|
let frozen_other: &Option<T> = transmute(&mut other.value);
|
||||||
frozen_self == frozen_other
|
frozen_self == frozen_other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pure fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
|
fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new full cell with the given value.
|
/// Creates a new full cell with the given value.
|
||||||
|
@ -36,7 +36,7 @@ pub fn Cell<T>(value: T) -> Cell<T> {
|
||||||
Cell { value: Some(value) }
|
Cell { value: Some(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn empty_cell<T>() -> Cell<T> {
|
pub fn empty_cell<T>() -> Cell<T> {
|
||||||
Cell { value: None }
|
Cell { value: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ pub impl<T> Cell<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the cell is empty and false if the cell is full.
|
/// Returns true if the cell is empty and false if the cell is full.
|
||||||
pure fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.value.is_none()
|
self.value.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub use is_XID_continue = unicode::derived_property::XID_Continue;
|
||||||
* in terms of the Unicode General Category 'Ll'
|
* in terms of the Unicode General Category 'Ll'
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_lowercase(c: char) -> bool {
|
pub fn is_lowercase(c: char) -> bool {
|
||||||
return unicode::general_category::Ll(c);
|
return unicode::general_category::Ll(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ pub pure fn is_lowercase(c: char) -> bool {
|
||||||
* in terms of the Unicode General Category 'Lu'.
|
* in terms of the Unicode General Category 'Lu'.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_uppercase(c: char) -> bool {
|
pub fn is_uppercase(c: char) -> bool {
|
||||||
return unicode::general_category::Lu(c);
|
return unicode::general_category::Lu(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ pub pure fn is_uppercase(c: char) -> bool {
|
||||||
* additional 'Cc'-category control codes in the range [0x09, 0x0d]
|
* additional 'Cc'-category control codes in the range [0x09, 0x0d]
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_whitespace(c: char) -> bool {
|
pub fn is_whitespace(c: char) -> bool {
|
||||||
return ('\x09' <= c && c <= '\x0d')
|
return ('\x09' <= c && c <= '\x0d')
|
||||||
|| unicode::general_category::Zs(c)
|
|| unicode::general_category::Zs(c)
|
||||||
|| unicode::general_category::Zl(c)
|
|| unicode::general_category::Zl(c)
|
||||||
|
@ -93,7 +93,7 @@ pub pure fn is_whitespace(c: char) -> bool {
|
||||||
* and the Derived Core Property 'Alphabetic'.
|
* and the Derived Core Property 'Alphabetic'.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_alphanumeric(c: char) -> bool {
|
pub fn is_alphanumeric(c: char) -> bool {
|
||||||
return unicode::derived_property::Alphabetic(c) ||
|
return unicode::derived_property::Alphabetic(c) ||
|
||||||
unicode::general_category::Nd(c) ||
|
unicode::general_category::Nd(c) ||
|
||||||
unicode::general_category::Nl(c) ||
|
unicode::general_category::Nl(c) ||
|
||||||
|
@ -102,13 +102,13 @@ pub pure fn is_alphanumeric(c: char) -> bool {
|
||||||
|
|
||||||
/// Indicates whether the character is an ASCII character
|
/// Indicates whether the character is an ASCII character
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_ascii(c: char) -> bool {
|
pub fn is_ascii(c: char) -> bool {
|
||||||
c - ('\x7F' & c) == '\x00'
|
c - ('\x7F' & c) == '\x00'
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates whether the character is numeric (Nd, Nl, or No)
|
/// Indicates whether the character is numeric (Nd, Nl, or No)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_digit(c: char) -> bool {
|
pub fn is_digit(c: char) -> bool {
|
||||||
return unicode::general_category::Nd(c) ||
|
return unicode::general_category::Nd(c) ||
|
||||||
unicode::general_category::Nl(c) ||
|
unicode::general_category::Nl(c) ||
|
||||||
unicode::general_category::No(c);
|
unicode::general_category::No(c);
|
||||||
|
@ -127,7 +127,7 @@ pub pure fn is_digit(c: char) -> bool {
|
||||||
* Note: This just wraps `to_digit()`.
|
* Note: This just wraps `to_digit()`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_digit_radix(c: char, radix: uint) -> bool {
|
pub fn is_digit_radix(c: char, radix: uint) -> bool {
|
||||||
match to_digit(c, radix) {
|
match to_digit(c, radix) {
|
||||||
Some(_) => true,
|
Some(_) => true,
|
||||||
None => false
|
None => false
|
||||||
|
@ -148,7 +148,7 @@ pub pure fn is_digit_radix(c: char, radix: uint) -> bool {
|
||||||
* Fails if given a `radix` outside the range `[0..36]`.
|
* Fails if given a `radix` outside the range `[0..36]`.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub pure fn to_digit(c: char, radix: uint) -> Option<uint> {
|
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
|
||||||
if radix > 36 {
|
if radix > 36 {
|
||||||
fail!(fmt!("to_digit: radix %? is to high (maximum 36)", radix));
|
fail!(fmt!("to_digit: radix %? is to high (maximum 36)", radix));
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ pub pure fn to_digit(c: char, radix: uint) -> Option<uint> {
|
||||||
* Fails if given an `radix` > 36.
|
* Fails if given an `radix` > 36.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub pure fn from_digit(num: uint, radix: uint) -> Option<char> {
|
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
|
||||||
if radix > 36 {
|
if radix > 36 {
|
||||||
fail!(fmt!("from_digit: radix %? is to high (maximum 36)", num));
|
fail!(fmt!("from_digit: radix %? is to high (maximum 36)", num));
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ pub pure fn from_digit(num: uint, radix: uint) -> Option<char> {
|
||||||
* - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
|
* - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
|
||||||
* - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
|
* - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
|
||||||
*/
|
*/
|
||||||
pub pure fn escape_unicode(c: char) -> ~str {
|
pub fn escape_unicode(c: char) -> ~str {
|
||||||
let s = u32::to_str_radix(c as u32, 16u);
|
let s = u32::to_str_radix(c as u32, 16u);
|
||||||
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
|
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
|
||||||
else if c <= '\uffff' { ('u', 4u) }
|
else if c <= '\uffff' { ('u', 4u) }
|
||||||
|
@ -223,7 +223,7 @@ pub pure fn escape_unicode(c: char) -> ~str {
|
||||||
* - Any other chars in the range [0x20,0x7e] are not escaped.
|
* - Any other chars in the range [0x20,0x7e] are not escaped.
|
||||||
* - Any other chars are given hex unicode escapes; see `escape_unicode`.
|
* - Any other chars are given hex unicode escapes; see `escape_unicode`.
|
||||||
*/
|
*/
|
||||||
pub pure fn escape_default(c: char) -> ~str {
|
pub fn escape_default(c: char) -> ~str {
|
||||||
match c {
|
match c {
|
||||||
'\t' => ~"\\t",
|
'\t' => ~"\\t",
|
||||||
'\r' => ~"\\r",
|
'\r' => ~"\\r",
|
||||||
|
@ -244,7 +244,7 @@ pub pure fn escape_default(c: char) -> ~str {
|
||||||
* -1 if a < b, 0 if a == b, +1 if a > b
|
* -1 if a < b, 0 if a == b, +1 if a > b
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn cmp(a: char, b: char) -> int {
|
pub fn cmp(a: char, b: char) -> int {
|
||||||
return if b > a { -1 }
|
return if b > a { -1 }
|
||||||
else if b < a { 1 }
|
else if b < a { 1 }
|
||||||
else { 0 }
|
else { 0 }
|
||||||
|
@ -252,8 +252,8 @@ pub pure fn cmp(a: char, b: char) -> int {
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Eq for char {
|
impl Eq for char {
|
||||||
pure fn eq(&self, other: &char) -> bool { (*self) == (*other) }
|
fn eq(&self, other: &char) -> bool { (*self) == (*other) }
|
||||||
pure fn ne(&self, other: &char) -> bool { (*self) != (*other) }
|
fn ne(&self, other: &char) -> bool { (*self) != (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -33,8 +33,8 @@ and `Eq` to overload the `==` and `!=` operators.
|
||||||
*/
|
*/
|
||||||
#[lang="eq"]
|
#[lang="eq"]
|
||||||
pub trait Eq {
|
pub trait Eq {
|
||||||
pure fn eq(&self, other: &Self) -> bool;
|
fn eq(&self, other: &Self) -> bool;
|
||||||
pure fn ne(&self, other: &Self) -> bool;
|
fn ne(&self, other: &Self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
|
@ -42,11 +42,11 @@ pub enum Ordering { Less, Equal, Greater }
|
||||||
|
|
||||||
/// Trait for types that form a total order
|
/// Trait for types that form a total order
|
||||||
pub trait TotalOrd {
|
pub trait TotalOrd {
|
||||||
pure fn cmp(&self, other: &Self) -> Ordering;
|
fn cmp(&self, other: &Self) -> Ordering;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn icmp<T: Ord>(a: &T, b: &T) -> Ordering {
|
fn icmp<T: Ord>(a: &T, b: &T) -> Ordering {
|
||||||
if *a < *b { Less }
|
if *a < *b { Less }
|
||||||
else if *a > *b { Greater }
|
else if *a > *b { Greater }
|
||||||
else { Equal }
|
else { Equal }
|
||||||
|
@ -54,52 +54,52 @@ pure fn icmp<T: Ord>(a: &T, b: &T) -> Ordering {
|
||||||
|
|
||||||
impl TotalOrd for u8 {
|
impl TotalOrd for u8 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &u8) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &u8) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for u16 {
|
impl TotalOrd for u16 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &u16) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &u16) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for u32 {
|
impl TotalOrd for u32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &u32) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &u32) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for u64 {
|
impl TotalOrd for u64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &u64) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &u64) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for i8 {
|
impl TotalOrd for i8 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &i8) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &i8) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for i16 {
|
impl TotalOrd for i16 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &i16) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &i16) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for i32 {
|
impl TotalOrd for i32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &i32) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &i32) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for i64 {
|
impl TotalOrd for i64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &i64) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &i64) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for int {
|
impl TotalOrd for int {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &int) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &int) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalOrd for uint {
|
impl TotalOrd for uint {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, other: &uint) -> Ordering { icmp(self, other) }
|
fn cmp(&self, other: &uint) -> Ordering { icmp(self, other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,39 +114,39 @@ impl TotalOrd for uint {
|
||||||
*/
|
*/
|
||||||
#[lang="ord"]
|
#[lang="ord"]
|
||||||
pub trait Ord {
|
pub trait Ord {
|
||||||
pure fn lt(&self, other: &Self) -> bool;
|
fn lt(&self, other: &Self) -> bool;
|
||||||
pure fn le(&self, other: &Self) -> bool;
|
fn le(&self, other: &Self) -> bool;
|
||||||
pure fn ge(&self, other: &Self) -> bool;
|
fn ge(&self, other: &Self) -> bool;
|
||||||
pure fn gt(&self, other: &Self) -> bool;
|
fn gt(&self, other: &Self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn lt<T:Ord>(v1: &T, v2: &T) -> bool {
|
pub fn lt<T:Ord>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).lt(v2)
|
(*v1).lt(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn le<T:Ord>(v1: &T, v2: &T) -> bool {
|
pub fn le<T:Ord>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).le(v2)
|
(*v1).le(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn eq<T:Eq>(v1: &T, v2: &T) -> bool {
|
pub fn eq<T:Eq>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).eq(v2)
|
(*v1).eq(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ne<T:Eq>(v1: &T, v2: &T) -> bool {
|
pub fn ne<T:Eq>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).ne(v2)
|
(*v1).ne(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ge<T:Ord>(v1: &T, v2: &T) -> bool {
|
pub fn ge<T:Ord>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).ge(v2)
|
(*v1).ge(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn gt<T:Ord>(v1: &T, v2: &T) -> bool {
|
pub fn gt<T:Ord>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).gt(v2)
|
(*v1).gt(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,16 +155,16 @@ pub pure fn gt<T:Ord>(v1: &T, v2: &T) -> bool {
|
||||||
/// container types; e.g. it is often desirable to be able to use `&str`
|
/// container types; e.g. it is often desirable to be able to use `&str`
|
||||||
/// values to look up entries in a container with `~str` keys.
|
/// values to look up entries in a container with `~str` keys.
|
||||||
pub trait Equiv<T> {
|
pub trait Equiv<T> {
|
||||||
pure fn equiv(&self, other: &T) -> bool;
|
fn equiv(&self, other: &T) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn min<T:Ord>(v1: T, v2: T) -> T {
|
pub fn min<T:Ord>(v1: T, v2: T) -> T {
|
||||||
if v1 < v2 { v1 } else { v2 }
|
if v1 < v2 { v1 } else { v2 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn max<T:Ord>(v1: T, v2: T) -> T {
|
pub fn max<T:Ord>(v1: T, v2: T) -> T {
|
||||||
if v1 > v2 { v1 } else { v2 }
|
if v1 > v2 { v1 } else { v2 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub trait GenericPort<T> {
|
||||||
/// Ports that can `peek`
|
/// Ports that can `peek`
|
||||||
pub trait Peekable<T> {
|
pub trait Peekable<T> {
|
||||||
/// Returns true if a message is available
|
/// Returns true if a message is available
|
||||||
pure fn peek(&self) -> bool;
|
fn peek(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the index of an endpoint that is ready to receive.
|
/// Returns the index of an endpoint that is ready to receive.
|
||||||
|
@ -148,7 +148,7 @@ fn chan_try_send<T:Owned>(self: &Chan<T>, x: T) -> bool {
|
||||||
pub impl<T: Owned> Port<T> {
|
pub impl<T: Owned> Port<T> {
|
||||||
fn recv(&self) -> T { port_recv(self) }
|
fn recv(&self) -> T { port_recv(self) }
|
||||||
fn try_recv(&self) -> Option<T> { port_try_recv(self) }
|
fn try_recv(&self) -> Option<T> { port_try_recv(self) }
|
||||||
pure fn peek(&self) -> bool { port_peek(self) }
|
fn peek(&self) -> bool { port_peek(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericPort<T> for Port<T> {
|
impl<T: Owned> GenericPort<T> for Port<T> {
|
||||||
|
@ -180,11 +180,11 @@ fn port_try_recv<T:Owned>(self: &Port<T>) -> Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Peekable<T> for Port<T> {
|
impl<T: Owned> Peekable<T> for Port<T> {
|
||||||
pure fn peek(&self) -> bool { port_peek(self) }
|
fn peek(&self) -> bool { port_peek(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn port_peek<T:Owned>(self: &Port<T>) -> bool {
|
fn port_peek<T:Owned>(self: &Port<T>) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
|
@ -198,7 +198,7 @@ pure fn port_peek<T:Owned>(self: &Port<T>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Selectable for Port<T> {
|
impl<T: Owned> Selectable for Port<T> {
|
||||||
pure fn header(&self) -> *PacketHeader {
|
fn header(&self) -> *PacketHeader {
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.endp {
|
match self.endp {
|
||||||
Some(ref endp) => endp.header(),
|
Some(ref endp) => endp.header(),
|
||||||
|
@ -223,7 +223,7 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
|
||||||
pub impl<T:Owned> PortSet<T> {
|
pub impl<T:Owned> PortSet<T> {
|
||||||
fn recv(&self) -> T { port_set_recv(self) }
|
fn recv(&self) -> T { port_set_recv(self) }
|
||||||
fn try_recv(&self) -> Option<T> { port_set_try_recv(self) }
|
fn try_recv(&self) -> Option<T> { port_set_try_recv(self) }
|
||||||
pure fn peek(&self) -> bool { port_set_peek(self) }
|
fn peek(&self) -> bool { port_set_peek(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: Owned> PortSet<T> {
|
pub impl<T: Owned> PortSet<T> {
|
||||||
|
@ -272,11 +272,11 @@ fn port_set_try_recv<T:Owned>(self: &PortSet<T>) -> Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Peekable<T> for PortSet<T> {
|
impl<T: Owned> Peekable<T> for PortSet<T> {
|
||||||
pure fn peek(&self) -> bool { port_set_peek(self) }
|
fn peek(&self) -> bool { port_set_peek(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn port_set_peek<T:Owned>(self: &PortSet<T>) -> bool {
|
fn port_set_peek<T:Owned>(self: &PortSet<T>) -> bool {
|
||||||
// It'd be nice to use self.port.each, but that version isn't
|
// It'd be nice to use self.port.each, but that version isn't
|
||||||
// pure.
|
// pure.
|
||||||
for uint::range(0, vec::uniq_len(&const self.ports)) |i| {
|
for uint::range(0, vec::uniq_len(&const self.ports)) |i| {
|
||||||
|
|
|
@ -14,10 +14,10 @@ use option::Option;
|
||||||
|
|
||||||
pub trait Container {
|
pub trait Container {
|
||||||
/// Return the number of elements in the container
|
/// Return the number of elements in the container
|
||||||
pure fn len(&const self) -> uint;
|
fn len(&const self) -> uint;
|
||||||
|
|
||||||
/// Return true if the container contains no elements
|
/// Return true if the container contains no elements
|
||||||
pure fn is_empty(&const self) -> bool;
|
fn is_empty(&const self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Mutable: Container {
|
pub trait Mutable: Container {
|
||||||
|
@ -27,19 +27,19 @@ pub trait Mutable: Container {
|
||||||
|
|
||||||
pub trait Map<K, V>: Mutable {
|
pub trait Map<K, V>: Mutable {
|
||||||
/// Return true if the map contains a value for the specified key
|
/// 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;
|
||||||
|
|
||||||
/// Visit all keys
|
/// Visit all keys
|
||||||
pure fn each_key(&self, f: &fn(&K) -> bool);
|
fn each_key(&self, f: &fn(&K) -> bool);
|
||||||
|
|
||||||
/// Visit all values
|
/// Visit all values
|
||||||
pure fn each_value(&self, f: &fn(&V) -> bool);
|
fn each_value(&self, f: &fn(&V) -> bool);
|
||||||
|
|
||||||
/// Iterate over the map and mutate the contained values
|
/// Iterate over the map and mutate the contained values
|
||||||
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);
|
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);
|
||||||
|
|
||||||
/// Return the value corresponding to the key in the map
|
/// 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>;
|
||||||
|
|
||||||
/// Insert a key-value pair into the map. An existing value for a
|
/// Insert a key-value pair into the map. An existing value for a
|
||||||
/// key is replaced by the new value. Return true if the key did
|
/// key is replaced by the new value. Return true if the key did
|
||||||
|
@ -53,7 +53,7 @@ pub trait Map<K, V>: Mutable {
|
||||||
|
|
||||||
pub trait Set<T>: Mutable {
|
pub trait Set<T>: Mutable {
|
||||||
/// Return true if the set contains a value
|
/// Return true if the set contains a value
|
||||||
pure fn contains(&self, value: &T) -> bool;
|
fn contains(&self, value: &T) -> bool;
|
||||||
|
|
||||||
/// Add a value to the set. Return true if the value was not already
|
/// Add a value to the set. Return true if the value was not already
|
||||||
/// present in the set.
|
/// present in the set.
|
||||||
|
@ -65,23 +65,23 @@ pub trait Set<T>: Mutable {
|
||||||
|
|
||||||
/// Return true if the set has no elements in common with `other`.
|
/// Return true if the set has no elements in common with `other`.
|
||||||
/// This is equivalent to checking for an empty intersection.
|
/// This is equivalent to checking for an empty intersection.
|
||||||
pure fn is_disjoint(&self, other: &Self) -> bool;
|
fn is_disjoint(&self, other: &Self) -> bool;
|
||||||
|
|
||||||
/// Return true if the set is a subset of another
|
/// Return true if the set is a subset of another
|
||||||
pure fn is_subset(&self, other: &Self) -> bool;
|
fn is_subset(&self, other: &Self) -> bool;
|
||||||
|
|
||||||
/// Return true if the set is a superset of another
|
/// Return true if the set is a superset of another
|
||||||
pure fn is_superset(&self, other: &Self) -> bool;
|
fn is_superset(&self, other: &Self) -> bool;
|
||||||
|
|
||||||
/// Visit the values representing the difference
|
/// Visit the values representing the difference
|
||||||
pure fn difference(&self, other: &Self, f: &fn(&T) -> bool);
|
fn difference(&self, other: &Self, f: &fn(&T) -> bool);
|
||||||
|
|
||||||
/// Visit the values representing the symmetric difference
|
/// Visit the values representing the symmetric difference
|
||||||
pure fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool);
|
fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool);
|
||||||
|
|
||||||
/// Visit the values representing the intersection
|
/// Visit the values representing the intersection
|
||||||
pure fn intersection(&self, other: &Self, f: &fn(&T) -> bool);
|
fn intersection(&self, other: &Self, f: &fn(&T) -> bool);
|
||||||
|
|
||||||
/// Visit the values representing the union
|
/// Visit the values representing the union
|
||||||
pure fn union(&self, other: &Self, f: &fn(&T) -> bool);
|
fn union(&self, other: &Self, f: &fn(&T) -> bool);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub struct DList<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
priv impl<T> DListNode<T> {
|
priv impl<T> DListNode<T> {
|
||||||
pure fn assert_links(@mut self) {
|
fn assert_links(@mut self) {
|
||||||
match self.next {
|
match self.next {
|
||||||
Some(neighbour) => match neighbour.prev {
|
Some(neighbour) => match neighbour.prev {
|
||||||
Some(me) => if !managed::mut_ptr_eq(self, me) {
|
Some(me) => if !managed::mut_ptr_eq(self, me) {
|
||||||
|
@ -66,24 +66,24 @@ priv impl<T> DListNode<T> {
|
||||||
|
|
||||||
pub impl<T> DListNode<T> {
|
pub impl<T> DListNode<T> {
|
||||||
/// Get the next node in the list, if there is one.
|
/// Get the next node in the list, if there is one.
|
||||||
pure fn next_link(@mut self) -> DListLink<T> {
|
fn next_link(@mut self) -> DListLink<T> {
|
||||||
self.assert_links();
|
self.assert_links();
|
||||||
self.next
|
self.next
|
||||||
}
|
}
|
||||||
/// Get the next node in the list, failing if there isn't one.
|
/// Get the next node in the list, failing if there isn't one.
|
||||||
pure fn next_node(@mut self) -> @mut DListNode<T> {
|
fn next_node(@mut self) -> @mut DListNode<T> {
|
||||||
match self.next_link() {
|
match self.next_link() {
|
||||||
Some(nobe) => nobe,
|
Some(nobe) => nobe,
|
||||||
None => fail!(~"This dlist node has no next neighbour.")
|
None => fail!(~"This dlist node has no next neighbour.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the previous node in the list, if there is one.
|
/// Get the previous node in the list, if there is one.
|
||||||
pure fn prev_link(@mut self) -> DListLink<T> {
|
fn prev_link(@mut self) -> DListLink<T> {
|
||||||
self.assert_links();
|
self.assert_links();
|
||||||
self.prev
|
self.prev
|
||||||
}
|
}
|
||||||
/// Get the previous node in the list, failing if there isn't one.
|
/// Get the previous node in the list, failing if there isn't one.
|
||||||
pure fn prev_node(@mut self) -> @mut DListNode<T> {
|
fn prev_node(@mut self) -> @mut DListNode<T> {
|
||||||
match self.prev_link() {
|
match self.prev_link() {
|
||||||
Some(nobe) => nobe,
|
Some(nobe) => nobe,
|
||||||
None => fail!(~"This dlist node has no previous neighbour.")
|
None => fail!(~"This dlist node has no previous neighbour.")
|
||||||
|
@ -92,17 +92,17 @@ pub impl<T> DListNode<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new dlist node with the given data.
|
/// Creates a new dlist node with the given data.
|
||||||
pub pure fn new_dlist_node<T>(data: T) -> @mut DListNode<T> {
|
pub fn new_dlist_node<T>(data: T) -> @mut DListNode<T> {
|
||||||
@mut DListNode { data: data, linked: false, prev: None, next: None }
|
@mut DListNode { data: data, linked: false, prev: None, next: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new, empty dlist.
|
/// Creates a new, empty dlist.
|
||||||
pub pure fn DList<T>() -> @mut DList<T> {
|
pub fn DList<T>() -> @mut DList<T> {
|
||||||
@mut DList { size: 0, hd: None, tl: None }
|
@mut DList { size: 0, hd: None, tl: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new dlist with a single element
|
/// Creates a new dlist with a single element
|
||||||
pub pure fn from_elem<T>(data: T) -> @mut DList<T> {
|
pub fn from_elem<T>(data: T) -> @mut DList<T> {
|
||||||
let list = DList();
|
let list = DList();
|
||||||
unsafe { list.push(data); }
|
unsafe { list.push(data); }
|
||||||
list
|
list
|
||||||
|
@ -126,7 +126,7 @@ pub fn concat<T>(lists: @mut DList<@mut DList<T>>) -> @mut DList<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
priv impl<T> DList<T> {
|
priv impl<T> DList<T> {
|
||||||
pure fn new_link(data: T) -> DListLink<T> {
|
fn new_link(data: T) -> DListLink<T> {
|
||||||
Some(@mut DListNode {
|
Some(@mut DListNode {
|
||||||
data: data,
|
data: data,
|
||||||
linked: true,
|
linked: true,
|
||||||
|
@ -134,7 +134,7 @@ priv impl<T> DList<T> {
|
||||||
next: None
|
next: None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pure fn assert_mine(@mut self, nobe: @mut DListNode<T>) {
|
fn assert_mine(@mut self, nobe: @mut DListNode<T>) {
|
||||||
// These asserts could be stronger if we had node-root back-pointers,
|
// These asserts could be stronger if we had node-root back-pointers,
|
||||||
// but those wouldn't allow for O(1) append.
|
// but those wouldn't allow for O(1) append.
|
||||||
if self.size == 0 {
|
if self.size == 0 {
|
||||||
|
@ -212,9 +212,9 @@ priv impl<T> DList<T> {
|
||||||
|
|
||||||
pub impl<T> DList<T> {
|
pub impl<T> DList<T> {
|
||||||
/// Get the size of the list. O(1).
|
/// Get the size of the list. O(1).
|
||||||
pure fn len(@mut self) -> uint { self.size }
|
fn len(@mut self) -> uint { self.size }
|
||||||
/// Returns true if the list is empty. O(1).
|
/// Returns true if the list is empty. O(1).
|
||||||
pure fn is_empty(@mut self) -> bool { self.len() == 0 }
|
fn is_empty(@mut self) -> bool { self.len() == 0 }
|
||||||
|
|
||||||
/// Add data to the head of the list. O(1).
|
/// Add data to the head of the list. O(1).
|
||||||
fn push_head(@mut self, data: T) {
|
fn push_head(@mut self, data: T) {
|
||||||
|
@ -316,12 +316,12 @@ pub impl<T> DList<T> {
|
||||||
tl
|
tl
|
||||||
}
|
}
|
||||||
/// Get the node at the list's head. O(1).
|
/// Get the node at the list's head. O(1).
|
||||||
pure fn peek_n(@mut self) -> DListLink<T> { self.hd }
|
fn peek_n(@mut self) -> DListLink<T> { self.hd }
|
||||||
/// Get the node at the list's tail. O(1).
|
/// Get the node at the list's tail. O(1).
|
||||||
pure fn peek_tail_n(@mut self) -> DListLink<T> { self.tl }
|
fn peek_tail_n(@mut self) -> DListLink<T> { self.tl }
|
||||||
|
|
||||||
/// Get the node at the list's head, failing if empty. O(1).
|
/// Get the node at the list's head, failing if empty. O(1).
|
||||||
pure fn head_n(@mut self) -> @mut DListNode<T> {
|
fn head_n(@mut self) -> @mut DListNode<T> {
|
||||||
match self.hd {
|
match self.hd {
|
||||||
Some(nobe) => nobe,
|
Some(nobe) => nobe,
|
||||||
None => fail!(
|
None => fail!(
|
||||||
|
@ -329,7 +329,7 @@ pub impl<T> DList<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the node at the list's tail, failing if empty. O(1).
|
/// Get the node at the list's tail, failing if empty. O(1).
|
||||||
pure fn tail_n(@mut self) -> @mut DListNode<T> {
|
fn tail_n(@mut self) -> @mut DListNode<T> {
|
||||||
match self.tl {
|
match self.tl {
|
||||||
Some(nobe) => nobe,
|
Some(nobe) => nobe,
|
||||||
None => fail!(
|
None => fail!(
|
||||||
|
@ -399,7 +399,7 @@ pub impl<T> DList<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over nodes.
|
/// Iterate over nodes.
|
||||||
pure fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
|
fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
|
||||||
let mut link = self.peek_n();
|
let mut link = self.peek_n();
|
||||||
while link.is_some() {
|
while link.is_some() {
|
||||||
let nobe = link.get();
|
let nobe = link.get();
|
||||||
|
@ -471,23 +471,23 @@ pub impl<T:Copy> DList<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get data at the list's head. O(1).
|
/// Get data at the list's head. O(1).
|
||||||
pure fn peek(@mut self) -> Option<T> {
|
fn peek(@mut self) -> Option<T> {
|
||||||
self.peek_n().map(|nobe| nobe.data)
|
self.peek_n().map(|nobe| nobe.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get data at the list's tail. O(1).
|
/// Get data at the list's tail. O(1).
|
||||||
pure fn peek_tail(@mut self) -> Option<T> {
|
fn peek_tail(@mut self) -> Option<T> {
|
||||||
self.peek_tail_n().map (|nobe| nobe.data)
|
self.peek_tail_n().map (|nobe| nobe.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get data at the list's head, failing if empty. O(1).
|
/// Get data at the list's head, failing if empty. O(1).
|
||||||
pure fn head(@mut self) -> T { self.head_n().data }
|
fn head(@mut self) -> T { self.head_n().data }
|
||||||
|
|
||||||
/// Get data at the list's tail, failing if empty. O(1).
|
/// Get data at the list's tail, failing if empty. O(1).
|
||||||
pure fn tail(@mut self) -> T { self.tail_n().data }
|
fn tail(@mut self) -> T { self.tail_n().data }
|
||||||
|
|
||||||
/// Get the elements of the list as a vector. O(n).
|
/// Get the elements of the list as a vector. O(n).
|
||||||
pure fn to_vec(@mut self) -> ~[T] {
|
fn to_vec(@mut self) -> ~[T] {
|
||||||
let mut v = vec::with_capacity(self.size);
|
let mut v = vec::with_capacity(self.size);
|
||||||
unsafe {
|
unsafe {
|
||||||
// Take this out of the unchecked when iter's functions are pure
|
// Take this out of the unchecked when iter's functions are pure
|
||||||
|
@ -507,7 +507,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
|
||||||
* allow for e.g. breadth-first search with in-place enqueues), but
|
* allow for e.g. breadth-first search with in-place enqueues), but
|
||||||
* removing the current node is forbidden.
|
* removing the current node is forbidden.
|
||||||
*/
|
*/
|
||||||
pure fn each(&self, f: &fn(v: &T) -> bool) {
|
fn each(&self, f: &fn(v: &T) -> bool) {
|
||||||
let mut link = self.peek_n();
|
let mut link = self.peek_n();
|
||||||
while option::is_some(&link) {
|
while option::is_some(&link) {
|
||||||
let nobe = option::get(link);
|
let nobe = option::get(link);
|
||||||
|
@ -536,7 +536,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
|
pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
|
||||||
//! Flips between left and right of a given either
|
//! Flips between left and right of a given either
|
||||||
|
|
||||||
match eith {
|
match eith {
|
||||||
|
@ -97,7 +97,7 @@ pub pure fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_result<T, U>(eith: Either<T, U>)
|
pub fn to_result<T, U>(eith: Either<T, U>)
|
||||||
-> Result<U, T> {
|
-> Result<U, T> {
|
||||||
/*!
|
/*!
|
||||||
* Converts either::t to a result::t
|
* Converts either::t to a result::t
|
||||||
|
@ -113,21 +113,21 @@ pub pure fn to_result<T, U>(eith: Either<T, U>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_left<T, U>(eith: &Either<T, U>) -> bool {
|
pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
|
||||||
//! Checks whether the given value is a left
|
//! Checks whether the given value is a left
|
||||||
|
|
||||||
match *eith { Left(_) => true, _ => false }
|
match *eith { Left(_) => true, _ => false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_right<T, U>(eith: &Either<T, U>) -> bool {
|
pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
|
||||||
//! Checks whether the given value is a right
|
//! Checks whether the given value is a right
|
||||||
|
|
||||||
match *eith { Right(_) => true, _ => false }
|
match *eith { Right(_) => true, _ => false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
|
pub fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
|
||||||
//! Retrieves the value in the left branch. Fails if the either is Right.
|
//! Retrieves the value in the left branch. Fails if the either is Right.
|
||||||
|
|
||||||
match eith {
|
match eith {
|
||||||
|
@ -137,7 +137,7 @@ pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
|
pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
|
||||||
//! Retrieves the value in the right branch. Fails if the either is Left.
|
//! Retrieves the value in the right branch. Fails if the either is Left.
|
||||||
|
|
||||||
match eith {
|
match eith {
|
||||||
|
|
|
@ -13,5 +13,5 @@
|
||||||
use option::Option;
|
use option::Option;
|
||||||
|
|
||||||
pub trait FromStr {
|
pub trait FromStr {
|
||||||
pure fn from_str(s: &str) -> Option<Self>;
|
fn from_str(s: &str) -> Option<Self>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,17 +50,17 @@ pub trait Hash {
|
||||||
* function and require most types to only implement the
|
* function and require most types to only implement the
|
||||||
* IterBytes trait, that feeds SipHash.
|
* IterBytes trait, that feeds SipHash.
|
||||||
*/
|
*/
|
||||||
pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64;
|
fn hash_keyed(&self, k0: u64, k1: u64) -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we have default methods, won't need this.
|
// When we have default methods, won't need this.
|
||||||
pub trait HashUtil {
|
pub trait HashUtil {
|
||||||
pure fn hash(&self) -> u64;
|
fn hash(&self) -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:Hash> HashUtil for A {
|
impl<A:Hash> HashUtil for A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn hash(&self) -> u64 { self.hash_keyed(0,0) }
|
fn hash(&self) -> u64 { self.hash_keyed(0,0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Streaming hash-functions should implement this.
|
/// Streaming hash-functions should implement this.
|
||||||
|
@ -75,7 +75,7 @@ pub trait Streaming {
|
||||||
|
|
||||||
impl<A:IterBytes> Hash for A {
|
impl<A:IterBytes> Hash for A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64 {
|
fn hash_keyed(&self, k0: u64, k1: u64) -> u64 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = &State(k0, k1);
|
let s = &State(k0, k1);
|
||||||
for self.iter_bytes(true) |bytes| {
|
for self.iter_bytes(true) |bytes| {
|
||||||
|
@ -86,9 +86,8 @@ impl<A:IterBytes> Hash for A {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn hash_keyed_2<A: IterBytes,
|
fn hash_keyed_2<A: IterBytes,
|
||||||
B: IterBytes>(a: &A, b: &B,
|
B: IterBytes>(a: &A, b: &B, k0: u64, k1: u64) -> u64 {
|
||||||
k0: u64, k1: u64) -> u64 {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = &State(k0, k1);
|
let s = &State(k0, k1);
|
||||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||||
|
@ -97,10 +96,9 @@ pure fn hash_keyed_2<A: IterBytes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn hash_keyed_3<A: IterBytes,
|
fn hash_keyed_3<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes>(a: &A, b: &B, c: &C,
|
C: IterBytes>(a: &A, b: &B, c: &C, k0: u64, k1: u64) -> u64 {
|
||||||
k0: u64, k1: u64) -> u64 {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = &State(k0, k1);
|
let s = &State(k0, k1);
|
||||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||||
|
@ -110,11 +108,11 @@ pure fn hash_keyed_3<A: IterBytes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn hash_keyed_4<A: IterBytes,
|
fn hash_keyed_4<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes,
|
C: IterBytes,
|
||||||
D: IterBytes>(a: &A, b: &B, c: &C, d: &D,
|
D: IterBytes>(a: &A, b: &B, c: &C, d: &D, k0: u64, k1: u64)
|
||||||
k0: u64, k1: u64) -> u64 {
|
-> u64 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = &State(k0, k1);
|
let s = &State(k0, k1);
|
||||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||||
|
@ -125,12 +123,12 @@ pure fn hash_keyed_4<A: IterBytes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn hash_keyed_5<A: IterBytes,
|
fn hash_keyed_5<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes,
|
C: IterBytes,
|
||||||
D: IterBytes,
|
D: IterBytes,
|
||||||
E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E,
|
E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E,
|
||||||
k0: u64, k1: u64) -> u64 {
|
k0: u64, k1: u64) -> u64 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = &State(k0, k1);
|
let s = &State(k0, k1);
|
||||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn resize_at(capacity: uint) -> uint {
|
fn resize_at(capacity: uint) -> uint {
|
||||||
((capacity as float) * 3. / 4.) as uint
|
((capacity as float) * 3. / 4.) as uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ pub mod linear {
|
||||||
initial_capacity)
|
initial_capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
|
fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
|
||||||
k0: u64, k1: u64,
|
k0: u64, k1: u64,
|
||||||
initial_capacity: uint) -> LinearMap<K, V> {
|
initial_capacity: uint) -> LinearMap<K, V> {
|
||||||
LinearMap {
|
LinearMap {
|
||||||
|
@ -72,21 +72,21 @@ pub mod linear {
|
||||||
|
|
||||||
priv impl<K:Hash + IterBytes + Eq,V> LinearMap<K, V> {
|
priv impl<K:Hash + IterBytes + Eq,V> LinearMap<K, V> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_bucket(&self, h: uint) -> uint {
|
fn to_bucket(&self, h: uint) -> uint {
|
||||||
// A good hash function with entropy spread over all of the
|
// A good hash function with entropy spread over all of the
|
||||||
// bits is assumed. SipHash is more than good enough.
|
// bits is assumed. SipHash is more than good enough.
|
||||||
h % self.buckets.len()
|
h % self.buckets.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn next_bucket(&self, idx: uint, len_buckets: uint) -> uint {
|
fn next_bucket(&self, idx: uint, len_buckets: uint) -> uint {
|
||||||
let n = (idx + 1) % len_buckets;
|
let n = (idx + 1) % len_buckets;
|
||||||
debug!("next_bucket(%?, %?) = %?", idx, len_buckets, n);
|
debug!("next_bucket(%?, %?) = %?", idx, len_buckets, n);
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn bucket_sequence(&self, hash: uint,
|
fn bucket_sequence(&self, hash: uint,
|
||||||
op: &fn(uint) -> bool) -> uint {
|
op: &fn(uint) -> bool) -> uint {
|
||||||
let start_idx = self.to_bucket(hash);
|
let start_idx = self.to_bucket(hash);
|
||||||
let len_buckets = self.buckets.len();
|
let len_buckets = self.buckets.len();
|
||||||
|
@ -103,24 +103,24 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn bucket_for_key(&self, k: &K) -> SearchResult {
|
fn bucket_for_key(&self, k: &K) -> SearchResult {
|
||||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||||
self.bucket_for_key_with_hash(hash, k)
|
self.bucket_for_key_with_hash(hash, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(
|
fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self,
|
||||||
&self,
|
k: &Q)
|
||||||
k: &Q)
|
-> SearchResult {
|
||||||
-> SearchResult {
|
|
||||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||||
self.bucket_for_key_with_hash_equiv(hash, k)
|
self.bucket_for_key_with_hash_equiv(hash, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn bucket_for_key_with_hash(&self,
|
fn bucket_for_key_with_hash(&self,
|
||||||
hash: uint,
|
hash: uint,
|
||||||
k: &K) -> SearchResult {
|
k: &K)
|
||||||
|
-> SearchResult {
|
||||||
let _ = for self.bucket_sequence(hash) |i| {
|
let _ = for self.bucket_sequence(hash) |i| {
|
||||||
match self.buckets[i] {
|
match self.buckets[i] {
|
||||||
Some(ref bkt) => if bkt.hash == hash && *k == bkt.key {
|
Some(ref bkt) => if bkt.hash == hash && *k == bkt.key {
|
||||||
|
@ -133,10 +133,10 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn bucket_for_key_with_hash_equiv<Q:Equiv<K>>(&self,
|
fn bucket_for_key_with_hash_equiv<Q:Equiv<K>>(&self,
|
||||||
hash: uint,
|
hash: uint,
|
||||||
k: &Q)
|
k: &Q)
|
||||||
-> SearchResult {
|
-> SearchResult {
|
||||||
let _ = for self.bucket_sequence(hash) |i| {
|
let _ = for self.bucket_sequence(hash) |i| {
|
||||||
match self.buckets[i] {
|
match self.buckets[i] {
|
||||||
Some(ref bkt) => {
|
Some(ref bkt) => {
|
||||||
|
@ -185,7 +185,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn value_for_bucket(&self, idx: uint) -> &'self V {
|
fn value_for_bucket(&self, idx: uint) -> &'self V {
|
||||||
match self.buckets[idx] {
|
match self.buckets[idx] {
|
||||||
Some(ref bkt) => &bkt.value,
|
Some(ref bkt) => &bkt.value,
|
||||||
None => fail!(~"LinearMap::find: internal logic error"),
|
None => fail!(~"LinearMap::find: internal logic error"),
|
||||||
|
@ -273,7 +273,7 @@ pub mod linear {
|
||||||
BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
|
BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
|
||||||
{
|
{
|
||||||
/// Visit all key-value pairs
|
/// Visit all key-value pairs
|
||||||
pure fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
|
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
|
||||||
for uint::range(0, self.buckets.len()) |i| {
|
for uint::range(0, self.buckets.len()) |i| {
|
||||||
let mut broke = false;
|
let mut broke = false;
|
||||||
do self.buckets[i].map |bucket| {
|
do self.buckets[i].map |bucket| {
|
||||||
|
@ -284,16 +284,16 @@ pub mod linear {
|
||||||
if broke { break; }
|
if broke { break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<K:Hash + IterBytes + Eq,V> Container for LinearMap<K, V> {
|
impl<K:Hash + IterBytes + Eq,V> Container for LinearMap<K, V> {
|
||||||
/// Return the number of elements in the map
|
/// Return the number of elements in the map
|
||||||
pure fn len(&const self) -> uint { self.size }
|
fn len(&const self) -> uint { self.size }
|
||||||
|
|
||||||
/// Return true if the map contains no elements
|
/// 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<K:Hash + IterBytes + Eq,V> Mutable for LinearMap<K, V> {
|
impl<K:Hash + IterBytes + Eq,V> Mutable for LinearMap<K, V> {
|
||||||
|
@ -308,7 +308,7 @@ pub mod linear {
|
||||||
|
|
||||||
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
|
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
|
||||||
/// Return true if the map contains a value for the specified key
|
/// Return true if the map contains a value for the specified key
|
||||||
pure fn contains_key(&self, k: &K) -> bool {
|
fn contains_key(&self, k: &K) -> bool {
|
||||||
match self.bucket_for_key(k) {
|
match self.bucket_for_key(k) {
|
||||||
FoundEntry(_) => {true}
|
FoundEntry(_) => {true}
|
||||||
TableFull | FoundHole(_) => {false}
|
TableFull | FoundHole(_) => {false}
|
||||||
|
@ -316,12 +316,12 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all keys
|
/// Visit all keys
|
||||||
pure fn each_key(&self, blk: &fn(k: &K) -> bool) {
|
fn each_key(&self, blk: &fn(k: &K) -> bool) {
|
||||||
self.each(|&(k, _)| blk(k))
|
self.each(|&(k, _)| blk(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all values
|
/// Visit all values
|
||||||
pure fn each_value(&self, blk: &fn(v: &V) -> bool) {
|
fn each_value(&self, blk: &fn(v: &V) -> bool) {
|
||||||
self.each(|&(_, v)| blk(v))
|
self.each(|&(_, v)| blk(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the value corresponding to the key in the map
|
/// Return the value corresponding to the key in the map
|
||||||
pure fn find(&self, k: &K) -> Option<&'self V> {
|
fn find(&self, k: &K) -> Option<&'self V> {
|
||||||
match self.bucket_for_key(k) {
|
match self.bucket_for_key(k) {
|
||||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||||
TableFull | FoundHole(_) => None,
|
TableFull | FoundHole(_) => None,
|
||||||
|
@ -487,7 +487,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn get(&self, k: &K) -> &'self V {
|
fn get(&self, k: &K) -> &'self V {
|
||||||
match self.find(k) {
|
match self.find(k) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => fail!(fmt!("No entry found for key: %?", k)),
|
None => fail!(fmt!("No entry found for key: %?", k)),
|
||||||
|
@ -496,10 +496,8 @@ pub mod linear {
|
||||||
|
|
||||||
/// Return true if the map contains a value for the specified key,
|
/// Return true if the map contains a value for the specified key,
|
||||||
/// using equivalence
|
/// using equivalence
|
||||||
pure fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(
|
fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, key: &Q)
|
||||||
&self,
|
-> bool {
|
||||||
key: &Q)
|
|
||||||
-> bool {
|
|
||||||
match self.bucket_for_key_equiv(key) {
|
match self.bucket_for_key_equiv(key) {
|
||||||
FoundEntry(_) => {true}
|
FoundEntry(_) => {true}
|
||||||
TableFull | FoundHole(_) => {false}
|
TableFull | FoundHole(_) => {false}
|
||||||
|
@ -508,8 +506,8 @@ pub mod linear {
|
||||||
|
|
||||||
/// Return the value corresponding to the key in the map, using
|
/// Return the value corresponding to the key in the map, using
|
||||||
/// equivalence
|
/// equivalence
|
||||||
pure fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
|
fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
|
||||||
-> Option<&'self V> {
|
-> Option<&'self V> {
|
||||||
match self.bucket_for_key_equiv(k) {
|
match self.bucket_for_key_equiv(k) {
|
||||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||||
TableFull | FoundHole(_) => None,
|
TableFull | FoundHole(_) => None,
|
||||||
|
@ -518,7 +516,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Hash + IterBytes + Eq,V:Eq> Eq for LinearMap<K, V> {
|
impl<K:Hash + IterBytes + Eq,V:Eq> Eq for LinearMap<K, V> {
|
||||||
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
|
fn eq(&self, other: &LinearMap<K, V>) -> bool {
|
||||||
if self.len() != other.len() { return false; }
|
if self.len() != other.len() { return false; }
|
||||||
|
|
||||||
for self.each |&(key, value)| {
|
for self.each |&(key, value)| {
|
||||||
|
@ -531,7 +529,7 @@ pub mod linear {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn ne(&self, other: &LinearMap<K, V>) -> bool { !self.eq(other) }
|
fn ne(&self, other: &LinearMap<K, V>) -> bool { !self.eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LinearSet<T> {
|
pub struct LinearSet<T> {
|
||||||
|
@ -540,25 +538,21 @@ pub mod linear {
|
||||||
|
|
||||||
impl<T:Hash + IterBytes + Eq> BaseIter<T> for LinearSet<T> {
|
impl<T:Hash + IterBytes + Eq> BaseIter<T> for LinearSet<T> {
|
||||||
/// Visit all values in order
|
/// Visit all values in order
|
||||||
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) }
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Hash + IterBytes + Eq> Eq for LinearSet<T> {
|
impl<T:Hash + IterBytes + Eq> Eq for LinearSet<T> {
|
||||||
pure fn eq(&self, other: &LinearSet<T>) -> bool {
|
fn eq(&self, other: &LinearSet<T>) -> bool { self.map == other.map }
|
||||||
self.map == other.map
|
fn ne(&self, other: &LinearSet<T>) -> bool { self.map != other.map }
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &LinearSet<T>) -> bool {
|
|
||||||
self.map != other.map
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Hash + IterBytes + Eq> Container for LinearSet<T> {
|
impl<T:Hash + IterBytes + Eq> Container for LinearSet<T> {
|
||||||
/// Return the number of elements in the set
|
/// Return the number of elements in the set
|
||||||
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
|
/// Return true if the set contains no elements
|
||||||
pure fn is_empty(&const self) -> bool { self.map.is_empty() }
|
fn is_empty(&const self) -> bool { self.map.is_empty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Hash + IterBytes + Eq> Mutable for LinearSet<T> {
|
impl<T:Hash + IterBytes + Eq> Mutable for LinearSet<T> {
|
||||||
|
@ -568,9 +562,7 @@ pub mod linear {
|
||||||
|
|
||||||
impl<T:Hash + IterBytes + Eq> Set<T> for LinearSet<T> {
|
impl<T:Hash + IterBytes + Eq> Set<T> for LinearSet<T> {
|
||||||
/// Return true if the set contains a value
|
/// Return true if the set contains a value
|
||||||
pure fn contains(&self, value: &T) -> bool {
|
fn contains(&self, value: &T) -> bool { self.map.contains_key(value) }
|
||||||
self.map.contains_key(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a value to the set. Return true if the value was not already
|
/// Add a value to the set. Return true if the value was not already
|
||||||
/// present in the set.
|
/// present in the set.
|
||||||
|
@ -582,22 +574,22 @@ pub mod linear {
|
||||||
|
|
||||||
/// Return true if the set has no elements in common with `other`.
|
/// Return true if the set has no elements in common with `other`.
|
||||||
/// This is equivalent to checking for an empty intersection.
|
/// This is equivalent to checking for an empty intersection.
|
||||||
pure fn is_disjoint(&self, other: &LinearSet<T>) -> bool {
|
fn is_disjoint(&self, other: &LinearSet<T>) -> bool {
|
||||||
iter::all(self, |v| !other.contains(v))
|
iter::all(self, |v| !other.contains(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if the set is a subset of another
|
/// Return true if the set is a subset of another
|
||||||
pure fn is_subset(&self, other: &LinearSet<T>) -> bool {
|
fn is_subset(&self, other: &LinearSet<T>) -> bool {
|
||||||
iter::all(self, |v| other.contains(v))
|
iter::all(self, |v| other.contains(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if the set is a superset of another
|
/// Return true if the set is a superset of another
|
||||||
pure fn is_superset(&self, other: &LinearSet<T>) -> bool {
|
fn is_superset(&self, other: &LinearSet<T>) -> bool {
|
||||||
other.is_subset(self)
|
other.is_subset(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit the values representing the difference
|
/// Visit the values representing the difference
|
||||||
pure fn difference(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
|
fn difference(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
|
||||||
for self.each |v| {
|
for self.each |v| {
|
||||||
if !other.contains(v) {
|
if !other.contains(v) {
|
||||||
if !f(v) { return }
|
if !f(v) { return }
|
||||||
|
@ -606,16 +598,15 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit the values representing the symmetric difference
|
/// Visit the values representing the symmetric difference
|
||||||
pure fn symmetric_difference(&self, other: &LinearSet<T>,
|
fn symmetric_difference(&self,
|
||||||
f: &fn(&T) -> bool) {
|
other: &LinearSet<T>,
|
||||||
|
f: &fn(&T) -> bool) {
|
||||||
self.difference(other, f);
|
self.difference(other, f);
|
||||||
other.difference(self, f);
|
other.difference(self, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit the values representing the intersection
|
/// Visit the values representing the intersection
|
||||||
pure fn intersection(&self,
|
fn intersection(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
|
||||||
other: &LinearSet<T>,
|
|
||||||
f: &fn(&T) -> bool) {
|
|
||||||
for self.each |v| {
|
for self.each |v| {
|
||||||
if other.contains(v) {
|
if other.contains(v) {
|
||||||
if !f(v) { return }
|
if !f(v) { return }
|
||||||
|
@ -624,7 +615,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit the values representing the union
|
/// Visit the values representing the union
|
||||||
pure fn union(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
|
fn union(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
|
||||||
for self.each |v| {
|
for self.each |v| {
|
||||||
if !f(v) { return }
|
if !f(v) { return }
|
||||||
}
|
}
|
||||||
|
|
|
@ -646,11 +646,11 @@ impl Reader for BytesReader<'self> {
|
||||||
fn tell(&self) -> uint { self.pos }
|
fn tell(&self) -> uint { self.pos }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: &fn(@Reader) -> t) -> t {
|
pub fn with_bytes_reader<t>(bytes: &[u8], f: &fn(@Reader) -> t) -> t {
|
||||||
f(@BytesReader { bytes: bytes, pos: 0u } as @Reader)
|
f(@BytesReader { bytes: bytes, pos: 0u } as @Reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
|
pub fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
|
||||||
str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
|
str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1165,18 +1165,18 @@ impl Writer for BytesWriter {
|
||||||
fn get_type(&self) -> WriterType { File }
|
fn get_type(&self) -> WriterType { File }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn BytesWriter() -> BytesWriter {
|
pub fn BytesWriter() -> BytesWriter {
|
||||||
BytesWriter { bytes: ~[], mut pos: 0u }
|
BytesWriter { bytes: ~[], mut pos: 0u }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
|
pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
|
||||||
let wr = @BytesWriter();
|
let wr = @BytesWriter();
|
||||||
f(wr as @Writer);
|
f(wr as @Writer);
|
||||||
let @BytesWriter{bytes, _} = wr;
|
let @BytesWriter{bytes, _} = wr;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_str_writer(f: &fn(@Writer)) -> ~str {
|
pub fn with_str_writer(f: &fn(@Writer)) -> ~str {
|
||||||
let mut v = with_bytes_writer(f);
|
let mut v = with_bytes_writer(f);
|
||||||
|
|
||||||
// FIXME (#3758): This should not be needed.
|
// FIXME (#3758): This should not be needed.
|
||||||
|
|
|
@ -23,12 +23,12 @@ use vec;
|
||||||
pub type InitOp<T> = &'self fn(uint) -> T;
|
pub type InitOp<T> = &'self fn(uint) -> T;
|
||||||
|
|
||||||
pub trait BaseIter<A> {
|
pub trait BaseIter<A> {
|
||||||
pure fn each(&self, blk: &fn(v: &A) -> bool);
|
fn each(&self, blk: &fn(v: &A) -> bool);
|
||||||
pure fn size_hint(&self) -> Option<uint>;
|
fn size_hint(&self) -> Option<uint>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ReverseIter<A>: BaseIter<A> {
|
pub trait ReverseIter<A>: BaseIter<A> {
|
||||||
pure fn each_reverse(&self, blk: &fn(&A) -> bool);
|
fn each_reverse(&self, blk: &fn(&A) -> bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MutableIter<A>: BaseIter<A> {
|
pub trait MutableIter<A>: BaseIter<A> {
|
||||||
|
@ -36,41 +36,40 @@ pub trait MutableIter<A>: BaseIter<A> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ExtendedIter<A> {
|
pub trait ExtendedIter<A> {
|
||||||
pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
|
fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
|
||||||
pure fn all(&self, blk: &fn(&A) -> bool) -> bool;
|
fn all(&self, blk: &fn(&A) -> bool) -> bool;
|
||||||
pure fn any(&self, blk: &fn(&A) -> bool) -> bool;
|
fn any(&self, blk: &fn(&A) -> bool) -> bool;
|
||||||
pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
|
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
|
||||||
pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
|
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
|
||||||
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
|
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
|
||||||
pure fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB)
|
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
|
||||||
-> ~[B];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EqIter<A:Eq> {
|
pub trait EqIter<A:Eq> {
|
||||||
pure fn contains(&self, x: &A) -> bool;
|
fn contains(&self, x: &A) -> bool;
|
||||||
pure fn count(&self, x: &A) -> uint;
|
fn count(&self, x: &A) -> uint;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Times {
|
pub trait Times {
|
||||||
pure fn times(&self, it: &fn() -> bool);
|
fn times(&self, it: &fn() -> bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CopyableIter<A:Copy> {
|
pub trait CopyableIter<A:Copy> {
|
||||||
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
|
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
|
||||||
pure fn to_vec(&self) -> ~[A];
|
fn to_vec(&self) -> ~[A];
|
||||||
pure fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
|
fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CopyableOrderedIter<A:Copy + Ord> {
|
pub trait CopyableOrderedIter<A:Copy + Ord> {
|
||||||
pure fn min(&self) -> A;
|
fn min(&self) -> A;
|
||||||
pure fn max(&self) -> A;
|
fn max(&self) -> A;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CopyableNonstrictIter<A:Copy> {
|
pub trait CopyableNonstrictIter<A:Copy> {
|
||||||
// Like "each", but copies out the value. If the receiver is mutated while
|
// Like "each", but copies out the value. If the receiver is mutated while
|
||||||
// iterating over it, the semantics must not be memory-unsafe but are
|
// iterating over it, the semantics must not be memory-unsafe but are
|
||||||
// otherwise undefined.
|
// otherwise undefined.
|
||||||
pure fn each_val(&const self, f: &fn(A) -> bool);
|
fn each_val(&const self, f: &fn(A) -> bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A trait for sequences that can be built by imperatively pushing elements
|
// A trait for sequences that can be built by imperatively pushing elements
|
||||||
|
@ -89,13 +88,11 @@ pub trait Buildable<A> {
|
||||||
* as an argument a function that will push an element
|
* as an argument a function that will push an element
|
||||||
* onto the sequence being constructed.
|
* onto the sequence being constructed.
|
||||||
*/
|
*/
|
||||||
pure fn build_sized(size: uint,
|
fn build_sized(size: uint, builder: &fn(push: &fn(A))) -> Self;
|
||||||
builder: &fn(push: &pure fn(A))) -> Self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn eachi<A,IA:BaseIter<A>>(self: &IA,
|
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) {
|
||||||
blk: &fn(uint, &A) -> bool) {
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
if !blk(i, a) { break; }
|
if !blk(i, a) { break; }
|
||||||
|
@ -104,8 +101,7 @@ pub pure fn eachi<A,IA:BaseIter<A>>(self: &IA,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn all<A,IA:BaseIter<A>>(self: &IA,
|
pub fn all<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
|
||||||
blk: &fn(&A) -> bool) -> bool {
|
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
if !blk(a) { return false; }
|
if !blk(a) { return false; }
|
||||||
}
|
}
|
||||||
|
@ -113,8 +109,7 @@ pub pure fn all<A,IA:BaseIter<A>>(self: &IA,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn any<A,IA:BaseIter<A>>(self: &IA,
|
pub fn any<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
|
||||||
blk: &fn(&A) -> bool) -> bool {
|
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
if blk(a) { return true; }
|
if blk(a) { return true; }
|
||||||
}
|
}
|
||||||
|
@ -122,8 +117,9 @@ pub pure fn any<A,IA:BaseIter<A>>(self: &IA,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(
|
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
|
||||||
self: &IA, prd: &fn(&A) -> bool) -> ~[A] {
|
prd: &fn(&A) -> bool)
|
||||||
|
-> ~[A] {
|
||||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
if prd(a) { push(*a); }
|
if prd(a) { push(*a); }
|
||||||
|
@ -132,9 +128,7 @@ pub pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA,
|
pub fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA, op: &fn(&A) -> B) -> ~[B] {
|
||||||
op: &fn(&A) -> B)
|
|
||||||
-> ~[B] {
|
|
||||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
push(op(a));
|
push(op(a));
|
||||||
|
@ -143,8 +137,9 @@ pub pure fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(
|
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
|
||||||
self: &IA, op: &fn(&A) -> IB) -> ~[B] {
|
op: &fn(&A) -> IB)
|
||||||
|
-> ~[B] {
|
||||||
do vec::build |push| {
|
do vec::build |push| {
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
for op(a).each |&b| {
|
for op(a).each |&b| {
|
||||||
|
@ -155,9 +150,8 @@ pub pure fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B,
|
pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
|
||||||
blk: &fn(&B, &A) -> B)
|
-> B {
|
||||||
-> B {
|
|
||||||
let mut b = b0;
|
let mut b = b0;
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
b = blk(&b, a);
|
b = blk(&b, a);
|
||||||
|
@ -166,12 +160,12 @@ pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
|
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
|
||||||
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
|
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
|
pub fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
if *a == *x { return true; }
|
if *a == *x { return true; }
|
||||||
}
|
}
|
||||||
|
@ -179,7 +173,7 @@ pub pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
|
pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
|
||||||
do foldl(self, 0) |count, value| {
|
do foldl(self, 0) |count, value| {
|
||||||
if *value == *x {
|
if *value == *x {
|
||||||
*count + 1
|
*count + 1
|
||||||
|
@ -190,9 +184,8 @@ pub pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
pub fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||||
-> Option<uint>
|
-> Option<uint> {
|
||||||
{
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
if f(a) { return Some(i); }
|
if f(a) { return Some(i); }
|
||||||
|
@ -206,7 +199,7 @@ pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||||
// it would have to be implemented with foldr, which is too inefficient.
|
// it would have to be implemented with foldr, which is too inefficient.
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn repeat(times: uint, blk: &fn() -> bool) {
|
pub fn repeat(times: uint, blk: &fn() -> bool) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < times {
|
while i < times {
|
||||||
if !blk() { break }
|
if !blk() { break }
|
||||||
|
@ -215,7 +208,7 @@ pub pure fn repeat(times: uint, blk: &fn() -> bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
&Some(ref a_) if *a_ < *b => {
|
&Some(ref a_) if *a_ < *b => {
|
||||||
|
@ -230,7 +223,7 @@ pub pure fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
&Some(ref a_) if *a_ > *b => {
|
&Some(ref a_) if *a_ > *b => {
|
||||||
|
@ -245,8 +238,8 @@ pub pure fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn find<A:Copy,IA:BaseIter<A>>(self: &IA,
|
pub fn find<A:Copy,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||||
f: &fn(&A) -> bool) -> Option<A> {
|
-> Option<A> {
|
||||||
for self.each |i| {
|
for self.each |i| {
|
||||||
if f(i) { return Some(*i) }
|
if f(i) { return Some(*i) }
|
||||||
}
|
}
|
||||||
|
@ -266,8 +259,7 @@ pub pure fn find<A:Copy,IA:BaseIter<A>>(self: &IA,
|
||||||
* onto the sequence being constructed.
|
* onto the sequence being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn build<A,B: Buildable<A>>(builder: &fn(push: &pure fn(A)))
|
pub fn build<A,B: Buildable<A>>(builder: &fn(push: &fn(A))) -> B {
|
||||||
-> B {
|
|
||||||
Buildable::build_sized(4, builder)
|
Buildable::build_sized(4, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,10 +277,8 @@ pub pure fn build<A,B: Buildable<A>>(builder: &fn(push: &pure fn(A)))
|
||||||
* onto the sequence being constructed.
|
* onto the sequence being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn build_sized_opt<A,B: Buildable<A>>(
|
pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,
|
||||||
size: Option<uint>,
|
builder: &fn(push: &fn(A))) -> B {
|
||||||
builder: &fn(push: &pure fn(A))) -> B {
|
|
||||||
|
|
||||||
Buildable::build_sized(size.get_or_default(4), builder)
|
Buildable::build_sized(size.get_or_default(4), builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,8 +302,7 @@ pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
|
||||||
* to the value returned by the function `op`.
|
* to the value returned by the function `op`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint,
|
pub fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
|
||||||
op: InitOp<T>) -> BT {
|
|
||||||
do Buildable::build_sized(n_elts) |push| {
|
do Buildable::build_sized(n_elts) |push| {
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n_elts { push(op(i)); i += 1u; }
|
while i < n_elts { push(op(i)); i += 1u; }
|
||||||
|
@ -327,8 +316,7 @@ pub pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint,
|
||||||
* to the value `t`.
|
* to the value `t`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint,
|
pub fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint, t: T) -> BT {
|
||||||
t: T) -> BT {
|
|
||||||
do Buildable::build_sized(n_elts) |push| {
|
do Buildable::build_sized(n_elts) |push| {
|
||||||
let mut i: uint = 0;
|
let mut i: uint = 0;
|
||||||
while i < n_elts { push(t); i += 1; }
|
while i < n_elts { push(t); i += 1; }
|
||||||
|
@ -337,8 +325,8 @@ pub pure fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint,
|
||||||
|
|
||||||
/// Appends two generic sequences.
|
/// Appends two generic sequences.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(
|
pub fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(lhs: &IT, rhs: &IT)
|
||||||
lhs: &IT, rhs: &IT) -> BT {
|
-> BT {
|
||||||
let size_opt = lhs.size_hint().chain_ref(
|
let size_opt = lhs.size_hint().chain_ref(
|
||||||
|sz1| rhs.size_hint().map(|sz2| *sz1+*sz2));
|
|sz1| rhs.size_hint().map(|sz2| *sz1+*sz2));
|
||||||
do build_sized_opt(size_opt) |push| {
|
do build_sized_opt(size_opt) |push| {
|
||||||
|
@ -350,8 +338,7 @@ pub pure fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(
|
||||||
/// Copies a generic sequence, possibly converting it to a different
|
/// Copies a generic sequence, possibly converting it to a different
|
||||||
/// type of sequence.
|
/// type of sequence.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(
|
pub fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(v: &IT) -> BT {
|
||||||
v: &IT) -> BT {
|
|
||||||
do build_sized_opt(v.size_hint()) |push| {
|
do build_sized_opt(v.size_hint()) |push| {
|
||||||
for v.each |x| { push(*x); }
|
for v.each |x| { push(*x); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,13 @@ pub mod raw {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||||
//! Determine if two shared boxes point to the same object
|
//! Determine if two shared boxes point to the same object
|
||||||
unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) }
|
unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
|
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
|
||||||
//! Determine if two mutable shared boxes point to the same object
|
//! Determine if two mutable shared boxes point to the same object
|
||||||
unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) }
|
unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) }
|
||||||
}
|
}
|
||||||
|
@ -51,41 +51,41 @@ pub pure fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Eq> Eq for @T {
|
impl<T:Eq> Eq for @T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
|
fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
|
fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Eq> Eq for @mut T {
|
impl<T:Eq> Eq for @mut T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &@mut T) -> bool { *(*self) == *(*other) }
|
fn eq(&self, other: &@mut T) -> bool { *(*self) == *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &@mut T) -> bool { *(*self) != *(*other) }
|
fn ne(&self, other: &@mut T) -> bool { *(*self) != *(*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Ord> Ord for @T {
|
impl<T:Ord> Ord for @T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
|
fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
|
fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
|
fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
|
fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Ord> Ord for @mut T {
|
impl<T:Ord> Ord for @mut T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &@mut T) -> bool { *(*self) < *(*other) }
|
fn lt(&self, other: &@mut T) -> bool { *(*self) < *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &@mut T) -> bool { *(*self) <= *(*other) }
|
fn le(&self, other: &@mut T) -> bool { *(*self) <= *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) }
|
fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
|
fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub impl<T> Data<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
|
fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
|
||||||
op(&const self.value)
|
op(&const self.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,25 +20,25 @@ use cmp::{Eq, Ord, TotalOrd, Ordering, Equal};
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Eq for () {
|
impl Eq for () {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, _other: &()) -> bool { true }
|
fn eq(&self, _other: &()) -> bool { true }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, _other: &()) -> bool { false }
|
fn ne(&self, _other: &()) -> bool { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Ord for () {
|
impl Ord for () {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, _other: &()) -> bool { false }
|
fn lt(&self, _other: &()) -> bool { false }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, _other: &()) -> bool { true }
|
fn le(&self, _other: &()) -> bool { true }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, _other: &()) -> bool { true }
|
fn ge(&self, _other: &()) -> bool { true }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, _other: &()) -> bool { false }
|
fn gt(&self, _other: &()) -> bool { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl TotalOrd for () {
|
impl TotalOrd for () {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn cmp(&self, _other: &()) -> Ordering { Equal }
|
fn cmp(&self, _other: &()) -> Ordering { Equal }
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ macro_rules! delegate(
|
||||||
),*
|
),*
|
||||||
) -> $rv:ty = $bound_name:path
|
) -> $rv:ty = $bound_name:path
|
||||||
) => (
|
) => (
|
||||||
pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
|
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
|
||||||
unsafe {
|
unsafe {
|
||||||
$bound_name($( $arg ),*)
|
$bound_name($( $arg ),*)
|
||||||
}
|
}
|
||||||
|
@ -109,57 +109,59 @@ pub const infinity: f32 = 1.0_f32/0.0_f32;
|
||||||
pub const neg_infinity: f32 = -1.0_f32/0.0_f32;
|
pub const neg_infinity: f32 = -1.0_f32/0.0_f32;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_NaN(f: f32) -> bool { f != f }
|
pub fn is_NaN(f: f32) -> bool { f != f }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn add(x: f32, y: f32) -> f32 { return x + y; }
|
pub fn add(x: f32, y: f32) -> f32 { return x + y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn sub(x: f32, y: f32) -> f32 { return x - y; }
|
pub fn sub(x: f32, y: f32) -> f32 { return x - y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mul(x: f32, y: f32) -> f32 { return x * y; }
|
pub fn mul(x: f32, y: f32) -> f32 { return x * y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn div(x: f32, y: f32) -> f32 { return x / y; }
|
pub fn div(x: f32, y: f32) -> f32 { return x / y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn rem(x: f32, y: f32) -> f32 { return x % y; }
|
pub fn rem(x: f32, y: f32) -> f32 { return x % y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn lt(x: f32, y: f32) -> bool { return x < y; }
|
pub fn lt(x: f32, y: f32) -> bool { return x < y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn le(x: f32, y: f32) -> bool { return x <= y; }
|
pub fn le(x: f32, y: f32) -> bool { return x <= y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn eq(x: f32, y: f32) -> bool { return x == y; }
|
pub fn eq(x: f32, y: f32) -> bool { return x == y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ne(x: f32, y: f32) -> bool { return x != y; }
|
pub fn ne(x: f32, y: f32) -> bool { return x != y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ge(x: f32, y: f32) -> bool { return x >= y; }
|
pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn gt(x: f32, y: f32) -> bool { return x > y; }
|
pub fn gt(x: f32, y: f32) -> bool { return x > y; }
|
||||||
|
|
||||||
/// Returns `x` rounded down
|
/// Returns `x` rounded down
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn floor(x: f32) -> f32 { unsafe { floorf32(x) } }
|
pub fn floor(x: f32) -> f32 { unsafe { floorf32(x) } }
|
||||||
|
|
||||||
// FIXME (#1999): replace the predicates below with llvm intrinsics or
|
// FIXME (#1999): replace the predicates below with llvm intrinsics or
|
||||||
// calls to the libmath macros in the rust runtime for performance.
|
// calls to the libmath macros in the rust runtime for performance.
|
||||||
|
|
||||||
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
|
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_positive(x: f32) -> bool
|
pub fn is_positive(x: f32) -> bool {
|
||||||
{ return x > 0.0f32 || (1.0f32/x) == infinity; }
|
x > 0.0f32 || (1.0f32/x) == infinity
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
|
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_negative(x: f32) -> bool
|
pub fn is_negative(x: f32) -> bool {
|
||||||
{ return x < 0.0f32 || (1.0f32/x) == neg_infinity; }
|
x < 0.0f32 || (1.0f32/x) == neg_infinity
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
|
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
|
||||||
|
@ -167,7 +169,7 @@ pub pure fn is_negative(x: f32) -> bool
|
||||||
* This is the same as `f32::is_negative`.
|
* This is the same as `f32::is_negative`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonpositive(x: f32) -> bool {
|
pub fn is_nonpositive(x: f32) -> bool {
|
||||||
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
|
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,25 +179,25 @@ pub pure fn is_nonpositive(x: f32) -> bool {
|
||||||
* This is the same as `f32::is_positive`.)
|
* This is the same as `f32::is_positive`.)
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonnegative(x: f32) -> bool {
|
pub fn is_nonnegative(x: f32) -> bool {
|
||||||
return x > 0.0f32 || (1.0f32/x) == infinity;
|
return x > 0.0f32 || (1.0f32/x) == infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if `x` is a zero number (positive or negative zero)
|
/// Returns true if `x` is a zero number (positive or negative zero)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_zero(x: f32) -> bool {
|
pub fn is_zero(x: f32) -> bool {
|
||||||
return x == 0.0f32 || x == -0.0f32;
|
return x == 0.0f32 || x == -0.0f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if `x`is an infinite number
|
/// Returns true if `x`is an infinite number
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_infinite(x: f32) -> bool {
|
pub fn is_infinite(x: f32) -> bool {
|
||||||
return x == infinity || x == neg_infinity;
|
return x == infinity || x == neg_infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if `x`is a finite number
|
/// Returns true if `x`is a finite number
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_finite(x: f32) -> bool {
|
pub fn is_finite(x: f32) -> bool {
|
||||||
return !(is_NaN(x) || is_infinite(x));
|
return !(is_NaN(x) || is_infinite(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,43 +248,43 @@ pub mod consts {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn signbit(x: f32) -> int {
|
pub fn signbit(x: f32) -> int {
|
||||||
if is_negative(x) { return 1; } else { return 0; }
|
if is_negative(x) { return 1; } else { return 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn logarithm(n: f32, b: f32) -> f32 {
|
pub fn logarithm(n: f32, b: f32) -> f32 {
|
||||||
return log2(n) / log2(b);
|
return log2(n) / log2(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl cmp::Eq for f32 {
|
impl cmp::Eq for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
|
fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &f32) -> bool { (*self) != (*other) }
|
fn ne(&self, other: &f32) -> bool { (*self) != (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl cmp::Ord for f32 {
|
impl cmp::Ord for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
|
fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &f32) -> bool { (*self) <= (*other) }
|
fn le(&self, other: &f32) -> bool { (*self) <= (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
|
fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
|
fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Zero for f32 {
|
impl num::Zero for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn zero() -> f32 { 0.0 }
|
fn zero() -> f32 { 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::One for f32 {
|
impl num::One for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn one() -> f32 { 1.0 }
|
fn one() -> f32 { 1.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NumCast for f32 {
|
impl NumCast for f32 {
|
||||||
|
@ -290,53 +292,53 @@ impl NumCast for f32 {
|
||||||
* Cast `n` to an `f32`
|
* Cast `n` to an `f32`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> f32 { n.to_f32() }
|
fn from<N:NumCast>(n: N) -> f32 { n.to_f32() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Add<f32,f32> for f32 {
|
impl ops::Add<f32,f32> for f32 {
|
||||||
pure fn add(&self, other: &f32) -> f32 { *self + *other }
|
fn add(&self, other: &f32) -> f32 { *self + *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Sub<f32,f32> for f32 {
|
impl ops::Sub<f32,f32> for f32 {
|
||||||
pure fn sub(&self, other: &f32) -> f32 { *self - *other }
|
fn sub(&self, other: &f32) -> f32 { *self - *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Mul<f32,f32> for f32 {
|
impl ops::Mul<f32,f32> for f32 {
|
||||||
pure fn mul(&self, other: &f32) -> f32 { *self * *other }
|
fn mul(&self, other: &f32) -> f32 { *self * *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Div<f32,f32> for f32 {
|
impl ops::Div<f32,f32> for f32 {
|
||||||
pure fn div(&self, other: &f32) -> f32 { *self / *other }
|
fn div(&self, other: &f32) -> f32 { *self / *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Modulo<f32,f32> for f32 {
|
impl ops::Modulo<f32,f32> for f32 {
|
||||||
pure fn modulo(&self, other: &f32) -> f32 { *self % *other }
|
fn modulo(&self, other: &f32) -> f32 { *self % *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Neg<f32> for f32 {
|
impl ops::Neg<f32> for f32 {
|
||||||
pure fn neg(&self) -> f32 { -*self }
|
fn neg(&self) -> f32 { -*self }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Round for f32 {
|
impl num::Round for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn round(&self, mode: num::RoundMode) -> f32 {
|
fn round(&self, mode: num::RoundMode) -> f32 {
|
||||||
match mode {
|
match mode {
|
||||||
num::RoundDown => floor(*self),
|
num::RoundDown => floor(*self),
|
||||||
num::RoundUp => ceil(*self),
|
num::RoundUp => ceil(*self),
|
||||||
|
@ -348,11 +350,11 @@ impl num::Round for f32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn floor(&self) -> f32 { floor(*self) }
|
fn floor(&self) -> f32 { floor(*self) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ceil(&self) -> f32 { ceil(*self) }
|
fn ceil(&self) -> f32 { ceil(*self) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn fract(&self) -> f32 {
|
fn fract(&self) -> f32 {
|
||||||
if is_negative(*self) {
|
if is_negative(*self) {
|
||||||
(*self) - ceil(*self)
|
(*self) - ceil(*self)
|
||||||
} else {
|
} else {
|
||||||
|
@ -373,7 +375,7 @@ impl num::Round for f32 {
|
||||||
* * num - The float value
|
* * num - The float value
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str(num: f32) -> ~str {
|
pub fn to_str(num: f32) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
|
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
|
||||||
r
|
r
|
||||||
|
@ -387,7 +389,7 @@ pub pure fn to_str(num: f32) -> ~str {
|
||||||
* * num - The float value
|
* * num - The float value
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_hex(num: f32) -> ~str {
|
pub fn to_str_hex(num: f32) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
|
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
|
||||||
r
|
r
|
||||||
|
@ -408,7 +410,7 @@ pub pure fn to_str_hex(num: f32) -> ~str {
|
||||||
* are expected, use `to_str_radix_special()` instead.
|
* are expected, use `to_str_radix_special()` instead.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix(num: f32, rdx: uint) -> ~str {
|
pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
|
||||||
let (r, special) = strconv::to_str_common(
|
let (r, special) = strconv::to_str_common(
|
||||||
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
|
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
|
||||||
if special { fail!(~"number has a special value, \
|
if special { fail!(~"number has a special value, \
|
||||||
|
@ -426,7 +428,7 @@ pub pure fn to_str_radix(num: f32, rdx: uint) -> ~str {
|
||||||
* * radix - The base to use
|
* * radix - The base to use
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
|
pub fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
|
||||||
strconv::to_str_common(&num, rdx, true,
|
strconv::to_str_common(&num, rdx, true,
|
||||||
strconv::SignNeg, strconv::DigAll)
|
strconv::SignNeg, strconv::DigAll)
|
||||||
}
|
}
|
||||||
|
@ -441,7 +443,7 @@ pub pure fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
|
||||||
* * digits - The number of significant digits
|
* * digits - The number of significant digits
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_exact(num: f32, dig: uint) -> ~str {
|
pub fn to_str_exact(num: f32, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
|
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
|
||||||
r
|
r
|
||||||
|
@ -457,7 +459,7 @@ pub pure fn to_str_exact(num: f32, dig: uint) -> ~str {
|
||||||
* * digits - The number of significant digits
|
* * digits - The number of significant digits
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_digits(num: f32, dig: uint) -> ~str {
|
pub fn to_str_digits(num: f32, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
|
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
|
||||||
r
|
r
|
||||||
|
@ -465,12 +467,12 @@ pub pure fn to_str_digits(num: f32, dig: uint) -> ~str {
|
||||||
|
|
||||||
impl to_str::ToStr for f32 {
|
impl to_str::ToStr for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
|
fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::ToStrRadix for f32 {
|
impl num::ToStrRadix for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str_radix(&self, rdx: uint) -> ~str {
|
fn to_str_radix(&self, rdx: uint) -> ~str {
|
||||||
to_str_radix(*self, rdx)
|
to_str_radix(*self, rdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,7 +505,7 @@ impl num::ToStrRadix for f32 {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str(num: &str) -> Option<f32> {
|
pub fn from_str(num: &str) -> Option<f32> {
|
||||||
strconv::from_str_common(num, 10u, true, true, true,
|
strconv::from_str_common(num, 10u, true, true, true,
|
||||||
strconv::ExpDec, false)
|
strconv::ExpDec, false)
|
||||||
}
|
}
|
||||||
|
@ -536,7 +538,7 @@ pub pure fn from_str(num: &str) -> Option<f32> {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_hex(num: &str) -> Option<f32> {
|
pub fn from_str_hex(num: &str) -> Option<f32> {
|
||||||
strconv::from_str_common(num, 16u, true, true, true,
|
strconv::from_str_common(num, 16u, true, true, true,
|
||||||
strconv::ExpBin, false)
|
strconv::ExpBin, false)
|
||||||
}
|
}
|
||||||
|
@ -561,19 +563,19 @@ pub pure fn from_str_hex(num: &str) -> Option<f32> {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
|
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
|
||||||
strconv::from_str_common(num, rdx, true, true, false,
|
strconv::from_str_common(num, rdx, true, true, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl from_str::FromStr for f32 {
|
impl from_str::FromStr for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str(val: &str) -> Option<f32> { from_str(val) }
|
fn from_str(val: &str) -> Option<f32> { from_str(val) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::FromStrRadix for f32 {
|
impl num::FromStrRadix for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str_radix(val: &str, rdx: uint) -> Option<f32> {
|
fn from_str_radix(val: &str, rdx: uint) -> Option<f32> {
|
||||||
from_str_radix(val, rdx)
|
from_str_radix(val, rdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ macro_rules! delegate(
|
||||||
),*
|
),*
|
||||||
) -> $rv:ty = $bound_name:path
|
) -> $rv:ty = $bound_name:path
|
||||||
) => (
|
) => (
|
||||||
pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
|
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
|
||||||
unsafe {
|
unsafe {
|
||||||
$bound_name($( $arg ),*)
|
$bound_name($( $arg ),*)
|
||||||
}
|
}
|
||||||
|
@ -136,49 +136,49 @@ pub const infinity: f64 = 1.0_f64/0.0_f64;
|
||||||
pub const neg_infinity: f64 = -1.0_f64/0.0_f64;
|
pub const neg_infinity: f64 = -1.0_f64/0.0_f64;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_NaN(f: f64) -> bool { f != f }
|
pub fn is_NaN(f: f64) -> bool { f != f }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn add(x: f64, y: f64) -> f64 { return x + y; }
|
pub fn add(x: f64, y: f64) -> f64 { return x + y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn sub(x: f64, y: f64) -> f64 { return x - y; }
|
pub fn sub(x: f64, y: f64) -> f64 { return x - y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mul(x: f64, y: f64) -> f64 { return x * y; }
|
pub fn mul(x: f64, y: f64) -> f64 { return x * y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn div(x: f64, y: f64) -> f64 { return x / y; }
|
pub fn div(x: f64, y: f64) -> f64 { return x / y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn rem(x: f64, y: f64) -> f64 { return x % y; }
|
pub fn rem(x: f64, y: f64) -> f64 { return x % y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn lt(x: f64, y: f64) -> bool { return x < y; }
|
pub fn lt(x: f64, y: f64) -> bool { return x < y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn le(x: f64, y: f64) -> bool { return x <= y; }
|
pub fn le(x: f64, y: f64) -> bool { return x <= y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn eq(x: f64, y: f64) -> bool { return x == y; }
|
pub fn eq(x: f64, y: f64) -> bool { return x == y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ne(x: f64, y: f64) -> bool { return x != y; }
|
pub fn ne(x: f64, y: f64) -> bool { return x != y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ge(x: f64, y: f64) -> bool { return x >= y; }
|
pub fn ge(x: f64, y: f64) -> bool { return x >= y; }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn gt(x: f64, y: f64) -> bool { return x > y; }
|
pub fn gt(x: f64, y: f64) -> bool { return x > y; }
|
||||||
|
|
||||||
/// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
|
/// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_positive(x: f64) -> bool
|
pub fn is_positive(x: f64) -> bool
|
||||||
{ return x > 0.0f64 || (1.0f64/x) == infinity; }
|
{ return x > 0.0f64 || (1.0f64/x) == infinity; }
|
||||||
|
|
||||||
/// Returns true if `x` is a negative number, including -0.0f640 and -Infinity
|
/// Returns true if `x` is a negative number, including -0.0f640 and -Infinity
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_negative(x: f64) -> bool
|
pub fn is_negative(x: f64) -> bool
|
||||||
{ return x < 0.0f64 || (1.0f64/x) == neg_infinity; }
|
{ return x < 0.0f64 || (1.0f64/x) == neg_infinity; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,7 +187,7 @@ pub pure fn is_negative(x: f64) -> bool
|
||||||
* This is the same as `f64::is_negative`.
|
* This is the same as `f64::is_negative`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonpositive(x: f64) -> bool {
|
pub fn is_nonpositive(x: f64) -> bool {
|
||||||
return x < 0.0f64 || (1.0f64/x) == neg_infinity;
|
return x < 0.0f64 || (1.0f64/x) == neg_infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,31 +197,31 @@ pub pure fn is_nonpositive(x: f64) -> bool {
|
||||||
* This is the same as `f64::positive`.
|
* This is the same as `f64::positive`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonnegative(x: f64) -> bool {
|
pub fn is_nonnegative(x: f64) -> bool {
|
||||||
return x > 0.0f64 || (1.0f64/x) == infinity;
|
return x > 0.0f64 || (1.0f64/x) == infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if `x` is a zero number (positive or negative zero)
|
/// Returns true if `x` is a zero number (positive or negative zero)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_zero(x: f64) -> bool {
|
pub fn is_zero(x: f64) -> bool {
|
||||||
return x == 0.0f64 || x == -0.0f64;
|
return x == 0.0f64 || x == -0.0f64;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if `x`is an infinite number
|
/// Returns true if `x`is an infinite number
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_infinite(x: f64) -> bool {
|
pub fn is_infinite(x: f64) -> bool {
|
||||||
return x == infinity || x == neg_infinity;
|
return x == infinity || x == neg_infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if `x` is a finite number
|
/// Returns true if `x` is a finite number
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_finite(x: f64) -> bool {
|
pub fn is_finite(x: f64) -> bool {
|
||||||
return !(is_NaN(x) || is_infinite(x));
|
return !(is_NaN(x) || is_infinite(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `x` rounded down
|
/// Returns `x` rounded down
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn floor(x: f64) -> f64 { unsafe { floorf64(x) } }
|
pub fn floor(x: f64) -> f64 { unsafe { floorf64(x) } }
|
||||||
|
|
||||||
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
|
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
|
||||||
|
|
||||||
|
@ -270,33 +270,33 @@ pub mod consts {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn signbit(x: f64) -> int {
|
pub fn signbit(x: f64) -> int {
|
||||||
if is_negative(x) { return 1; } else { return 0; }
|
if is_negative(x) { return 1; } else { return 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn logarithm(n: f64, b: f64) -> f64 {
|
pub fn logarithm(n: f64, b: f64) -> f64 {
|
||||||
return log2(n) / log2(b);
|
return log2(n) / log2(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl cmp::Eq for f64 {
|
impl cmp::Eq for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
|
fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &f64) -> bool { (*self) != (*other) }
|
fn ne(&self, other: &f64) -> bool { (*self) != (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl cmp::Ord for f64 {
|
impl cmp::Ord for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
|
fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &f64) -> bool { (*self) <= (*other) }
|
fn le(&self, other: &f64) -> bool { (*self) <= (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
|
fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
|
fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NumCast for f64 {
|
impl NumCast for f64 {
|
||||||
|
@ -304,63 +304,63 @@ impl NumCast for f64 {
|
||||||
* Cast `n` to an `f64`
|
* Cast `n` to an `f64`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> f64 { n.to_f64() }
|
fn from<N:NumCast>(n: N) -> f64 { n.to_f64() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Zero for f64 {
|
impl num::Zero for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn zero() -> f64 { 0.0 }
|
fn zero() -> f64 { 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::One for f64 {
|
impl num::One for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn one() -> f64 { 1.0 }
|
fn one() -> f64 { 1.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Add<f64,f64> for f64 {
|
impl ops::Add<f64,f64> for f64 {
|
||||||
pure fn add(&self, other: &f64) -> f64 { *self + *other }
|
fn add(&self, other: &f64) -> f64 { *self + *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Sub<f64,f64> for f64 {
|
impl ops::Sub<f64,f64> for f64 {
|
||||||
pure fn sub(&self, other: &f64) -> f64 { *self - *other }
|
fn sub(&self, other: &f64) -> f64 { *self - *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Mul<f64,f64> for f64 {
|
impl ops::Mul<f64,f64> for f64 {
|
||||||
pure fn mul(&self, other: &f64) -> f64 { *self * *other }
|
fn mul(&self, other: &f64) -> f64 { *self * *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Div<f64,f64> for f64 {
|
impl ops::Div<f64,f64> for f64 {
|
||||||
pure fn div(&self, other: &f64) -> f64 { *self / *other }
|
fn div(&self, other: &f64) -> f64 { *self / *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Modulo<f64,f64> for f64 {
|
impl ops::Modulo<f64,f64> for f64 {
|
||||||
pure fn modulo(&self, other: &f64) -> f64 { *self % *other }
|
fn modulo(&self, other: &f64) -> f64 { *self % *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Neg<f64> for f64 {
|
impl ops::Neg<f64> for f64 {
|
||||||
pure fn neg(&self) -> f64 { -*self }
|
fn neg(&self) -> f64 { -*self }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Round for f64 {
|
impl num::Round for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn round(&self, mode: num::RoundMode) -> f64 {
|
fn round(&self, mode: num::RoundMode) -> f64 {
|
||||||
match mode {
|
match mode {
|
||||||
num::RoundDown => floor(*self),
|
num::RoundDown => floor(*self),
|
||||||
num::RoundUp => ceil(*self),
|
num::RoundUp => ceil(*self),
|
||||||
|
@ -372,11 +372,11 @@ impl num::Round for f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn floor(&self) -> f64 { floor(*self) }
|
fn floor(&self) -> f64 { floor(*self) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ceil(&self) -> f64 { ceil(*self) }
|
fn ceil(&self) -> f64 { ceil(*self) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn fract(&self) -> f64 {
|
fn fract(&self) -> f64 {
|
||||||
if is_negative(*self) {
|
if is_negative(*self) {
|
||||||
(*self) - ceil(*self)
|
(*self) - ceil(*self)
|
||||||
} else {
|
} else {
|
||||||
|
@ -397,7 +397,7 @@ impl num::Round for f64 {
|
||||||
* * num - The float value
|
* * num - The float value
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str(num: f64) -> ~str {
|
pub fn to_str(num: f64) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
|
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
|
||||||
r
|
r
|
||||||
|
@ -411,7 +411,7 @@ pub pure fn to_str(num: f64) -> ~str {
|
||||||
* * num - The float value
|
* * num - The float value
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_hex(num: f64) -> ~str {
|
pub fn to_str_hex(num: f64) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
|
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
|
||||||
r
|
r
|
||||||
|
@ -432,7 +432,7 @@ pub pure fn to_str_hex(num: f64) -> ~str {
|
||||||
* are expected, use `to_str_radix_special()` instead.
|
* are expected, use `to_str_radix_special()` instead.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix(num: f64, rdx: uint) -> ~str {
|
pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
|
||||||
let (r, special) = strconv::to_str_common(
|
let (r, special) = strconv::to_str_common(
|
||||||
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
|
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
|
||||||
if special { fail!(~"number has a special value, \
|
if special { fail!(~"number has a special value, \
|
||||||
|
@ -450,7 +450,7 @@ pub pure fn to_str_radix(num: f64, rdx: uint) -> ~str {
|
||||||
* * radix - The base to use
|
* * radix - The base to use
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
|
pub fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
|
||||||
strconv::to_str_common(&num, rdx, true,
|
strconv::to_str_common(&num, rdx, true,
|
||||||
strconv::SignNeg, strconv::DigAll)
|
strconv::SignNeg, strconv::DigAll)
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ pub pure fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
|
||||||
* * digits - The number of significant digits
|
* * digits - The number of significant digits
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_exact(num: f64, dig: uint) -> ~str {
|
pub fn to_str_exact(num: f64, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
|
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
|
||||||
r
|
r
|
||||||
|
@ -481,7 +481,7 @@ pub pure fn to_str_exact(num: f64, dig: uint) -> ~str {
|
||||||
* * digits - The number of significant digits
|
* * digits - The number of significant digits
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_digits(num: f64, dig: uint) -> ~str {
|
pub fn to_str_digits(num: f64, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
|
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
|
||||||
r
|
r
|
||||||
|
@ -489,12 +489,12 @@ pub pure fn to_str_digits(num: f64, dig: uint) -> ~str {
|
||||||
|
|
||||||
impl to_str::ToStr for f64 {
|
impl to_str::ToStr for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
|
fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::ToStrRadix for f64 {
|
impl num::ToStrRadix for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str_radix(&self, rdx: uint) -> ~str {
|
fn to_str_radix(&self, rdx: uint) -> ~str {
|
||||||
to_str_radix(*self, rdx)
|
to_str_radix(*self, rdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -527,7 +527,7 @@ impl num::ToStrRadix for f64 {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str(num: &str) -> Option<f64> {
|
pub fn from_str(num: &str) -> Option<f64> {
|
||||||
strconv::from_str_common(num, 10u, true, true, true,
|
strconv::from_str_common(num, 10u, true, true, true,
|
||||||
strconv::ExpDec, false)
|
strconv::ExpDec, false)
|
||||||
}
|
}
|
||||||
|
@ -560,7 +560,7 @@ pub pure fn from_str(num: &str) -> Option<f64> {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_hex(num: &str) -> Option<f64> {
|
pub fn from_str_hex(num: &str) -> Option<f64> {
|
||||||
strconv::from_str_common(num, 16u, true, true, true,
|
strconv::from_str_common(num, 16u, true, true, true,
|
||||||
strconv::ExpBin, false)
|
strconv::ExpBin, false)
|
||||||
}
|
}
|
||||||
|
@ -585,19 +585,19 @@ pub pure fn from_str_hex(num: &str) -> Option<f64> {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
|
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
|
||||||
strconv::from_str_common(num, rdx, true, true, false,
|
strconv::from_str_common(num, rdx, true, true, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl from_str::FromStr for f64 {
|
impl from_str::FromStr for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str(val: &str) -> Option<f64> { from_str(val) }
|
fn from_str(val: &str) -> Option<f64> { from_str(val) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::FromStrRadix for f64 {
|
impl num::FromStrRadix for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str_radix(val: &str, rdx: uint) -> Option<f64> {
|
fn from_str_radix(val: &str, rdx: uint) -> Option<f64> {
|
||||||
from_str_radix(val, rdx)
|
from_str_radix(val, rdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub mod consts {
|
||||||
* * num - The float value
|
* * num - The float value
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str(num: float) -> ~str {
|
pub fn to_str(num: float) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
|
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
|
||||||
r
|
r
|
||||||
|
@ -117,7 +117,7 @@ pub pure fn to_str(num: float) -> ~str {
|
||||||
* * num - The float value
|
* * num - The float value
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_hex(num: float) -> ~str {
|
pub fn to_str_hex(num: float) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
|
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
|
||||||
r
|
r
|
||||||
|
@ -138,7 +138,7 @@ pub pure fn to_str_hex(num: float) -> ~str {
|
||||||
* are expected, use `to_str_radix_special()` instead.
|
* are expected, use `to_str_radix_special()` instead.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix(num: float, radix: uint) -> ~str {
|
pub fn to_str_radix(num: float, radix: uint) -> ~str {
|
||||||
let (r, special) = strconv::to_str_common(
|
let (r, special) = strconv::to_str_common(
|
||||||
&num, radix, true, strconv::SignNeg, strconv::DigAll);
|
&num, radix, true, strconv::SignNeg, strconv::DigAll);
|
||||||
if special { fail!(~"number has a special value, \
|
if special { fail!(~"number has a special value, \
|
||||||
|
@ -156,7 +156,7 @@ pub pure fn to_str_radix(num: float, radix: uint) -> ~str {
|
||||||
* * radix - The base to use
|
* * radix - The base to use
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
|
pub fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
|
||||||
strconv::to_str_common(&num, radix, true,
|
strconv::to_str_common(&num, radix, true,
|
||||||
strconv::SignNeg, strconv::DigAll)
|
strconv::SignNeg, strconv::DigAll)
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ pub pure fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
|
||||||
* * digits - The number of significant digits
|
* * digits - The number of significant digits
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_exact(num: float, digits: uint) -> ~str {
|
pub fn to_str_exact(num: float, digits: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigExact(digits));
|
&num, 10u, true, strconv::SignNeg, strconv::DigExact(digits));
|
||||||
r
|
r
|
||||||
|
@ -193,7 +193,7 @@ pub fn test_to_str_exact_do_decimal() {
|
||||||
* * digits - The number of significant digits
|
* * digits - The number of significant digits
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_digits(num: float, digits: uint) -> ~str {
|
pub fn to_str_digits(num: float, digits: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
&num, 10u, true, strconv::SignNeg, strconv::DigMax(digits));
|
&num, 10u, true, strconv::SignNeg, strconv::DigMax(digits));
|
||||||
r
|
r
|
||||||
|
@ -201,12 +201,12 @@ pub pure fn to_str_digits(num: float, digits: uint) -> ~str {
|
||||||
|
|
||||||
impl to_str::ToStr for float {
|
impl to_str::ToStr for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
|
fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::ToStrRadix for float {
|
impl num::ToStrRadix for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str_radix(&self, radix: uint) -> ~str {
|
fn to_str_radix(&self, radix: uint) -> ~str {
|
||||||
to_str_radix(*self, radix)
|
to_str_radix(*self, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ impl num::ToStrRadix for float {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str(num: &str) -> Option<float> {
|
pub fn from_str(num: &str) -> Option<float> {
|
||||||
strconv::from_str_common(num, 10u, true, true, true,
|
strconv::from_str_common(num, 10u, true, true, true,
|
||||||
strconv::ExpDec, false)
|
strconv::ExpDec, false)
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ pub pure fn from_str(num: &str) -> Option<float> {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_hex(num: &str) -> Option<float> {
|
pub fn from_str_hex(num: &str) -> Option<float> {
|
||||||
strconv::from_str_common(num, 16u, true, true, true,
|
strconv::from_str_common(num, 16u, true, true, true,
|
||||||
strconv::ExpBin, false)
|
strconv::ExpBin, false)
|
||||||
}
|
}
|
||||||
|
@ -297,19 +297,19 @@ pub pure fn from_str_hex(num: &str) -> Option<float> {
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_radix(num: &str, radix: uint) -> Option<float> {
|
pub fn from_str_radix(num: &str, radix: uint) -> Option<float> {
|
||||||
strconv::from_str_common(num, radix, true, true, false,
|
strconv::from_str_common(num, radix, true, true, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl from_str::FromStr for float {
|
impl from_str::FromStr for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str(val: &str) -> Option<float> { from_str(val) }
|
fn from_str(val: &str) -> Option<float> { from_str(val) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::FromStrRadix for float {
|
impl num::FromStrRadix for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str_radix(val: &str, radix: uint) -> Option<float> {
|
fn from_str_radix(val: &str, radix: uint) -> Option<float> {
|
||||||
from_str_radix(val, radix)
|
from_str_radix(val, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ impl num::FromStrRadix for float {
|
||||||
*
|
*
|
||||||
* `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
|
* `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
|
||||||
*/
|
*/
|
||||||
pub pure fn pow_with_uint(base: uint, pow: uint) -> float {
|
pub fn pow_with_uint(base: uint, pow: uint) -> float {
|
||||||
if base == 0u {
|
if base == 0u {
|
||||||
if pow == 0u {
|
if pow == 0u {
|
||||||
return NaN as float;
|
return NaN as float;
|
||||||
|
@ -351,69 +351,69 @@ pub pure fn pow_with_uint(base: uint, pow: uint) -> float {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
|
pub fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
|
pub fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
|
pub fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
|
pub fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
|
pub fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
|
pub fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
|
pub fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
|
pub fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn abs(x: float) -> float {
|
pub fn abs(x: float) -> float {
|
||||||
unsafe { f64::abs(x as f64) as float }
|
unsafe { f64::abs(x as f64) as float }
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn sqrt(x: float) -> float {
|
pub fn sqrt(x: float) -> float {
|
||||||
unsafe { f64::sqrt(x as f64) as float }
|
unsafe { f64::sqrt(x as f64) as float }
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn atan(x: float) -> float {
|
pub fn atan(x: float) -> float {
|
||||||
unsafe { f64::atan(x as f64) as float }
|
unsafe { f64::atan(x as f64) as float }
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn sin(x: float) -> float {
|
pub fn sin(x: float) -> float {
|
||||||
unsafe { f64::sin(x as f64) as float }
|
unsafe { f64::sin(x as f64) as float }
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn cos(x: float) -> float {
|
pub fn cos(x: float) -> float {
|
||||||
unsafe { f64::cos(x as f64) as float }
|
unsafe { f64::cos(x as f64) as float }
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn tan(x: float) -> float {
|
pub fn tan(x: float) -> float {
|
||||||
unsafe { f64::tan(x as f64) as float }
|
unsafe { f64::tan(x as f64) as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Eq for float {
|
impl Eq for float {
|
||||||
pure fn eq(&self, other: &float) -> bool { (*self) == (*other) }
|
fn eq(&self, other: &float) -> bool { (*self) == (*other) }
|
||||||
pure fn ne(&self, other: &float) -> bool { (*self) != (*other) }
|
fn ne(&self, other: &float) -> bool { (*self) != (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Ord for float {
|
impl Ord for float {
|
||||||
pure fn lt(&self, other: &float) -> bool { (*self) < (*other) }
|
fn lt(&self, other: &float) -> bool { (*self) < (*other) }
|
||||||
pure fn le(&self, other: &float) -> bool { (*self) <= (*other) }
|
fn le(&self, other: &float) -> bool { (*self) <= (*other) }
|
||||||
pure fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
|
fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
|
||||||
pure fn gt(&self, other: &float) -> bool { (*self) > (*other) }
|
fn gt(&self, other: &float) -> bool { (*self) > (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Zero for float {
|
impl num::Zero for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn zero() -> float { 0.0 }
|
fn zero() -> float { 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::One for float {
|
impl num::One for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn one() -> float { 1.0 }
|
fn one() -> float { 1.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NumCast for float {
|
impl NumCast for float {
|
||||||
|
@ -421,28 +421,28 @@ impl NumCast for float {
|
||||||
* Cast `n` to a `float`
|
* Cast `n` to a `float`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> float { n.to_float() }
|
fn from<N:NumCast>(n: N) -> float { n.to_float() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self }
|
#[inline(always)] fn to_float(&self) -> float { *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Round for float {
|
impl num::Round for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn round(&self, mode: num::RoundMode) -> float {
|
fn round(&self, mode: num::RoundMode) -> float {
|
||||||
match mode {
|
match mode {
|
||||||
num::RoundDown
|
num::RoundDown
|
||||||
=> f64::floor(*self as f64) as float,
|
=> f64::floor(*self as f64) as float,
|
||||||
|
@ -460,11 +460,11 @@ impl num::Round for float {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn floor(&self) -> float { f64::floor(*self as f64) as float}
|
fn floor(&self) -> float { f64::floor(*self as f64) as float}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ceil(&self) -> float { f64::ceil(*self as f64) as float}
|
fn ceil(&self) -> float { f64::ceil(*self as f64) as float}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn fract(&self) -> float {
|
fn fract(&self) -> float {
|
||||||
if is_negative(*self) {
|
if is_negative(*self) {
|
||||||
(*self) - (f64::ceil(*self as f64) as float)
|
(*self) - (f64::ceil(*self as f64) as float)
|
||||||
} else {
|
} else {
|
||||||
|
@ -475,27 +475,27 @@ impl num::Round for float {
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Add<float,float> for float {
|
impl ops::Add<float,float> for float {
|
||||||
pure fn add(&self, other: &float) -> float { *self + *other }
|
fn add(&self, other: &float) -> float { *self + *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Sub<float,float> for float {
|
impl ops::Sub<float,float> for float {
|
||||||
pure fn sub(&self, other: &float) -> float { *self - *other }
|
fn sub(&self, other: &float) -> float { *self - *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Mul<float,float> for float {
|
impl ops::Mul<float,float> for float {
|
||||||
pure fn mul(&self, other: &float) -> float { *self * *other }
|
fn mul(&self, other: &float) -> float { *self * *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Div<float,float> for float {
|
impl ops::Div<float,float> for float {
|
||||||
pure fn div(&self, other: &float) -> float { *self / *other }
|
fn div(&self, other: &float) -> float { *self / *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Modulo<float,float> for float {
|
impl ops::Modulo<float,float> for float {
|
||||||
pure fn modulo(&self, other: &float) -> float { *self % *other }
|
fn modulo(&self, other: &float) -> float { *self % *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Neg<float> for float {
|
impl ops::Neg<float> for float {
|
||||||
pure fn neg(&self) -> float { -*self }
|
fn neg(&self) -> float { -*self }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -28,13 +28,13 @@ pub const min_value: T = (-1 as T) << (bits - 1);
|
||||||
pub const max_value: T = min_value - 1 as T;
|
pub const max_value: T = min_value - 1 as T;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn add(x: T, y: T) -> T { x + y }
|
pub fn add(x: T, y: T) -> T { x + y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn sub(x: T, y: T) -> T { x - y }
|
pub fn sub(x: T, y: T) -> T { x - y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mul(x: T, y: T) -> T { x * y }
|
pub fn mul(x: T, y: T) -> T { x * y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn div(x: T, y: T) -> T { x / y }
|
pub fn div(x: T, y: T) -> T { x / y }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the remainder of y / x.
|
* Returns the remainder of y / x.
|
||||||
|
@ -57,29 +57,29 @@ pub pure fn div(x: T, y: T) -> T { x / y }
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn rem(x: T, y: T) -> T { x % y }
|
pub fn rem(x: T, y: T) -> T { x % y }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn lt(x: T, y: T) -> bool { x < y }
|
pub fn lt(x: T, y: T) -> bool { x < y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn le(x: T, y: T) -> bool { x <= y }
|
pub fn le(x: T, y: T) -> bool { x <= y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn eq(x: T, y: T) -> bool { x == y }
|
pub fn eq(x: T, y: T) -> bool { x == y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ne(x: T, y: T) -> bool { x != y }
|
pub fn ne(x: T, y: T) -> bool { x != y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ge(x: T, y: T) -> bool { x >= y }
|
pub fn ge(x: T, y: T) -> bool { x >= y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn gt(x: T, y: T) -> bool { x > y }
|
pub fn gt(x: T, y: T) -> bool { x > y }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_positive(x: T) -> bool { x > 0 as T }
|
pub fn is_positive(x: T) -> bool { x > 0 as T }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_negative(x: T) -> bool { x < 0 as T }
|
pub fn is_negative(x: T) -> bool { x < 0 as T }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
|
pub fn is_nonpositive(x: T) -> bool { x <= 0 as T }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
pub fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over the range [`lo`..`hi`)
|
* Iterate over the range [`lo`..`hi`)
|
||||||
|
@ -100,7 +100,7 @@ pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// Iterate over the range [`start`,`start`+`step`..`stop`)
|
/// Iterate over the range [`start`,`start`+`step`..`stop`)
|
||||||
pub pure fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
|
pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
|
||||||
let mut i = start;
|
let mut i = start;
|
||||||
if step == 0 {
|
if step == 0 {
|
||||||
fail!(~"range_step called with step == 0");
|
fail!(~"range_step called with step == 0");
|
||||||
|
@ -119,116 +119,116 @@ pub pure fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// Iterate over the range [`lo`..`hi`)
|
/// Iterate over the range [`lo`..`hi`)
|
||||||
pub pure fn range(lo: T, hi: T, it: &fn(T) -> bool) {
|
pub fn range(lo: T, hi: T, it: &fn(T) -> bool) {
|
||||||
range_step(lo, hi, 1 as T, it);
|
range_step(lo, hi, 1 as T, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// Iterate over the range [`hi`..`lo`)
|
/// Iterate over the range [`hi`..`lo`)
|
||||||
pub pure fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
|
pub fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
|
||||||
range_step(hi, lo, -1 as T, it);
|
range_step(hi, lo, -1 as T, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the bitwise complement
|
/// Computes the bitwise complement
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn compl(i: T) -> T {
|
pub fn compl(i: T) -> T {
|
||||||
-1 as T ^ i
|
-1 as T ^ i
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the absolute value
|
/// Computes the absolute value
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn abs(i: T) -> T {
|
pub fn abs(i: T) -> T {
|
||||||
if is_negative(i) { -i } else { i }
|
if is_negative(i) { -i } else { i }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Ord for T {
|
impl Ord for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &T) -> bool { return (*self) < (*other); }
|
fn lt(&self, other: &T) -> bool { return (*self) < (*other); }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &T) -> bool { return (*self) <= (*other); }
|
fn le(&self, other: &T) -> bool { return (*self) <= (*other); }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &T) -> bool { return (*self) >= (*other); }
|
fn ge(&self, other: &T) -> bool { return (*self) >= (*other); }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &T) -> bool { return (*self) > (*other); }
|
fn gt(&self, other: &T) -> bool { return (*self) > (*other); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Eq for T {
|
impl Eq for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
|
fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
|
fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Zero for T {
|
impl num::Zero for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn zero() -> T { 0 }
|
fn zero() -> T { 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::One for T {
|
impl num::One for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn one() -> T { 1 }
|
fn one() -> T { 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Add<T,T> for T {
|
impl ops::Add<T,T> for T {
|
||||||
pure fn add(&self, other: &T) -> T { *self + *other }
|
fn add(&self, other: &T) -> T { *self + *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Sub<T,T> for T {
|
impl ops::Sub<T,T> for T {
|
||||||
pure fn sub(&self, other: &T) -> T { *self - *other }
|
fn sub(&self, other: &T) -> T { *self - *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Mul<T,T> for T {
|
impl ops::Mul<T,T> for T {
|
||||||
pure fn mul(&self, other: &T) -> T { *self * *other }
|
fn mul(&self, other: &T) -> T { *self * *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Div<T,T> for T {
|
impl ops::Div<T,T> for T {
|
||||||
pure fn div(&self, other: &T) -> T { *self / *other }
|
fn div(&self, other: &T) -> T { *self / *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Modulo<T,T> for T {
|
impl ops::Modulo<T,T> for T {
|
||||||
pure fn modulo(&self, other: &T) -> T { *self % *other }
|
fn modulo(&self, other: &T) -> T { *self % *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Neg<T> for T {
|
impl ops::Neg<T> for T {
|
||||||
pure fn neg(&self) -> T { -*self }
|
fn neg(&self) -> T { -*self }
|
||||||
}
|
}
|
||||||
|
|
||||||
// String conversion functions and impl str -> num
|
// String conversion functions and impl str -> num
|
||||||
|
|
||||||
/// Parse a string as a number in base 10.
|
/// Parse a string as a number in base 10.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str(s: &str) -> Option<T> {
|
pub fn from_str(s: &str) -> Option<T> {
|
||||||
strconv::from_str_common(s, 10u, true, false, false,
|
strconv::from_str_common(s, 10u, true, false, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a string as a number in the given base.
|
/// Parse a string as a number in the given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
pub fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
||||||
strconv::from_str_common(s, radix, true, false, false,
|
strconv::from_str_common(s, radix, true, false, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a byte slice as a number in the given base.
|
/// Parse a byte slice as a number in the given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
|
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
|
||||||
strconv::from_str_bytes_common(buf, radix, true, false, false,
|
strconv::from_str_bytes_common(buf, radix, true, false, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for T {
|
impl FromStr for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str(s: &str) -> Option<T> {
|
fn from_str(s: &str) -> Option<T> {
|
||||||
from_str(s)
|
from_str(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStrRadix for T {
|
impl FromStrRadix for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
||||||
from_str_radix(s, radix)
|
from_str_radix(s, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ impl FromStrRadix for T {
|
||||||
|
|
||||||
/// Convert to a string as a byte slice in a given base.
|
/// Convert to a string as a byte slice in a given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
pub fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
||||||
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
|
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
|
||||||
strconv::SignNeg, strconv::DigAll);
|
strconv::SignNeg, strconv::DigAll);
|
||||||
f(buf)
|
f(buf)
|
||||||
|
@ -245,7 +245,7 @@ pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
||||||
|
|
||||||
/// Convert to a string in base 10.
|
/// Convert to a string in base 10.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str(num: T) -> ~str {
|
pub fn to_str(num: T) -> ~str {
|
||||||
let (buf, _) = strconv::to_str_common(&num, 10u, false,
|
let (buf, _) = strconv::to_str_common(&num, 10u, false,
|
||||||
strconv::SignNeg, strconv::DigAll);
|
strconv::SignNeg, strconv::DigAll);
|
||||||
buf
|
buf
|
||||||
|
@ -253,7 +253,7 @@ pub pure fn to_str(num: T) -> ~str {
|
||||||
|
|
||||||
/// Convert to a string in a given base.
|
/// Convert to a string in a given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
|
pub fn to_str_radix(num: T, radix: uint) -> ~str {
|
||||||
let (buf, _) = strconv::to_str_common(&num, radix, false,
|
let (buf, _) = strconv::to_str_common(&num, radix, false,
|
||||||
strconv::SignNeg, strconv::DigAll);
|
strconv::SignNeg, strconv::DigAll);
|
||||||
buf
|
buf
|
||||||
|
@ -261,14 +261,14 @@ pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
|
||||||
|
|
||||||
impl ToStr for T {
|
impl ToStr for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
to_str(*self)
|
to_str(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToStrRadix for T {
|
impl ToStrRadix for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str_radix(&self, radix: uint) -> ~str {
|
fn to_str_radix(&self, radix: uint) -> ~str {
|
||||||
to_str_radix(*self, radix)
|
to_str_radix(*self, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,23 +22,23 @@ impl NumCast for i16 {
|
||||||
* Cast `n` to a `i16`
|
* Cast `n` to a `i16`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> i16 { n.to_i16() }
|
fn from<N:NumCast>(n: N) -> i16 { n.to_i16() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -22,23 +22,23 @@ impl NumCast for i32 {
|
||||||
* Cast `n` to a `i32`
|
* Cast `n` to a `i32`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> i32 { n.to_i32() }
|
fn from<N:NumCast>(n: N) -> i32 { n.to_i32() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -22,23 +22,23 @@ impl NumCast for i64 {
|
||||||
* Cast `n` to a `i64`
|
* Cast `n` to a `i64`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> i64 { n.to_i64() }
|
fn from<N:NumCast>(n: N) -> i64 { n.to_i64() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -22,23 +22,23 @@ impl NumCast for i8 {
|
||||||
* Cast `n` to a `i8`
|
* Cast `n` to a `i8`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> i8 { n.to_i8() }
|
fn from<N:NumCast>(n: N) -> i8 { n.to_i8() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -19,7 +19,7 @@ mod inst {
|
||||||
pub const bits: uint = ::uint::bits;
|
pub const bits: uint = ::uint::bits;
|
||||||
|
|
||||||
/// Returns `base` raised to the power of `exponent`
|
/// Returns `base` raised to the power of `exponent`
|
||||||
pub pure fn pow(base: int, exponent: uint) -> int {
|
pub fn pow(base: int, exponent: uint) -> int {
|
||||||
if exponent == 0u {
|
if exponent == 0u {
|
||||||
//Not mathemtically true if ~[base == 0]
|
//Not mathemtically true if ~[base == 0]
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -63,23 +63,23 @@ impl NumCast for int {
|
||||||
* Cast `n` to a `int`
|
* Cast `n` to a `int`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> int { n.to_int() }
|
fn from<N:NumCast>(n: N) -> int { n.to_int() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self }
|
#[inline(always)] fn to_int(&self) -> int { *self }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -17,28 +17,28 @@ use kinds::Copy;
|
||||||
pub mod strconv;
|
pub mod strconv;
|
||||||
|
|
||||||
pub trait IntConvertible {
|
pub trait IntConvertible {
|
||||||
pure fn to_int(&self) -> int;
|
fn to_int(&self) -> int;
|
||||||
pure fn from_int(n: int) -> Self;
|
fn from_int(n: int) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Zero {
|
pub trait Zero {
|
||||||
pure fn zero() -> Self;
|
fn zero() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait One {
|
pub trait One {
|
||||||
pure fn one() -> Self;
|
fn one() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn abs<T:Ord + Zero + Neg<T>>(v: T) -> T {
|
pub fn abs<T:Ord + Zero + Neg<T>>(v: T) -> T {
|
||||||
if v < Zero::zero() { v.neg() } else { v }
|
if v < Zero::zero() { v.neg() } else { v }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Round {
|
pub trait Round {
|
||||||
pure fn round(&self, mode: RoundMode) -> Self;
|
fn round(&self, mode: RoundMode) -> Self;
|
||||||
|
|
||||||
pure fn floor(&self) -> Self;
|
fn floor(&self) -> Self;
|
||||||
pure fn ceil(&self) -> Self;
|
fn ceil(&self) -> Self;
|
||||||
pure fn fract(&self) -> Self;
|
fn fract(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RoundMode {
|
pub enum RoundMode {
|
||||||
|
@ -59,7 +59,7 @@ pub enum RoundMode {
|
||||||
* ~~~
|
* ~~~
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn cast<T:NumCast,U:NumCast>(n: T) -> U {
|
pub fn cast<T:NumCast,U:NumCast>(n: T) -> U {
|
||||||
NumCast::from(n)
|
NumCast::from(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,31 +67,31 @@ pub pure fn cast<T:NumCast,U:NumCast>(n: T) -> U {
|
||||||
* An interface for generic numeric type casts
|
* An interface for generic numeric type casts
|
||||||
*/
|
*/
|
||||||
pub trait NumCast {
|
pub trait NumCast {
|
||||||
pure fn from<T:NumCast>(n: T) -> Self;
|
fn from<T:NumCast>(n: T) -> Self;
|
||||||
|
|
||||||
pure fn to_u8(&self) -> u8;
|
fn to_u8(&self) -> u8;
|
||||||
pure fn to_u16(&self) -> u16;
|
fn to_u16(&self) -> u16;
|
||||||
pure fn to_u32(&self) -> u32;
|
fn to_u32(&self) -> u32;
|
||||||
pure fn to_u64(&self) -> u64;
|
fn to_u64(&self) -> u64;
|
||||||
pure fn to_uint(&self) -> uint;
|
fn to_uint(&self) -> uint;
|
||||||
|
|
||||||
pure fn to_i8(&self) -> i8;
|
fn to_i8(&self) -> i8;
|
||||||
pure fn to_i16(&self) -> i16;
|
fn to_i16(&self) -> i16;
|
||||||
pure fn to_i32(&self) -> i32;
|
fn to_i32(&self) -> i32;
|
||||||
pure fn to_i64(&self) -> i64;
|
fn to_i64(&self) -> i64;
|
||||||
pure fn to_int(&self) -> int;
|
fn to_int(&self) -> int;
|
||||||
|
|
||||||
pure fn to_f32(&self) -> f32;
|
fn to_f32(&self) -> f32;
|
||||||
pure fn to_f64(&self) -> f64;
|
fn to_f64(&self) -> f64;
|
||||||
pure fn to_float(&self) -> float;
|
fn to_float(&self) -> float;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToStrRadix {
|
pub trait ToStrRadix {
|
||||||
pub pure fn to_str_radix(&self, radix: uint) -> ~str;
|
pub fn to_str_radix(&self, radix: uint) -> ~str;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromStrRadix {
|
pub trait FromStrRadix {
|
||||||
pub pure fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
|
pub fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic math functions:
|
// Generic math functions:
|
||||||
|
@ -109,7 +109,7 @@ pub trait FromStrRadix {
|
||||||
* - If code written to use this function doesn't care about it, it's
|
* - If code written to use this function doesn't care about it, it's
|
||||||
* probably assuming that `x^0` always equals `1`.
|
* probably assuming that `x^0` always equals `1`.
|
||||||
*/
|
*/
|
||||||
pub pure fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
|
pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
|
||||||
radix: uint, pow: uint) -> T {
|
radix: uint, pow: uint) -> T {
|
||||||
let _0: T = Zero::zero();
|
let _0: T = Zero::zero();
|
||||||
let _1: T = One::one();
|
let _1: T = One::one();
|
||||||
|
|
|
@ -37,12 +37,12 @@ pub enum SignFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_NaN<T:Eq>(num: &T) -> bool {
|
fn is_NaN<T:Eq>(num: &T) -> bool {
|
||||||
*num != *num
|
*num != *num
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_inf<T:Eq+NumStrConv>(num: &T) -> bool {
|
fn is_inf<T:Eq+NumStrConv>(num: &T) -> bool {
|
||||||
match NumStrConv::inf() {
|
match NumStrConv::inf() {
|
||||||
None => false,
|
None => false,
|
||||||
Some(n) => *num == n
|
Some(n) => *num == n
|
||||||
|
@ -50,7 +50,7 @@ pure fn is_inf<T:Eq+NumStrConv>(num: &T) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_neg_inf<T:Eq+NumStrConv>(num: &T) -> bool {
|
fn is_neg_inf<T:Eq+NumStrConv>(num: &T) -> bool {
|
||||||
match NumStrConv::neg_inf() {
|
match NumStrConv::neg_inf() {
|
||||||
None => false,
|
None => false,
|
||||||
Some(n) => *num == n
|
Some(n) => *num == n
|
||||||
|
@ -58,7 +58,7 @@ pure fn is_neg_inf<T:Eq+NumStrConv>(num: &T) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool {
|
fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool {
|
||||||
let _0: T = Zero::zero();
|
let _0: T = Zero::zero();
|
||||||
let _1: T = One::one();
|
let _1: T = One::one();
|
||||||
|
|
||||||
|
@ -66,35 +66,35 @@ pure fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait NumStrConv {
|
pub trait NumStrConv {
|
||||||
pure fn NaN() -> Option<Self>;
|
fn NaN() -> Option<Self>;
|
||||||
pure fn inf() -> Option<Self>;
|
fn inf() -> Option<Self>;
|
||||||
pure fn neg_inf() -> Option<Self>;
|
fn neg_inf() -> Option<Self>;
|
||||||
pure fn neg_zero() -> Option<Self>;
|
fn neg_zero() -> Option<Self>;
|
||||||
|
|
||||||
pure fn round_to_zero(&self) -> Self;
|
fn round_to_zero(&self) -> Self;
|
||||||
pure fn fractional_part(&self) -> Self;
|
fn fractional_part(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_NumStrConv_Floating (($t:ty) => (
|
macro_rules! impl_NumStrConv_Floating (($t:ty) => (
|
||||||
impl NumStrConv for $t {
|
impl NumStrConv for $t {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn NaN() -> Option<$t> { Some( 0.0 / 0.0) }
|
fn NaN() -> Option<$t> { Some( 0.0 / 0.0) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn inf() -> Option<$t> { Some( 1.0 / 0.0) }
|
fn inf() -> Option<$t> { Some( 1.0 / 0.0) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn neg_inf() -> Option<$t> { Some(-1.0 / 0.0) }
|
fn neg_inf() -> Option<$t> { Some(-1.0 / 0.0) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn neg_zero() -> Option<$t> { Some(-0.0 ) }
|
fn neg_zero() -> Option<$t> { Some(-0.0 ) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn round_to_zero(&self) -> $t {
|
fn round_to_zero(&self) -> $t {
|
||||||
( if *self < 0.0 { f64::ceil(*self as f64) }
|
( if *self < 0.0 { f64::ceil(*self as f64) }
|
||||||
else { f64::floor(*self as f64) }
|
else { f64::floor(*self as f64) }
|
||||||
) as $t
|
) as $t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn fractional_part(&self) -> $t {
|
fn fractional_part(&self) -> $t {
|
||||||
*self - self.round_to_zero()
|
*self - self.round_to_zero()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,13 +102,13 @@ macro_rules! impl_NumStrConv_Floating (($t:ty) => (
|
||||||
|
|
||||||
macro_rules! impl_NumStrConv_Integer (($t:ty) => (
|
macro_rules! impl_NumStrConv_Integer (($t:ty) => (
|
||||||
impl NumStrConv for $t {
|
impl NumStrConv for $t {
|
||||||
#[inline(always)] pure fn NaN() -> Option<$t> { None }
|
#[inline(always)] fn NaN() -> Option<$t> { None }
|
||||||
#[inline(always)] pure fn inf() -> Option<$t> { None }
|
#[inline(always)] fn inf() -> Option<$t> { None }
|
||||||
#[inline(always)] pure fn neg_inf() -> Option<$t> { None }
|
#[inline(always)] fn neg_inf() -> Option<$t> { None }
|
||||||
#[inline(always)] pure fn neg_zero() -> Option<$t> { None }
|
#[inline(always)] fn neg_zero() -> Option<$t> { None }
|
||||||
|
|
||||||
#[inline(always)] pure fn round_to_zero(&self) -> $t { *self }
|
#[inline(always)] fn round_to_zero(&self) -> $t { *self }
|
||||||
#[inline(always)] pure fn fractional_part(&self) -> $t { 0 }
|
#[inline(always)] fn fractional_part(&self) -> $t { 0 }
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ impl_NumStrConv_Integer!(u64)
|
||||||
* # Failure
|
* # Failure
|
||||||
* - Fails if `radix` < 2 or `radix` > 36.
|
* - Fails if `radix` < 2 or `radix` > 36.
|
||||||
*/
|
*/
|
||||||
pub pure fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
|
pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
|
||||||
Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
|
Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
|
||||||
num: &T, radix: uint, negative_zero: bool,
|
num: &T, radix: uint, negative_zero: bool,
|
||||||
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
|
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
|
||||||
|
@ -383,7 +383,7 @@ pub pure fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
|
||||||
* `to_str_bytes_common()`, for details see there.
|
* `to_str_bytes_common()`, for details see there.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
|
pub fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
|
||||||
Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
|
Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
|
||||||
num: &T, radix: uint, negative_zero: bool,
|
num: &T, radix: uint, negative_zero: bool,
|
||||||
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
|
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
|
||||||
|
@ -439,7 +439,7 @@ priv const DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
|
||||||
* - Could accept option to allow ignoring underscores, allowing for numbers
|
* - Could accept option to allow ignoring underscores, allowing for numbers
|
||||||
* formated like `FF_AE_FF_FF`.
|
* formated like `FF_AE_FF_FF`.
|
||||||
*/
|
*/
|
||||||
pub pure fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
|
pub fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
|
||||||
Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+
|
Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+
|
||||||
NumStrConv>(
|
NumStrConv>(
|
||||||
buf: &[u8], radix: uint, negative: bool, fractional: bool,
|
buf: &[u8], radix: uint, negative: bool, fractional: bool,
|
||||||
|
@ -628,7 +628,7 @@ pub pure fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
|
||||||
* `from_str_bytes_common()`, for details see there.
|
* `from_str_bytes_common()`, for details see there.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+Mul<T,T>+
|
pub fn from_str_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+Mul<T,T>+
|
||||||
Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv>(
|
Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv>(
|
||||||
buf: &str, radix: uint, negative: bool, fractional: bool,
|
buf: &str, radix: uint, negative: bool, fractional: bool,
|
||||||
special: bool, exponent: ExponentFormat, empty_zero: bool
|
special: bool, exponent: ExponentFormat, empty_zero: bool
|
||||||
|
|
|
@ -30,44 +30,44 @@ pub const min_value: T = 0 as T;
|
||||||
pub const max_value: T = 0 as T - 1 as T;
|
pub const max_value: T = 0 as T - 1 as T;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn add(x: T, y: T) -> T { x + y }
|
pub fn add(x: T, y: T) -> T { x + y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn sub(x: T, y: T) -> T { x - y }
|
pub fn sub(x: T, y: T) -> T { x - y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mul(x: T, y: T) -> T { x * y }
|
pub fn mul(x: T, y: T) -> T { x * y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn div(x: T, y: T) -> T { x / y }
|
pub fn div(x: T, y: T) -> T { x / y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn rem(x: T, y: T) -> T { x % y }
|
pub fn rem(x: T, y: T) -> T { x % y }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn lt(x: T, y: T) -> bool { x < y }
|
pub fn lt(x: T, y: T) -> bool { x < y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn le(x: T, y: T) -> bool { x <= y }
|
pub fn le(x: T, y: T) -> bool { x <= y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn eq(x: T, y: T) -> bool { x == y }
|
pub fn eq(x: T, y: T) -> bool { x == y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ne(x: T, y: T) -> bool { x != y }
|
pub fn ne(x: T, y: T) -> bool { x != y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ge(x: T, y: T) -> bool { x >= y }
|
pub fn ge(x: T, y: T) -> bool { x >= y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn gt(x: T, y: T) -> bool { x > y }
|
pub fn gt(x: T, y: T) -> bool { x > y }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_positive(x: T) -> bool { x > 0 as T }
|
pub fn is_positive(x: T) -> bool { x > 0 as T }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_negative(x: T) -> bool { x < 0 as T }
|
pub fn is_negative(x: T) -> bool { x < 0 as T }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
|
pub fn is_nonpositive(x: T) -> bool { x <= 0 as T }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
pub fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/**
|
/**
|
||||||
* Iterate over the range [`start`,`start`+`step`..`stop`)
|
* Iterate over the range [`start`,`start`+`step`..`stop`)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
pub pure fn range_step(start: T,
|
pub fn range_step(start: T,
|
||||||
stop: T,
|
stop: T,
|
||||||
step: T_SIGNED,
|
step: T_SIGNED,
|
||||||
it: &fn(T) -> bool) {
|
it: &fn(T) -> bool) {
|
||||||
|
@ -91,110 +91,110 @@ pub pure fn range_step(start: T,
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// Iterate over the range [`lo`..`hi`)
|
/// Iterate over the range [`lo`..`hi`)
|
||||||
pub pure fn range(lo: T, hi: T, it: &fn(T) -> bool) {
|
pub fn range(lo: T, hi: T, it: &fn(T) -> bool) {
|
||||||
range_step(lo, hi, 1 as T_SIGNED, it);
|
range_step(lo, hi, 1 as T_SIGNED, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// Iterate over the range [`hi`..`lo`)
|
/// Iterate over the range [`hi`..`lo`)
|
||||||
pub pure fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
|
pub fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
|
||||||
range_step(hi, lo, -1 as T_SIGNED, it);
|
range_step(hi, lo, -1 as T_SIGNED, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the bitwise complement
|
/// Computes the bitwise complement
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn compl(i: T) -> T {
|
pub fn compl(i: T) -> T {
|
||||||
max_value ^ i
|
max_value ^ i
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Ord for T {
|
impl Ord for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &T) -> bool { (*self) < (*other) }
|
fn lt(&self, other: &T) -> bool { (*self) < (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &T) -> bool { (*self) <= (*other) }
|
fn le(&self, other: &T) -> bool { (*self) <= (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &T) -> bool { (*self) >= (*other) }
|
fn ge(&self, other: &T) -> bool { (*self) >= (*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &T) -> bool { (*self) > (*other) }
|
fn gt(&self, other: &T) -> bool { (*self) > (*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl Eq for T {
|
impl Eq for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
|
fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
|
fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Zero for T {
|
impl num::Zero for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn zero() -> T { 0 }
|
fn zero() -> T { 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::One for T {
|
impl num::One for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn one() -> T { 1 }
|
fn one() -> T { 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Add<T,T> for T {
|
impl ops::Add<T,T> for T {
|
||||||
pure fn add(&self, other: &T) -> T { *self + *other }
|
fn add(&self, other: &T) -> T { *self + *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Sub<T,T> for T {
|
impl ops::Sub<T,T> for T {
|
||||||
pure fn sub(&self, other: &T) -> T { *self - *other }
|
fn sub(&self, other: &T) -> T { *self - *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Mul<T,T> for T {
|
impl ops::Mul<T,T> for T {
|
||||||
pure fn mul(&self, other: &T) -> T { *self * *other }
|
fn mul(&self, other: &T) -> T { *self * *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Div<T,T> for T {
|
impl ops::Div<T,T> for T {
|
||||||
pure fn div(&self, other: &T) -> T { *self / *other }
|
fn div(&self, other: &T) -> T { *self / *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Modulo<T,T> for T {
|
impl ops::Modulo<T,T> for T {
|
||||||
pure fn modulo(&self, other: &T) -> T { *self % *other }
|
fn modulo(&self, other: &T) -> T { *self % *other }
|
||||||
}
|
}
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl ops::Neg<T> for T {
|
impl ops::Neg<T> for T {
|
||||||
pure fn neg(&self) -> T { -*self }
|
fn neg(&self) -> T { -*self }
|
||||||
}
|
}
|
||||||
|
|
||||||
// String conversion functions and impl str -> num
|
// String conversion functions and impl str -> num
|
||||||
|
|
||||||
/// Parse a string as a number in base 10.
|
/// Parse a string as a number in base 10.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str(s: &str) -> Option<T> {
|
pub fn from_str(s: &str) -> Option<T> {
|
||||||
strconv::from_str_common(s, 10u, false, false, false,
|
strconv::from_str_common(s, 10u, false, false, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a string as a number in the given base.
|
/// Parse a string as a number in the given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
pub fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
||||||
strconv::from_str_common(s, radix, false, false, false,
|
strconv::from_str_common(s, radix, false, false, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a byte slice as a number in the given base.
|
/// Parse a byte slice as a number in the given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
|
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
|
||||||
strconv::from_str_bytes_common(buf, radix, false, false, false,
|
strconv::from_str_bytes_common(buf, radix, false, false, false,
|
||||||
strconv::ExpNone, false)
|
strconv::ExpNone, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for T {
|
impl FromStr for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str(s: &str) -> Option<T> {
|
fn from_str(s: &str) -> Option<T> {
|
||||||
from_str(s)
|
from_str(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStrRadix for T {
|
impl FromStrRadix for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
fn from_str_radix(s: &str, radix: uint) -> Option<T> {
|
||||||
from_str_radix(s, radix)
|
from_str_radix(s, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ impl FromStrRadix for T {
|
||||||
|
|
||||||
/// Convert to a string as a byte slice in a given base.
|
/// Convert to a string as a byte slice in a given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
pub fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
||||||
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
|
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
|
||||||
strconv::SignNeg, strconv::DigAll);
|
strconv::SignNeg, strconv::DigAll);
|
||||||
f(buf)
|
f(buf)
|
||||||
|
@ -211,7 +211,7 @@ pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
||||||
|
|
||||||
/// Convert to a string in base 10.
|
/// Convert to a string in base 10.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str(num: T) -> ~str {
|
pub fn to_str(num: T) -> ~str {
|
||||||
let (buf, _) = strconv::to_str_common(&num, 10u, false,
|
let (buf, _) = strconv::to_str_common(&num, 10u, false,
|
||||||
strconv::SignNeg, strconv::DigAll);
|
strconv::SignNeg, strconv::DigAll);
|
||||||
buf
|
buf
|
||||||
|
@ -219,7 +219,7 @@ pub pure fn to_str(num: T) -> ~str {
|
||||||
|
|
||||||
/// Convert to a string in a given base.
|
/// Convert to a string in a given base.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
|
pub fn to_str_radix(num: T, radix: uint) -> ~str {
|
||||||
let (buf, _) = strconv::to_str_common(&num, radix, false,
|
let (buf, _) = strconv::to_str_common(&num, radix, false,
|
||||||
strconv::SignNeg, strconv::DigAll);
|
strconv::SignNeg, strconv::DigAll);
|
||||||
buf
|
buf
|
||||||
|
@ -227,14 +227,14 @@ pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
|
||||||
|
|
||||||
impl ToStr for T {
|
impl ToStr for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
to_str(*self)
|
to_str(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToStrRadix for T {
|
impl ToStrRadix for T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str_radix(&self, radix: uint) -> ~str {
|
fn to_str_radix(&self, radix: uint) -> ~str {
|
||||||
to_str_radix(*self, radix)
|
to_str_radix(*self, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,23 +24,23 @@ impl NumCast for u16 {
|
||||||
* Cast `n` to a `u16`
|
* Cast `n` to a `u16`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> u16 { n.to_u16() }
|
fn from<N:NumCast>(n: N) -> u16 { n.to_u16() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -24,23 +24,23 @@ impl NumCast for u32 {
|
||||||
* Cast `n` to a `u32`
|
* Cast `n` to a `u32`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> u32 { n.to_u32() }
|
fn from<N:NumCast>(n: N) -> u32 { n.to_u32() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -24,23 +24,23 @@ impl NumCast for u64 {
|
||||||
* Cast `n` to a `u64`
|
* Cast `n` to a `u64`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> u64 { n.to_u64() }
|
fn from<N:NumCast>(n: N) -> u64 { n.to_u64() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod inst {
|
||||||
// Type-specific functions here. These must be reexported by the
|
// Type-specific functions here. These must be reexported by the
|
||||||
// parent module so that they appear in core::u8 and not core::u8::u8;
|
// parent module so that they appear in core::u8 and not core::u8::u8;
|
||||||
|
|
||||||
pub pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }
|
pub fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NumCast for u8 {
|
impl NumCast for u8 {
|
||||||
|
@ -31,23 +31,23 @@ impl NumCast for u8 {
|
||||||
* Cast `n` to a `u8`
|
* Cast `n` to a `u8`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> u8 { n.to_u8() }
|
fn from<N:NumCast>(n: N) -> u8 { n.to_u8() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
|
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub mod inst {
|
||||||
*
|
*
|
||||||
* The smallest integer `q` such that `x/y <= q`.
|
* The smallest integer `q` such that `x/y <= q`.
|
||||||
*/
|
*/
|
||||||
pub pure fn div_ceil(x: uint, y: uint) -> uint {
|
pub fn div_ceil(x: uint, y: uint) -> uint {
|
||||||
let div = x / y;
|
let div = x / y;
|
||||||
if x % y == 0u { div }
|
if x % y == 0u { div }
|
||||||
else { div + 1u }
|
else { div + 1u }
|
||||||
|
@ -63,7 +63,7 @@ pub mod inst {
|
||||||
*
|
*
|
||||||
* The integer `q` closest to `x/y`.
|
* The integer `q` closest to `x/y`.
|
||||||
*/
|
*/
|
||||||
pub pure fn div_round(x: uint, y: uint) -> uint {
|
pub fn div_round(x: uint, y: uint) -> uint {
|
||||||
let div = x / y;
|
let div = x / y;
|
||||||
if x % y * 2u < y { div }
|
if x % y * 2u < y { div }
|
||||||
else { div + 1u }
|
else { div + 1u }
|
||||||
|
@ -84,7 +84,7 @@ pub mod inst {
|
||||||
* The smallest integer `q` such that `x/y <= q`. This
|
* The smallest integer `q` such that `x/y <= q`. This
|
||||||
* is either `x/y` or `x/y + 1`.
|
* is either `x/y` or `x/y + 1`.
|
||||||
*/
|
*/
|
||||||
pub pure fn div_floor(x: uint, y: uint) -> uint { return x / y; }
|
pub fn div_floor(x: uint, y: uint) -> uint { return x / y; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over the range [`lo`..`hi`), or stop when requested
|
* Iterate over the range [`lo`..`hi`), or stop when requested
|
||||||
|
@ -101,7 +101,7 @@ pub mod inst {
|
||||||
* `true` If execution proceeded correctly, `false` if it was interrupted,
|
* `true` If execution proceeded correctly, `false` if it was interrupted,
|
||||||
* that is if `it` returned `false` at any point.
|
* that is if `it` returned `false` at any point.
|
||||||
*/
|
*/
|
||||||
pub pure fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
|
pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
|
||||||
let mut i = lo;
|
let mut i = lo;
|
||||||
while i < hi {
|
while i < hi {
|
||||||
if (!it(i)) { return false; }
|
if (!it(i)) { return false; }
|
||||||
|
@ -122,7 +122,7 @@ pub mod inst {
|
||||||
* use with integer literals of inferred integer-type as
|
* use with integer literals of inferred integer-type as
|
||||||
* the self-value (eg. `for 100.times { ... }`).
|
* the self-value (eg. `for 100.times { ... }`).
|
||||||
*/
|
*/
|
||||||
pure fn times(&self, it: &fn() -> bool) {
|
fn times(&self, it: &fn() -> bool) {
|
||||||
let mut i = *self;
|
let mut i = *self;
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
if !it() { break }
|
if !it() { break }
|
||||||
|
@ -133,7 +133,7 @@ pub mod inst {
|
||||||
|
|
||||||
/// Returns the smallest power of 2 greater than or equal to `n`
|
/// Returns the smallest power of 2 greater than or equal to `n`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn next_power_of_two(n: uint) -> uint {
|
pub fn next_power_of_two(n: uint) -> uint {
|
||||||
let halfbits: uint = sys::size_of::<uint>() * 4u;
|
let halfbits: uint = sys::size_of::<uint>() * 4u;
|
||||||
let mut tmp: uint = n - 1u;
|
let mut tmp: uint = n - 1u;
|
||||||
let mut shift: uint = 1u;
|
let mut shift: uint = 1u;
|
||||||
|
@ -215,23 +215,23 @@ impl NumCast for uint {
|
||||||
* Cast `n` to a `uint`
|
* Cast `n` to a `uint`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn from<N:NumCast>(n: N) -> uint { n.to_uint() }
|
fn from<N:NumCast>(n: N) -> uint { n.to_uint() }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
|
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
|
||||||
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
|
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
|
||||||
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
|
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
|
||||||
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
|
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
|
||||||
#[inline(always)] pure fn to_uint(&self) -> uint { *self }
|
#[inline(always)] fn to_uint(&self) -> uint { *self }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
|
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
|
||||||
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
|
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
|
||||||
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
|
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
|
||||||
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
|
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
|
||||||
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
|
#[inline(always)] fn to_int(&self) -> int { *self as int }
|
||||||
|
|
||||||
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
|
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
|
||||||
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
|
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
|
||||||
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
|
#[inline(always)] fn to_float(&self) -> float { *self as float }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -17,65 +17,65 @@ pub trait Drop {
|
||||||
|
|
||||||
#[lang="add"]
|
#[lang="add"]
|
||||||
pub trait Add<RHS,Result> {
|
pub trait Add<RHS,Result> {
|
||||||
pure fn add(&self, rhs: &RHS) -> Result;
|
fn add(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="sub"]
|
#[lang="sub"]
|
||||||
pub trait Sub<RHS,Result> {
|
pub trait Sub<RHS,Result> {
|
||||||
pure fn sub(&self, rhs: &RHS) -> Result;
|
fn sub(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="mul"]
|
#[lang="mul"]
|
||||||
pub trait Mul<RHS,Result> {
|
pub trait Mul<RHS,Result> {
|
||||||
pure fn mul(&self, rhs: &RHS) -> Result;
|
fn mul(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="div"]
|
#[lang="div"]
|
||||||
pub trait Div<RHS,Result> {
|
pub trait Div<RHS,Result> {
|
||||||
pure fn div(&self, rhs: &RHS) -> Result;
|
fn div(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="modulo"]
|
#[lang="modulo"]
|
||||||
pub trait Modulo<RHS,Result> {
|
pub trait Modulo<RHS,Result> {
|
||||||
pure fn modulo(&self, rhs: &RHS) -> Result;
|
fn modulo(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="neg"]
|
#[lang="neg"]
|
||||||
pub trait Neg<Result> {
|
pub trait Neg<Result> {
|
||||||
pure fn neg(&self) -> Result;
|
fn neg(&self) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="not"]
|
#[lang="not"]
|
||||||
pub trait Not<Result> {
|
pub trait Not<Result> {
|
||||||
pure fn not(&self) -> Result;
|
fn not(&self) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="bitand"]
|
#[lang="bitand"]
|
||||||
pub trait BitAnd<RHS,Result> {
|
pub trait BitAnd<RHS,Result> {
|
||||||
pure fn bitand(&self, rhs: &RHS) -> Result;
|
fn bitand(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="bitor"]
|
#[lang="bitor"]
|
||||||
pub trait BitOr<RHS,Result> {
|
pub trait BitOr<RHS,Result> {
|
||||||
pure fn bitor(&self, rhs: &RHS) -> Result;
|
fn bitor(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="bitxor"]
|
#[lang="bitxor"]
|
||||||
pub trait BitXor<RHS,Result> {
|
pub trait BitXor<RHS,Result> {
|
||||||
pure fn bitxor(&self, rhs: &RHS) -> Result;
|
fn bitxor(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="shl"]
|
#[lang="shl"]
|
||||||
pub trait Shl<RHS,Result> {
|
pub trait Shl<RHS,Result> {
|
||||||
pure fn shl(&self, rhs: &RHS) -> Result;
|
fn shl(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="shr"]
|
#[lang="shr"]
|
||||||
pub trait Shr<RHS,Result> {
|
pub trait Shr<RHS,Result> {
|
||||||
pure fn shr(&self, rhs: &RHS) -> Result;
|
fn shr(&self, rhs: &RHS) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang="index"]
|
#[lang="index"]
|
||||||
pub trait Index<Index,Result> {
|
pub trait Index<Index,Result> {
|
||||||
pure fn index(&self, index: Index) -> Result;
|
fn index(&self, index: Index) -> Result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub enum Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Ord> Ord for Option<T> {
|
impl<T:Ord> Ord for Option<T> {
|
||||||
pure fn lt(&self, other: &Option<T>) -> bool {
|
fn lt(&self, other: &Option<T>) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(&None, &None) => false,
|
(&None, &None) => false,
|
||||||
(&None, &Some(_)) => true,
|
(&None, &Some(_)) => true,
|
||||||
|
@ -68,7 +68,7 @@ impl<T:Ord> Ord for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn le(&self, other: &Option<T>) -> bool {
|
fn le(&self, other: &Option<T>) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(&None, &None) => true,
|
(&None, &None) => true,
|
||||||
(&None, &Some(_)) => true,
|
(&None, &Some(_)) => true,
|
||||||
|
@ -77,18 +77,18 @@ impl<T:Ord> Ord for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn ge(&self, other: &Option<T>) -> bool {
|
fn ge(&self, other: &Option<T>) -> bool {
|
||||||
! (self < other)
|
! (self < other)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn gt(&self, other: &Option<T>) -> bool {
|
fn gt(&self, other: &Option<T>) -> bool {
|
||||||
! (self <= other)
|
! (self <= other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
|
impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn add(&self, other: &Option<T>) -> Option<T> {
|
fn add(&self, other: &Option<T>) -> Option<T> {
|
||||||
match (*self, *other) {
|
match (*self, *other) {
|
||||||
(None, None) => None,
|
(None, None) => None,
|
||||||
(_, None) => *self,
|
(_, None) => *self,
|
||||||
|
@ -99,7 +99,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get<T:Copy>(opt: Option<T>) -> T {
|
pub fn get<T:Copy>(opt: Option<T>) -> T {
|
||||||
/*!
|
/*!
|
||||||
Gets the value out of an option
|
Gets the value out of an option
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ pub pure fn get<T:Copy>(opt: Option<T>) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
|
pub fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
|
||||||
/*!
|
/*!
|
||||||
Gets an immutable reference to the value inside an option.
|
Gets an immutable reference to the value inside an option.
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ pub pure fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
|
pub fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
|
||||||
/*!
|
/*!
|
||||||
Gets a mutable reference to the value inside an option.
|
Gets a mutable reference to the value inside an option.
|
||||||
|
|
||||||
|
@ -165,14 +165,14 @@ pub pure fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
|
pub fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
|
||||||
//! Maps a `some` value by reference from one type to another
|
//! Maps a `some` value by reference from one type to another
|
||||||
|
|
||||||
match *opt { Some(ref x) => Some(f(x)), None => None }
|
match *opt { Some(ref x) => Some(f(x)), None => None }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn map_consume<T, U>(opt: Option<T>,
|
pub fn map_consume<T, U>(opt: Option<T>,
|
||||||
f: &fn(v: T) -> U) -> Option<U> {
|
f: &fn(v: T) -> U) -> Option<U> {
|
||||||
/*!
|
/*!
|
||||||
* As `map`, but consumes the option and gives `f` ownership to avoid
|
* As `map`, but consumes the option and gives `f` ownership to avoid
|
||||||
|
@ -182,7 +182,7 @@ pub pure fn map_consume<T, U>(opt: Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn chain<T, U>(opt: Option<T>,
|
pub fn chain<T, U>(opt: Option<T>,
|
||||||
f: &fn(t: T) -> Option<U>) -> Option<U> {
|
f: &fn(t: T) -> Option<U>) -> Option<U> {
|
||||||
/*!
|
/*!
|
||||||
* Update an optional value by optionally running its content through a
|
* Update an optional value by optionally running its content through a
|
||||||
|
@ -196,7 +196,7 @@ pub pure fn chain<T, U>(opt: Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn chain_ref<T, U>(opt: &Option<T>,
|
pub fn chain_ref<T, U>(opt: &Option<T>,
|
||||||
f: &fn(x: &T) -> Option<U>) -> Option<U> {
|
f: &fn(x: &T) -> Option<U>) -> Option<U> {
|
||||||
/*!
|
/*!
|
||||||
* Update an optional value by optionally running its content by reference
|
* Update an optional value by optionally running its content by reference
|
||||||
|
@ -207,7 +207,7 @@ pub pure fn chain_ref<T, U>(opt: &Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
|
pub fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
|
||||||
/*!
|
/*!
|
||||||
* Returns the leftmost Some() value, or None if both are None.
|
* Returns the leftmost Some() value, or None if both are None.
|
||||||
*/
|
*/
|
||||||
|
@ -218,7 +218,7 @@ pub pure fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
|
pub fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
|
||||||
//! Applies a function zero or more times until the result is none.
|
//! Applies a function zero or more times until the result is none.
|
||||||
|
|
||||||
let mut opt = x;
|
let mut opt = x;
|
||||||
|
@ -228,35 +228,35 @@ pub pure fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_none<T>(opt: &const Option<T>) -> bool {
|
pub fn is_none<T>(opt: &const Option<T>) -> bool {
|
||||||
//! Returns true if the option equals `none`
|
//! Returns true if the option equals `none`
|
||||||
|
|
||||||
match *opt { None => true, Some(_) => false }
|
match *opt { None => true, Some(_) => false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_some<T>(opt: &const Option<T>) -> bool {
|
pub fn is_some<T>(opt: &const Option<T>) -> bool {
|
||||||
//! Returns true if the option contains some value
|
//! Returns true if the option contains some value
|
||||||
|
|
||||||
!is_none(opt)
|
!is_none(opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_or_zero<T:Copy + Zero>(opt: Option<T>) -> T {
|
pub fn get_or_zero<T:Copy + Zero>(opt: Option<T>) -> T {
|
||||||
//! Returns the contained value or zero (for this type)
|
//! Returns the contained value or zero (for this type)
|
||||||
|
|
||||||
match opt { Some(copy x) => x, None => Zero::zero() }
|
match opt { Some(copy x) => x, None => Zero::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
|
pub fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
|
||||||
//! Returns the contained value or a default
|
//! Returns the contained value or a default
|
||||||
|
|
||||||
match opt { Some(copy x) => x, None => def }
|
match opt { Some(copy x) => x, None => def }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn map_default<T, U>(opt: &'r Option<T>, def: U,
|
pub fn map_default<T, U>(opt: &'r Option<T>, def: U,
|
||||||
f: &fn(&'r T) -> U) -> U {
|
f: &fn(&'r T) -> U) -> U {
|
||||||
//! Applies a function to the contained value or returns a default
|
//! Applies a function to the contained value or returns a default
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ pub pure fn map_default<T, U>(opt: &'r Option<T>, def: U,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap<T>(opt: Option<T>) -> T {
|
pub fn unwrap<T>(opt: Option<T>) -> T {
|
||||||
/*!
|
/*!
|
||||||
Moves a value out of an option type and returns it.
|
Moves a value out of an option type and returns it.
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
pub fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
||||||
//! As unwrap, but with a specified failure message.
|
//! As unwrap, but with a specified failure message.
|
||||||
match opt {
|
match opt {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
|
@ -313,12 +313,12 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
||||||
impl<T> BaseIter<T> for Option<T> {
|
impl<T> BaseIter<T> for Option<T> {
|
||||||
/// Performs an operation on the contained value by reference
|
/// Performs an operation on the contained value by reference
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each(&self, f: &fn(x: &'self T) -> bool) {
|
fn each(&self, f: &fn(x: &'self T) -> bool) {
|
||||||
match *self { None => (), Some(ref t) => { f(t); } }
|
match *self { None => (), Some(ref t) => { f(t); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn size_hint(&self) -> Option<uint> {
|
fn size_hint(&self) -> Option<uint> {
|
||||||
if self.is_some() { Some(1) } else { Some(0) }
|
if self.is_some() { Some(1) } else { Some(0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,42 +333,42 @@ impl<T> MutableIter<T> for Option<T> {
|
||||||
pub impl<T> Option<T> {
|
pub impl<T> Option<T> {
|
||||||
/// Returns true if the option equals `none`
|
/// Returns true if the option equals `none`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_none(&const self) -> bool { is_none(self) }
|
fn is_none(&const self) -> bool { is_none(self) }
|
||||||
|
|
||||||
/// Returns true if the option contains some value
|
/// Returns true if the option contains some value
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_some(&const self) -> bool { is_some(self) }
|
fn is_some(&const self) -> bool { is_some(self) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an optional value by optionally running its content by reference
|
* Update an optional value by optionally running its content by reference
|
||||||
* through a function that returns an option.
|
* through a function that returns an option.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> {
|
fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> {
|
||||||
chain_ref(self, f)
|
chain_ref(self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maps a `some` value from one type to another by reference
|
/// Maps a `some` value from one type to another by reference
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) }
|
fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) }
|
||||||
|
|
||||||
/// As `map`, but consumes the option and gives `f` ownership to avoid
|
/// As `map`, but consumes the option and gives `f` ownership to avoid
|
||||||
/// copying.
|
/// copying.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
|
fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
|
||||||
map_consume(self, f)
|
map_consume(self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a function to the contained value or returns a default
|
/// Applies a function to the contained value or returns a default
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
|
fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
|
||||||
map_default(self, def, f)
|
map_default(self, def, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// As `map_default`, but consumes the option and gives `f`
|
/// As `map_default`, but consumes the option and gives `f`
|
||||||
/// ownership to avoid copying.
|
/// ownership to avoid copying.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
|
fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
|
||||||
match self { None => def, Some(v) => f(v) }
|
match self { None => def, Some(v) => f(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ pub impl<T> Option<T> {
|
||||||
case explicitly.
|
case explicitly.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_ref(&self) -> &'self T { get_ref(self) }
|
fn get_ref(&self) -> &'self T { get_ref(self) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets a mutable reference to the value inside an option.
|
Gets a mutable reference to the value inside an option.
|
||||||
|
@ -420,7 +420,7 @@ pub impl<T> Option<T> {
|
||||||
case explicitly.
|
case explicitly.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) }
|
fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value out of an option without copying.
|
* Gets the value out of an option without copying.
|
||||||
|
@ -430,7 +430,7 @@ pub impl<T> Option<T> {
|
||||||
* Fails if the value equals `none`
|
* Fails if the value equals `none`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn unwrap(self) -> T { unwrap(self) }
|
fn unwrap(self) -> T { unwrap(self) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The option dance. Moves a value out of an option type and returns it,
|
* The option dance. Moves a value out of an option type and returns it,
|
||||||
|
@ -452,7 +452,7 @@ pub impl<T> Option<T> {
|
||||||
* Fails if the value equals `none`
|
* Fails if the value equals `none`
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
|
fn expect(self, reason: &str) -> T { expect(self, reason) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy> Option<T> {
|
pub impl<T:Copy> Option<T> {
|
||||||
|
@ -471,21 +471,21 @@ pub impl<T:Copy> Option<T> {
|
||||||
case explicitly.
|
case explicitly.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get(self) -> T { get(self) }
|
fn get(self) -> T { get(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_or_default(self, def: T) -> T { get_or_default(self, def) }
|
fn get_or_default(self, def: T) -> T { get_or_default(self, def) }
|
||||||
|
|
||||||
/// Applies a function zero or more times until the result is none.
|
/// Applies a function zero or more times until the result is none.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn while_some(self, blk: &fn(v: T) -> Option<T>) {
|
fn while_some(self, blk: &fn(v: T) -> Option<T>) {
|
||||||
while_some(self, blk)
|
while_some(self, blk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy + Zero> Option<T> {
|
pub impl<T:Copy + Zero> Option<T> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_or_zero(self) -> T { get_or_zero(self) }
|
fn get_or_zero(self) -> T { get_or_zero(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -15,20 +15,20 @@
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Eq> Eq for ~T {
|
impl<T:Eq> Eq for ~T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) }
|
fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) }
|
fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Ord> Ord for ~T {
|
impl<T:Ord> Ord for ~T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) }
|
fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) }
|
fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
|
fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
|
fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub struct WindowsPath {
|
||||||
components: ~[~str],
|
components: ~[~str],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn WindowsPath(s: &str) -> WindowsPath {
|
pub fn WindowsPath(s: &str) -> WindowsPath {
|
||||||
GenericPath::from_str(s)
|
GenericPath::from_str(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,42 +38,42 @@ pub struct PosixPath {
|
||||||
components: ~[~str],
|
components: ~[~str],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn PosixPath(s: &str) -> PosixPath {
|
pub fn PosixPath(s: &str) -> PosixPath {
|
||||||
GenericPath::from_str(s)
|
GenericPath::from_str(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GenericPath {
|
pub trait GenericPath {
|
||||||
pure fn from_str(&str) -> Self;
|
fn from_str(&str) -> Self;
|
||||||
|
|
||||||
pure fn dirname(&self) -> ~str;
|
fn dirname(&self) -> ~str;
|
||||||
pure fn filename(&self) -> Option<~str>;
|
fn filename(&self) -> Option<~str>;
|
||||||
pure fn filestem(&self) -> Option<~str>;
|
fn filestem(&self) -> Option<~str>;
|
||||||
pure fn filetype(&self) -> Option<~str>;
|
fn filetype(&self) -> Option<~str>;
|
||||||
|
|
||||||
pure fn with_dirname(&self, (&str)) -> Self;
|
fn with_dirname(&self, (&str)) -> Self;
|
||||||
pure fn with_filename(&self, (&str)) -> Self;
|
fn with_filename(&self, (&str)) -> Self;
|
||||||
pure fn with_filestem(&self, (&str)) -> Self;
|
fn with_filestem(&self, (&str)) -> Self;
|
||||||
pure fn with_filetype(&self, (&str)) -> Self;
|
fn with_filetype(&self, (&str)) -> Self;
|
||||||
|
|
||||||
pure fn dir_path(&self) -> Self;
|
fn dir_path(&self) -> Self;
|
||||||
pure fn file_path(&self) -> Self;
|
fn file_path(&self) -> Self;
|
||||||
|
|
||||||
pure fn push(&self, (&str)) -> Self;
|
fn push(&self, (&str)) -> Self;
|
||||||
pure fn push_rel(&self, (&Self)) -> Self;
|
fn push_rel(&self, (&Self)) -> Self;
|
||||||
pure fn push_many(&self, (&[~str])) -> Self;
|
fn push_many(&self, (&[~str])) -> Self;
|
||||||
pure fn pop(&self) -> Self;
|
fn pop(&self) -> Self;
|
||||||
|
|
||||||
pure fn unsafe_join(&self, (&Self)) -> Self;
|
fn unsafe_join(&self, (&Self)) -> Self;
|
||||||
pure fn is_restricted(&self) -> bool;
|
fn is_restricted(&self) -> bool;
|
||||||
|
|
||||||
pure fn normalize(&self) -> Self;
|
fn normalize(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub type Path = WindowsPath;
|
pub type Path = WindowsPath;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub pure fn Path(s: &str) -> Path {
|
pub fn Path(s: &str) -> Path {
|
||||||
WindowsPath(s)
|
WindowsPath(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ pub pure fn Path(s: &str) -> Path {
|
||||||
pub type Path = PosixPath;
|
pub type Path = PosixPath;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub pure fn Path(s: &str) -> Path {
|
pub fn Path(s: &str) -> Path {
|
||||||
PosixPath(s)
|
PosixPath(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ pub impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToStr for PosixPath {
|
impl ToStr for PosixPath {
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut s = ~"";
|
let mut s = ~"";
|
||||||
if self.is_absolute {
|
if self.is_absolute {
|
||||||
s += "/";
|
s += "/";
|
||||||
|
@ -380,14 +380,14 @@ impl ToStr for PosixPath {
|
||||||
// PosixPath and WindowsPath, most of their methods are common.
|
// PosixPath and WindowsPath, most of their methods are common.
|
||||||
impl GenericPath for PosixPath {
|
impl GenericPath for PosixPath {
|
||||||
|
|
||||||
pure fn from_str(s: &str) -> PosixPath {
|
fn from_str(s: &str) -> PosixPath {
|
||||||
let mut components = str::split_nonempty(s, |c| c == '/');
|
let mut components = str::split_nonempty(s, |c| c == '/');
|
||||||
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
|
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
|
||||||
return PosixPath { is_absolute: is_absolute,
|
return PosixPath { is_absolute: is_absolute,
|
||||||
components: components }
|
components: components }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn dirname(&self) -> ~str {
|
fn dirname(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = self.dir_path().to_str();
|
let s = self.dir_path().to_str();
|
||||||
if s.len() == 0 {
|
if s.len() == 0 {
|
||||||
|
@ -398,14 +398,14 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn filename(&self) -> Option<~str> {
|
fn filename(&self) -> Option<~str> {
|
||||||
match self.components.len() {
|
match self.components.len() {
|
||||||
0 => None,
|
0 => None,
|
||||||
n => Some(copy self.components[n - 1])
|
n => Some(copy self.components[n - 1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn filestem(&self) -> Option<~str> {
|
fn filestem(&self) -> Option<~str> {
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref f) => {
|
Some(ref f) => {
|
||||||
|
@ -417,7 +417,7 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn filetype(&self) -> Option<~str> {
|
fn filetype(&self) -> Option<~str> {
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref f) => {
|
Some(ref f) => {
|
||||||
|
@ -429,7 +429,7 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_dirname(&self, d: &str) -> PosixPath {
|
fn with_dirname(&self, d: &str) -> PosixPath {
|
||||||
let dpath = PosixPath(d);
|
let dpath = PosixPath(d);
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
Some(ref f) => dpath.push(*f),
|
Some(ref f) => dpath.push(*f),
|
||||||
|
@ -437,21 +437,21 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_filename(&self, f: &str) -> PosixPath {
|
fn with_filename(&self, f: &str) -> PosixPath {
|
||||||
unsafe {
|
unsafe {
|
||||||
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||||
self.dir_path().push(f)
|
self.dir_path().push(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_filestem(&self, s: &str) -> PosixPath {
|
fn with_filestem(&self, s: &str) -> PosixPath {
|
||||||
match self.filetype() {
|
match self.filetype() {
|
||||||
None => self.with_filename(s),
|
None => self.with_filename(s),
|
||||||
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
|
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_filetype(&self, t: &str) -> PosixPath {
|
fn with_filetype(&self, t: &str) -> PosixPath {
|
||||||
if t.len() == 0 {
|
if t.len() == 0 {
|
||||||
match self.filestem() {
|
match self.filestem() {
|
||||||
None => copy *self,
|
None => copy *self,
|
||||||
|
@ -466,7 +466,7 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn dir_path(&self) -> PosixPath {
|
fn dir_path(&self) -> PosixPath {
|
||||||
if self.components.len() != 0 {
|
if self.components.len() != 0 {
|
||||||
self.pop()
|
self.pop()
|
||||||
} else {
|
} else {
|
||||||
|
@ -474,7 +474,7 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn file_path(&self) -> PosixPath {
|
fn file_path(&self) -> PosixPath {
|
||||||
let cs = match self.filename() {
|
let cs = match self.filename() {
|
||||||
None => ~[],
|
None => ~[],
|
||||||
Some(ref f) => ~[copy *f]
|
Some(ref f) => ~[copy *f]
|
||||||
|
@ -483,12 +483,12 @@ impl GenericPath for PosixPath {
|
||||||
components: cs }
|
components: cs }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push_rel(&self, other: &PosixPath) -> PosixPath {
|
fn push_rel(&self, other: &PosixPath) -> PosixPath {
|
||||||
fail_unless!(!other.is_absolute);
|
fail_unless!(!other.is_absolute);
|
||||||
self.push_many(other.components)
|
self.push_many(other.components)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
|
fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
|
||||||
if other.is_absolute {
|
if other.is_absolute {
|
||||||
PosixPath { is_absolute: true,
|
PosixPath { is_absolute: true,
|
||||||
components: copy other.components }
|
components: copy other.components }
|
||||||
|
@ -497,11 +497,11 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn is_restricted(&self) -> bool {
|
fn is_restricted(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push_many(&self, cs: &[~str]) -> PosixPath {
|
fn push_many(&self, cs: &[~str]) -> PosixPath {
|
||||||
let mut v = copy self.components;
|
let mut v = copy self.components;
|
||||||
for cs.each |e| {
|
for cs.each |e| {
|
||||||
let mut ss = str::split_nonempty(
|
let mut ss = str::split_nonempty(
|
||||||
|
@ -513,14 +513,14 @@ impl GenericPath for PosixPath {
|
||||||
components: v }
|
components: v }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push(&self, s: &str) -> PosixPath {
|
fn push(&self, s: &str) -> PosixPath {
|
||||||
let mut v = copy self.components;
|
let mut v = copy self.components;
|
||||||
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
||||||
unsafe { v.push_all_move(ss); }
|
unsafe { v.push_all_move(ss); }
|
||||||
PosixPath { components: v, ..copy *self }
|
PosixPath { components: v, ..copy *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn pop(&self) -> PosixPath {
|
fn pop(&self) -> PosixPath {
|
||||||
let mut cs = copy self.components;
|
let mut cs = copy self.components;
|
||||||
if cs.len() != 0 {
|
if cs.len() != 0 {
|
||||||
unsafe { cs.pop(); }
|
unsafe { cs.pop(); }
|
||||||
|
@ -532,7 +532,7 @@ impl GenericPath for PosixPath {
|
||||||
//..self }
|
//..self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn normalize(&self) -> PosixPath {
|
fn normalize(&self) -> PosixPath {
|
||||||
return PosixPath {
|
return PosixPath {
|
||||||
is_absolute: self.is_absolute,
|
is_absolute: self.is_absolute,
|
||||||
components: normalize(self.components)
|
components: normalize(self.components)
|
||||||
|
@ -543,7 +543,7 @@ impl GenericPath for PosixPath {
|
||||||
|
|
||||||
|
|
||||||
impl ToStr for WindowsPath {
|
impl ToStr for WindowsPath {
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut s = ~"";
|
let mut s = ~"";
|
||||||
match self.host {
|
match self.host {
|
||||||
Some(ref h) => { s += "\\\\"; s += *h; }
|
Some(ref h) => { s += "\\\\"; s += *h; }
|
||||||
|
@ -563,7 +563,7 @@ impl ToStr for WindowsPath {
|
||||||
|
|
||||||
impl GenericPath for WindowsPath {
|
impl GenericPath for WindowsPath {
|
||||||
|
|
||||||
pure fn from_str(s: &str) -> WindowsPath {
|
fn from_str(s: &str) -> WindowsPath {
|
||||||
let host;
|
let host;
|
||||||
let device;
|
let device;
|
||||||
let rest;
|
let rest;
|
||||||
|
@ -599,7 +599,7 @@ impl GenericPath for WindowsPath {
|
||||||
components: components }
|
components: components }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn dirname(&self) -> ~str {
|
fn dirname(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = self.dir_path().to_str();
|
let s = self.dir_path().to_str();
|
||||||
if s.len() == 0 {
|
if s.len() == 0 {
|
||||||
|
@ -610,14 +610,14 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn filename(&self) -> Option<~str> {
|
fn filename(&self) -> Option<~str> {
|
||||||
match self.components.len() {
|
match self.components.len() {
|
||||||
0 => None,
|
0 => None,
|
||||||
n => Some(copy self.components[n - 1])
|
n => Some(copy self.components[n - 1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn filestem(&self) -> Option<~str> {
|
fn filestem(&self) -> Option<~str> {
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref f) => {
|
Some(ref f) => {
|
||||||
|
@ -629,7 +629,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn filetype(&self) -> Option<~str> {
|
fn filetype(&self) -> Option<~str> {
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref f) => {
|
Some(ref f) => {
|
||||||
|
@ -641,7 +641,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_dirname(&self, d: &str) -> WindowsPath {
|
fn with_dirname(&self, d: &str) -> WindowsPath {
|
||||||
let dpath = WindowsPath(d);
|
let dpath = WindowsPath(d);
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
Some(ref f) => dpath.push(*f),
|
Some(ref f) => dpath.push(*f),
|
||||||
|
@ -649,19 +649,19 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_filename(&self, f: &str) -> WindowsPath {
|
fn with_filename(&self, f: &str) -> WindowsPath {
|
||||||
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||||
self.dir_path().push(f)
|
self.dir_path().push(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_filestem(&self, s: &str) -> WindowsPath {
|
fn with_filestem(&self, s: &str) -> WindowsPath {
|
||||||
match self.filetype() {
|
match self.filetype() {
|
||||||
None => self.with_filename(s),
|
None => self.with_filename(s),
|
||||||
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
|
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn with_filetype(&self, t: &str) -> WindowsPath {
|
fn with_filetype(&self, t: &str) -> WindowsPath {
|
||||||
if t.len() == 0 {
|
if t.len() == 0 {
|
||||||
match self.filestem() {
|
match self.filestem() {
|
||||||
None => copy *self,
|
None => copy *self,
|
||||||
|
@ -677,7 +677,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn dir_path(&self) -> WindowsPath {
|
fn dir_path(&self) -> WindowsPath {
|
||||||
if self.components.len() != 0 {
|
if self.components.len() != 0 {
|
||||||
self.pop()
|
self.pop()
|
||||||
} else {
|
} else {
|
||||||
|
@ -685,7 +685,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn file_path(&self) -> WindowsPath {
|
fn file_path(&self) -> WindowsPath {
|
||||||
let cs = match self.filename() {
|
let cs = match self.filename() {
|
||||||
None => ~[],
|
None => ~[],
|
||||||
Some(ref f) => ~[copy *f]
|
Some(ref f) => ~[copy *f]
|
||||||
|
@ -696,12 +696,12 @@ impl GenericPath for WindowsPath {
|
||||||
components: cs }
|
components: cs }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
|
fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
|
||||||
fail_unless!(!other.is_absolute);
|
fail_unless!(!other.is_absolute);
|
||||||
self.push_many(other.components)
|
self.push_many(other.components)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
|
fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
|
||||||
/* rhs not absolute is simple push */
|
/* rhs not absolute is simple push */
|
||||||
if !other.is_absolute {
|
if !other.is_absolute {
|
||||||
return self.push_many(other.components);
|
return self.push_many(other.components);
|
||||||
|
@ -743,7 +743,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn is_restricted(&self) -> bool {
|
fn is_restricted(&self) -> bool {
|
||||||
match self.filestem() {
|
match self.filestem() {
|
||||||
Some(stem) => {
|
Some(stem) => {
|
||||||
match stem.to_lower() {
|
match stem.to_lower() {
|
||||||
|
@ -756,7 +756,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push_many(&self, cs: &[~str]) -> WindowsPath {
|
fn push_many(&self, cs: &[~str]) -> WindowsPath {
|
||||||
let mut v = copy self.components;
|
let mut v = copy self.components;
|
||||||
for cs.each |e| {
|
for cs.each |e| {
|
||||||
let mut ss = str::split_nonempty(
|
let mut ss = str::split_nonempty(
|
||||||
|
@ -773,14 +773,14 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push(&self, s: &str) -> WindowsPath {
|
fn push(&self, s: &str) -> WindowsPath {
|
||||||
let mut v = copy self.components;
|
let mut v = copy self.components;
|
||||||
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
||||||
unsafe { v.push_all_move(ss); }
|
unsafe { v.push_all_move(ss); }
|
||||||
return WindowsPath { components: v, ..copy *self }
|
return WindowsPath { components: v, ..copy *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn pop(&self) -> WindowsPath {
|
fn pop(&self) -> WindowsPath {
|
||||||
let mut cs = copy self.components;
|
let mut cs = copy self.components;
|
||||||
if cs.len() != 0 {
|
if cs.len() != 0 {
|
||||||
unsafe { cs.pop(); }
|
unsafe { cs.pop(); }
|
||||||
|
@ -793,7 +793,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn normalize(&self) -> WindowsPath {
|
fn normalize(&self) -> WindowsPath {
|
||||||
return WindowsPath {
|
return WindowsPath {
|
||||||
host: copy self.host,
|
host: copy self.host,
|
||||||
device: match self.device {
|
device: match self.device {
|
||||||
|
@ -807,7 +807,7 @@ impl GenericPath for WindowsPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub pure fn normalize(components: &[~str]) -> ~[~str] {
|
pub fn normalize(components: &[~str]) -> ~[~str] {
|
||||||
let mut cs = ~[];
|
let mut cs = ~[];
|
||||||
unsafe {
|
unsafe {
|
||||||
for components.each |c| {
|
for components.each |c| {
|
||||||
|
@ -831,11 +831,11 @@ pub mod windows {
|
||||||
use option::{None, Option, Some};
|
use option::{None, Option, Some};
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_sep(u: u8) -> bool {
|
pub fn is_sep(u: u8) -> bool {
|
||||||
u == '/' as u8 || u == '\\' as u8
|
u == '/' as u8 || u == '\\' as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
|
pub fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
|
||||||
if (s.len() > 1 &&
|
if (s.len() > 1 &&
|
||||||
(s[0] == '\\' as u8 || s[0] == '/' as u8) &&
|
(s[0] == '\\' as u8 || s[0] == '/' as u8) &&
|
||||||
s[0] == s[1]) {
|
s[0] == s[1]) {
|
||||||
|
@ -852,7 +852,7 @@ pub mod windows {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
|
pub fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if (s.len() > 1 &&
|
if (s.len() > 1 &&
|
||||||
libc::isalpha(s[0] as libc::c_int) != 0 &&
|
libc::isalpha(s[0] as libc::c_int) != 0 &&
|
||||||
|
|
|
@ -111,10 +111,10 @@ enum State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for State {
|
impl Eq for State {
|
||||||
pure fn eq(&self, other: &State) -> bool {
|
fn eq(&self, other: &State) -> bool {
|
||||||
((*self) as uint) == ((*other) as uint)
|
((*self) as uint) == ((*other) as uint)
|
||||||
}
|
}
|
||||||
pure fn ne(&self, other: &State) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &State) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BufferHeader {
|
pub struct BufferHeader {
|
||||||
|
@ -551,7 +551,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if messages are available.
|
/// Returns true if messages are available.
|
||||||
pub pure fn peek<T:Owned,Tb:Owned>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
pub fn peek<T:Owned,Tb:Owned>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
||||||
match unsafe {(*p.header()).state} {
|
match unsafe {(*p.header()).state} {
|
||||||
Empty | Terminated => false,
|
Empty | Terminated => false,
|
||||||
Blocked => fail!(~"peeking on blocked packet"),
|
Blocked => fail!(~"peeking on blocked packet"),
|
||||||
|
@ -723,11 +723,11 @@ pub fn select2<A:Owned,Ab:Owned,B:Owned,Bb:Owned>(
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait Selectable {
|
pub trait Selectable {
|
||||||
pure fn header(&self) -> *PacketHeader;
|
fn header(&self) -> *PacketHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable for *PacketHeader {
|
impl Selectable for *PacketHeader {
|
||||||
pure fn header(&self) -> *PacketHeader { *self }
|
fn header(&self) -> *PacketHeader { *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the index of an endpoint that is ready to receive.
|
/// Returns the index of an endpoint that is ready to receive.
|
||||||
|
@ -812,7 +812,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||||
option::unwrap(p)
|
option::unwrap(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn header(&self) -> *PacketHeader {
|
fn header(&self) -> *PacketHeader {
|
||||||
match self.p {
|
match self.p {
|
||||||
Some(packet) => unsafe {
|
Some(packet) => unsafe {
|
||||||
let packet = &*packet;
|
let packet = &*packet;
|
||||||
|
@ -879,7 +879,7 @@ pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Owned,Tbuffer:Owned> Selectable for RecvPacketBuffered<T, Tbuffer> {
|
impl<T:Owned,Tbuffer:Owned> Selectable for RecvPacketBuffered<T, Tbuffer> {
|
||||||
pure fn header(&self) -> *PacketHeader {
|
fn header(&self) -> *PacketHeader {
|
||||||
match self.p {
|
match self.p {
|
||||||
Some(packet) => unsafe {
|
Some(packet) => unsafe {
|
||||||
let packet = &*packet;
|
let packet = &*packet;
|
||||||
|
|
|
@ -51,11 +51,11 @@ pub mod rusti {
|
||||||
|
|
||||||
/// Get an unsafe pointer to a value
|
/// Get an unsafe pointer to a value
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
|
pub fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
|
||||||
|
|
||||||
/// Calculate the offset from a pointer
|
/// Calculate the offset from a pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
|
pub fn offset<T>(ptr: *T, count: uint) -> *T {
|
||||||
unsafe {
|
unsafe {
|
||||||
(ptr as uint + count * sys::size_of::<T>()) as *T
|
(ptr as uint + count * sys::size_of::<T>()) as *T
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
|
||||||
|
|
||||||
/// Calculate the offset from a const pointer
|
/// Calculate the offset from a const pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
|
pub fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
|
||||||
unsafe {
|
unsafe {
|
||||||
(ptr as uint + count * sys::size_of::<T>()) as *T
|
(ptr as uint + count * sys::size_of::<T>()) as *T
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ pub pure fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
|
||||||
|
|
||||||
/// Calculate the offset from a mut pointer
|
/// Calculate the offset from a mut pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
|
pub fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
|
||||||
(ptr as uint + count * sys::size_of::<T>()) as *mut T
|
(ptr as uint + count * sys::size_of::<T>()) as *mut T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,19 +93,19 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
|
||||||
|
|
||||||
/// Create an unsafe null pointer
|
/// Create an unsafe null pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
|
pub fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
|
||||||
|
|
||||||
/// Create an unsafe mutable null pointer
|
/// Create an unsafe mutable null pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
|
pub fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
|
||||||
|
|
||||||
/// Returns true if the pointer is equal to the null pointer.
|
/// Returns true if the pointer is equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
|
pub fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
|
||||||
|
|
||||||
/// Returns true if the pointer is not equal to the null pointer.
|
/// Returns true if the pointer is not equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
|
pub fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies data from one location to another
|
* Copies data from one location to another
|
||||||
|
@ -138,7 +138,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
|
||||||
reinterpret_cast.
|
reinterpret_cast.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_unsafe_ptr<T>(thing: &T) -> *T {
|
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
|
||||||
unsafe { cast::reinterpret_cast(&thing) }
|
unsafe { cast::reinterpret_cast(&thing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ pub pure fn to_unsafe_ptr<T>(thing: &T) -> *T {
|
||||||
reinterpret_cast.
|
reinterpret_cast.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
|
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
|
||||||
unsafe { cast::reinterpret_cast(&thing) }
|
unsafe { cast::reinterpret_cast(&thing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ pub pure fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
|
||||||
reinterpret_cast.
|
reinterpret_cast.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
||||||
unsafe { cast::reinterpret_cast(&thing) }
|
unsafe { cast::reinterpret_cast(&thing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ pub pure fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
||||||
(I couldn't think of a cutesy name for this one.)
|
(I couldn't think of a cutesy name for this one.)
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_uint<T>(thing: &T) -> uint {
|
pub fn to_uint<T>(thing: &T) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
cast::reinterpret_cast(&thing)
|
cast::reinterpret_cast(&thing)
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ pub pure fn to_uint<T>(thing: &T) -> uint {
|
||||||
|
|
||||||
/// Determine if two borrowed pointers point to the same thing.
|
/// Determine if two borrowed pointers point to the same thing.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
|
pub fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
|
||||||
to_uint(thing) == to_uint(other)
|
to_uint(thing) == to_uint(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,46 +223,46 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Ptr<T> {
|
pub trait Ptr<T> {
|
||||||
pure fn is_null(&const self) -> bool;
|
fn is_null(&const self) -> bool;
|
||||||
pure fn is_not_null(&const self) -> bool;
|
fn is_not_null(&const self) -> bool;
|
||||||
pure fn offset(&self, count: uint) -> Self;
|
fn offset(&self, count: uint) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for immutable pointers
|
/// Extension methods for immutable pointers
|
||||||
impl<T> Ptr<T> for *T {
|
impl<T> Ptr<T> for *T {
|
||||||
/// Returns true if the pointer is equal to the null pointer.
|
/// Returns true if the pointer is equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_null(&const self) -> bool { is_null(*self) }
|
fn is_null(&const self) -> bool { is_null(*self) }
|
||||||
|
|
||||||
/// Returns true if the pointer is not equal to the null pointer.
|
/// Returns true if the pointer is not equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_not_null(&const self) -> bool { is_not_null(*self) }
|
fn is_not_null(&const self) -> bool { is_not_null(*self) }
|
||||||
|
|
||||||
/// Calculates the offset from a pointer.
|
/// Calculates the offset from a pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn offset(&self, count: uint) -> *T { offset(*self, count) }
|
fn offset(&self, count: uint) -> *T { offset(*self, count) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for mutable pointers
|
/// Extension methods for mutable pointers
|
||||||
impl<T> Ptr<T> for *mut T {
|
impl<T> Ptr<T> for *mut T {
|
||||||
/// Returns true if the pointer is equal to the null pointer.
|
/// Returns true if the pointer is equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_null(&const self) -> bool { is_null(*self) }
|
fn is_null(&const self) -> bool { is_null(*self) }
|
||||||
|
|
||||||
/// Returns true if the pointer is not equal to the null pointer.
|
/// Returns true if the pointer is not equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_not_null(&const self) -> bool { is_not_null(*self) }
|
fn is_not_null(&const self) -> bool { is_not_null(*self) }
|
||||||
|
|
||||||
/// Calculates the offset from a mutable pointer.
|
/// Calculates the offset from a mutable pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) }
|
fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equality for pointers
|
// Equality for pointers
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T> Eq for *const T {
|
impl<T> Eq for *const T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &*const T) -> bool {
|
fn eq(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::reinterpret_cast(&(*self));
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::reinterpret_cast(&(*other));
|
||||||
|
@ -270,14 +270,14 @@ impl<T> Eq for *const T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comparison for pointers
|
// Comparison for pointers
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T> Ord for *const T {
|
impl<T> Ord for *const T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &*const T) -> bool {
|
fn lt(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::reinterpret_cast(&(*self));
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::reinterpret_cast(&(*other));
|
||||||
|
@ -285,7 +285,7 @@ impl<T> Ord for *const T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &*const T) -> bool {
|
fn le(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::reinterpret_cast(&(*self));
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::reinterpret_cast(&(*other));
|
||||||
|
@ -293,7 +293,7 @@ impl<T> Ord for *const T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &*const T) -> bool {
|
fn ge(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::reinterpret_cast(&(*self));
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::reinterpret_cast(&(*other));
|
||||||
|
@ -301,7 +301,7 @@ impl<T> Ord for *const T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &*const T) -> bool {
|
fn gt(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::reinterpret_cast(&(*self));
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::reinterpret_cast(&(*other));
|
||||||
|
@ -314,11 +314,11 @@ impl<T> Ord for *const T {
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Eq> Eq for &'self const T {
|
impl<T:Eq> Eq for &'self const T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: & &'self const T) -> bool {
|
fn eq(&self, other: & &'self const T) -> bool {
|
||||||
return *(*self) == *(*other);
|
return *(*self) == *(*other);
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: & &'self const T) -> bool {
|
fn ne(&self, other: & &'self const T) -> bool {
|
||||||
return *(*self) != *(*other);
|
return *(*self) != *(*other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,19 +327,19 @@ impl<T:Eq> Eq for &'self const T {
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T:Ord> Ord for &'self const T {
|
impl<T:Ord> Ord for &'self const T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: & &'self const T) -> bool {
|
fn lt(&self, other: & &'self const T) -> bool {
|
||||||
*(*self) < *(*other)
|
*(*self) < *(*other)
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: & &'self const T) -> bool {
|
fn le(&self, other: & &'self const T) -> bool {
|
||||||
*(*self) <= *(*other)
|
*(*self) <= *(*other)
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: & &'self const T) -> bool {
|
fn ge(&self, other: & &'self const T) -> bool {
|
||||||
*(*self) >= *(*other)
|
*(*self) >= *(*other)
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: & &'self const T) -> bool {
|
fn gt(&self, other: & &'self const T) -> bool {
|
||||||
*(*self) > *(*other)
|
*(*self) > *(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -527,12 +527,12 @@ impl Rng for XorShiftState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn xorshift() -> @Rng {
|
pub fn xorshift() -> @Rng {
|
||||||
// constants taken from http://en.wikipedia.org/wiki/Xorshift
|
// constants taken from http://en.wikipedia.org/wiki/Xorshift
|
||||||
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
|
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> @Rng {
|
pub fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> @Rng {
|
||||||
@XorShiftState { x: x, y: y, z: z, w: w } as @Rng
|
@XorShiftState { x: x, y: y, z: z, w: w } as @Rng
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub enum Result<T, U> {
|
||||||
* If the result is an error
|
* If the result is an error
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get<T:Copy,U>(res: &Result<T, U>) -> T {
|
pub fn get<T:Copy,U>(res: &Result<T, U>) -> T {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(copy t) => t,
|
Ok(copy t) => t,
|
||||||
Err(ref the_err) => unsafe {
|
Err(ref the_err) => unsafe {
|
||||||
|
@ -53,7 +53,7 @@ pub pure fn get<T:Copy,U>(res: &Result<T, U>) -> T {
|
||||||
* If the result is an error
|
* If the result is an error
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
|
pub fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(ref t) => t,
|
Ok(ref t) => t,
|
||||||
Err(ref the_err) => unsafe {
|
Err(ref the_err) => unsafe {
|
||||||
|
@ -70,7 +70,7 @@ pub pure fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
|
||||||
* If the result is not an error
|
* If the result is not an error
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
pub fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
||||||
match *res {
|
match *res {
|
||||||
Err(copy u) => u,
|
Err(copy u) => u,
|
||||||
Ok(_) => fail!(~"get_err called on ok result")
|
Ok(_) => fail!(~"get_err called on ok result")
|
||||||
|
@ -79,7 +79,7 @@ pub pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
||||||
|
|
||||||
/// Returns true if the result is `ok`
|
/// Returns true if the result is `ok`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_ok<T, U>(res: &Result<T, U>) -> bool {
|
pub fn is_ok<T, U>(res: &Result<T, U>) -> bool {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(_) => false
|
Err(_) => false
|
||||||
|
@ -88,7 +88,7 @@ pub pure fn is_ok<T, U>(res: &Result<T, U>) -> bool {
|
||||||
|
|
||||||
/// Returns true if the result is `err`
|
/// Returns true if the result is `err`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn is_err<T, U>(res: &Result<T, U>) -> bool {
|
pub fn is_err<T, U>(res: &Result<T, U>) -> bool {
|
||||||
!is_ok(res)
|
!is_ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ pub pure fn is_err<T, U>(res: &Result<T, U>) -> bool {
|
||||||
* result variants are converted to `either::left`.
|
* result variants are converted to `either::left`.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
|
pub fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
|
||||||
-> Either<T, U> {
|
-> Either<T, U> {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(copy res) => either::Right(res),
|
Ok(copy res) => either::Right(res),
|
||||||
|
@ -122,7 +122,7 @@ pub pure fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
|
pub fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
|
||||||
-> Result<U, V>) -> Result<U, V> {
|
-> Result<U, V>) -> Result<U, V> {
|
||||||
match res {
|
match res {
|
||||||
Ok(t) => op(t),
|
Ok(t) => op(t),
|
||||||
|
@ -139,7 +139,7 @@ pub pure fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
|
||||||
* successful result while handling an error.
|
* successful result while handling an error.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn chain_err<T, U, V>(
|
pub fn chain_err<T, U, V>(
|
||||||
res: Result<T, V>,
|
res: Result<T, V>,
|
||||||
op: &fn(t: V) -> Result<T, U>)
|
op: &fn(t: V) -> Result<T, U>)
|
||||||
-> Result<T, U> {
|
-> Result<T, U> {
|
||||||
|
@ -164,7 +164,7 @@ pub pure fn chain_err<T, U, V>(
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
|
pub fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(ref t) => f(t),
|
Ok(ref t) => f(t),
|
||||||
Err(_) => ()
|
Err(_) => ()
|
||||||
|
@ -180,7 +180,7 @@ pub pure fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
|
||||||
* handling an error.
|
* handling an error.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
|
pub fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(ref e) => f(e)
|
Err(ref e) => f(e)
|
||||||
|
@ -202,7 +202,7 @@ pub pure fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
|
pub fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
|
||||||
-> Result<U, E> {
|
-> Result<U, E> {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(ref t) => Ok(op(t)),
|
Ok(ref t) => Ok(op(t)),
|
||||||
|
@ -219,7 +219,7 @@ pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
|
||||||
* successful result while handling an error.
|
* successful result while handling an error.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
|
pub fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
|
||||||
-> Result<T, F> {
|
-> Result<T, F> {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(copy t) => Ok(t),
|
Ok(copy t) => Ok(t),
|
||||||
|
@ -229,53 +229,53 @@ pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
|
||||||
|
|
||||||
pub impl<T, E> Result<T, E> {
|
pub impl<T, E> Result<T, E> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_ref(&self) -> &'self T { get_ref(self) }
|
fn get_ref(&self) -> &'self T { get_ref(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_ok(&self) -> bool { is_ok(self) }
|
fn is_ok(&self) -> bool { is_ok(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_err(&self) -> bool { is_err(self) }
|
fn is_err(&self) -> bool { is_err(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter(&self, f: &fn(&T)) { iter(self, f) }
|
fn iter(&self, f: &fn(&T)) { iter(self, f) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
|
fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn unwrap(self) -> T { unwrap(self) }
|
fn unwrap(self) -> T { unwrap(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn unwrap_err(self) -> E { unwrap_err(self) }
|
fn unwrap_err(self) -> E { unwrap_err(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
|
fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||||
chain(self, op)
|
chain(self, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
|
fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
|
||||||
chain_err(self, op)
|
chain_err(self, op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy,E> Result<T, E> {
|
pub impl<T:Copy,E> Result<T, E> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get(&self) -> T { get(self) }
|
fn get(&self) -> T { get(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
|
fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
|
||||||
map_err(self, op)
|
map_err(self, op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T, E: Copy> Result<T, E> {
|
pub impl<T, E: Copy> Result<T, E> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_err(&self) -> E { get_err(self) }
|
fn get_err(&self) -> E { get_err(self) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
|
fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
|
||||||
map(self, op)
|
map(self, op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
|
||||||
|
|
||||||
/// Unwraps a result, assuming it is an `ok(T)`
|
/// Unwraps a result, assuming it is an `ok(T)`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
|
pub fn unwrap<T, U>(res: Result<T, U>) -> T {
|
||||||
match res {
|
match res {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(_) => fail!(~"unwrap called on an err result")
|
Err(_) => fail!(~"unwrap called on an err result")
|
||||||
|
@ -384,7 +384,7 @@ pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
|
||||||
|
|
||||||
/// Unwraps a result, assuming it is an `err(U)`
|
/// Unwraps a result, assuming it is an `err(U)`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap_err<T, U>(res: Result<T, U>) -> U {
|
pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
|
||||||
match res {
|
match res {
|
||||||
Err(u) => u,
|
Err(u) => u,
|
||||||
Ok(_) => fail!(~"unwrap called on an ok result")
|
Ok(_) => fail!(~"unwrap called on an ok result")
|
||||||
|
|
|
@ -184,7 +184,7 @@ fn align_down(sp: *mut uint) -> *mut uint {
|
||||||
|
|
||||||
// XXX: ptr::offset is positive ints only
|
// XXX: ptr::offset is positive ints only
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
|
pub fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
|
||||||
use core::sys::size_of;
|
use core::sys::size_of;
|
||||||
unsafe {
|
unsafe {
|
||||||
(ptr as int + count * (size_of::<T>() as int)) as *mut T
|
(ptr as int + count * (size_of::<T>() as int)) as *mut T
|
||||||
|
|
|
@ -518,7 +518,7 @@ struct UvError(uvll::uv_err_t);
|
||||||
|
|
||||||
impl UvError {
|
impl UvError {
|
||||||
|
|
||||||
pure fn name(&self) -> ~str {
|
fn name(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let inner = match self { &UvError(ref a) => a };
|
let inner = match self { &UvError(ref a) => a };
|
||||||
let name_str = uvll::err_name(inner);
|
let name_str = uvll::err_name(inner);
|
||||||
|
@ -527,7 +527,7 @@ impl UvError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn desc(&self) -> ~str {
|
fn desc(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let inner = match self { &UvError(ref a) => a };
|
let inner = match self { &UvError(ref a) => a };
|
||||||
let desc_str = uvll::strerror(inner);
|
let desc_str = uvll::strerror(inner);
|
||||||
|
@ -538,7 +538,7 @@ impl UvError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToStr for UvError {
|
impl ToStr for UvError {
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
fmt!("%s: %s", self.name(), self.desc())
|
fmt!("%s: %s", self.name(), self.desc())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -60,15 +60,15 @@ pub mod rustrt {
|
||||||
|
|
||||||
/// Compares contents of two pointers using the default method.
|
/// Compares contents of two pointers using the default method.
|
||||||
/// Equivalent to `*x1 == *x2`. Useful for hashtables.
|
/// Equivalent to `*x1 == *x2`. Useful for hashtables.
|
||||||
pub pure fn shape_eq<T:Eq>(x1: &T, x2: &T) -> bool {
|
pub fn shape_eq<T:Eq>(x1: &T, x2: &T) -> bool {
|
||||||
*x1 == *x2
|
*x1 == *x2
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn shape_lt<T:Ord>(x1: &T, x2: &T) -> bool {
|
pub fn shape_lt<T:Ord>(x1: &T, x2: &T) -> bool {
|
||||||
*x1 < *x2
|
*x1 < *x2
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
|
pub fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
|
||||||
*x1 <= *x2
|
*x1 <= *x2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,13 +79,13 @@ pub pure fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
|
||||||
* performing dark magick.
|
* performing dark magick.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_type_desc<T>() -> *TypeDesc {
|
pub fn get_type_desc<T>() -> *TypeDesc {
|
||||||
unsafe { rusti::get_tydesc::<T>() as *TypeDesc }
|
unsafe { rusti::get_tydesc::<T>() as *TypeDesc }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the size of a type
|
/// Returns the size of a type
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn size_of<T>() -> uint {
|
pub fn size_of<T>() -> uint {
|
||||||
unsafe { rusti::size_of::<T>() }
|
unsafe { rusti::size_of::<T>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ pub pure fn size_of<T>() -> uint {
|
||||||
* Useful for building structures containing variable-length arrays.
|
* Useful for building structures containing variable-length arrays.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn nonzero_size_of<T>() -> uint {
|
pub fn nonzero_size_of<T>() -> uint {
|
||||||
let s = size_of::<T>();
|
let s = size_of::<T>();
|
||||||
if s == 0 { 1 } else { s }
|
if s == 0 { 1 } else { s }
|
||||||
}
|
}
|
||||||
|
@ -107,26 +107,26 @@ pub pure fn nonzero_size_of<T>() -> uint {
|
||||||
* than the preferred alignment.
|
* than the preferred alignment.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn min_align_of<T>() -> uint {
|
pub fn min_align_of<T>() -> uint {
|
||||||
unsafe { rusti::min_align_of::<T>() }
|
unsafe { rusti::min_align_of::<T>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the preferred alignment of a type
|
/// Returns the preferred alignment of a type
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn pref_align_of<T>() -> uint {
|
pub fn pref_align_of<T>() -> uint {
|
||||||
unsafe { rusti::pref_align_of::<T>() }
|
unsafe { rusti::pref_align_of::<T>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the refcount of a shared box (as just before calling this)
|
/// Returns the refcount of a shared box (as just before calling this)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn refcount<T>(t: @T) -> uint {
|
pub fn refcount<T>(t: @T) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ref_ptr: *uint = cast::reinterpret_cast(&t);
|
let ref_ptr: *uint = cast::reinterpret_cast(&t);
|
||||||
*ref_ptr - 1
|
*ref_ptr - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn log_str<T>(t: &T) -> ~str {
|
pub fn log_str<T>(t: &T) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
do io::with_str_writer |wr| {
|
do io::with_str_writer |wr| {
|
||||||
repr::write_repr(wr, t)
|
repr::write_repr(wr, t)
|
||||||
|
@ -135,7 +135,7 @@ pub pure fn log_str<T>(t: &T) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initiate task failure */
|
/** Initiate task failure */
|
||||||
pub pure fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
|
pub fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
|
||||||
do str::as_buf(msg) |msg_buf, _msg_len| {
|
do str::as_buf(msg) |msg_buf, _msg_len| {
|
||||||
do str::as_buf(file) |file_buf, _file_len| {
|
do str::as_buf(file) |file_buf, _file_len| {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -148,7 +148,7 @@ pub pure fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME #4427: Temporary until rt::rt_fail_ goes away
|
// FIXME #4427: Temporary until rt::rt_fail_ goes away
|
||||||
pub pure fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
||||||
unsafe {
|
unsafe {
|
||||||
gc::cleanup_stack_for_failure();
|
gc::cleanup_stack_for_failure();
|
||||||
rustrt::rust_upcall_fail(msg, file, line);
|
rustrt::rust_upcall_fail(msg, file, line);
|
||||||
|
@ -156,7 +156,7 @@ pub pure fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
|
pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
|
||||||
unsafe {
|
unsafe {
|
||||||
let (msg, file) = (msg.to_owned(), file.to_owned());
|
let (msg, file) = (msg.to_owned(), file.to_owned());
|
||||||
begin_unwind(~"assertion failed: " + msg, file, line)
|
begin_unwind(~"assertion failed: " + msg, file, line)
|
||||||
|
|
|
@ -24,14 +24,14 @@ pub trait LocalData { }
|
||||||
impl<T:Durable> LocalData for @T { }
|
impl<T:Durable> LocalData for @T { }
|
||||||
|
|
||||||
impl Eq for @LocalData {
|
impl Eq for @LocalData {
|
||||||
pure fn eq(&self, other: &@LocalData) -> bool {
|
fn eq(&self, other: &@LocalData) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self));
|
let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self));
|
||||||
let ptr_b: (uint, uint) = cast::reinterpret_cast(other);
|
let ptr_b: (uint, uint) = cast::reinterpret_cast(other);
|
||||||
return ptr_a == ptr_b;
|
return ptr_a == ptr_b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pure fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// If TLS is used heavily in future, this could be made more efficient with a
|
// If TLS is used heavily in future, this could be made more efficient with a
|
||||||
|
|
|
@ -78,13 +78,13 @@ pub enum TaskResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for TaskResult {
|
impl Eq for TaskResult {
|
||||||
pure fn eq(&self, other: &TaskResult) -> bool {
|
fn eq(&self, other: &TaskResult) -> bool {
|
||||||
match ((*self), (*other)) {
|
match ((*self), (*other)) {
|
||||||
(Success, Success) | (Failure, Failure) => true,
|
(Success, Success) | (Failure, Failure) => true,
|
||||||
(Success, _) | (Failure, _) => false
|
(Success, _) | (Failure, _) => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pure fn ne(&self, other: &TaskResult) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &TaskResult) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scheduler modes
|
/// Scheduler modes
|
||||||
|
|
|
@ -126,7 +126,7 @@ type TaskGroupArc = unstable::Exclusive<Option<TaskGroupData>>;
|
||||||
type TaskGroupInner = &'self mut Option<TaskGroupData>;
|
type TaskGroupInner = &'self mut Option<TaskGroupData>;
|
||||||
|
|
||||||
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
|
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
|
||||||
pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
|
fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
|
||||||
(&const tg.members).is_empty()
|
(&const tg.members).is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,12 +43,12 @@ pub trait IterBytes {
|
||||||
* left-to-right in declaration order, regardless of
|
* left-to-right in declaration order, regardless of
|
||||||
* underlying memory endianness.
|
* underlying memory endianness.
|
||||||
*/
|
*/
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb);
|
fn iter_bytes(&self, lsb0: bool, f: Cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IterBytes for bool {
|
impl IterBytes for bool {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
||||||
f([
|
f([
|
||||||
*self as u8
|
*self as u8
|
||||||
]);
|
]);
|
||||||
|
@ -57,7 +57,7 @@ impl IterBytes for bool {
|
||||||
|
|
||||||
impl IterBytes for u8 {
|
impl IterBytes for u8 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
||||||
f([
|
f([
|
||||||
*self
|
*self
|
||||||
]);
|
]);
|
||||||
|
@ -66,7 +66,7 @@ impl IterBytes for u8 {
|
||||||
|
|
||||||
impl IterBytes for u16 {
|
impl IterBytes for u16 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
if lsb0 {
|
if lsb0 {
|
||||||
f([
|
f([
|
||||||
*self as u8,
|
*self as u8,
|
||||||
|
@ -83,7 +83,7 @@ impl IterBytes for u16 {
|
||||||
|
|
||||||
impl IterBytes for u32 {
|
impl IterBytes for u32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
if lsb0 {
|
if lsb0 {
|
||||||
f([
|
f([
|
||||||
*self as u8,
|
*self as u8,
|
||||||
|
@ -104,7 +104,7 @@ impl IterBytes for u32 {
|
||||||
|
|
||||||
impl IterBytes for u64 {
|
impl IterBytes for u64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
if lsb0 {
|
if lsb0 {
|
||||||
f([
|
f([
|
||||||
*self as u8,
|
*self as u8,
|
||||||
|
@ -133,35 +133,35 @@ impl IterBytes for u64 {
|
||||||
|
|
||||||
impl IterBytes for i8 {
|
impl IterBytes for i8 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u8).iter_bytes(lsb0, f)
|
(*self as u8).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IterBytes for i16 {
|
impl IterBytes for i16 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u16).iter_bytes(lsb0, f)
|
(*self as u16).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IterBytes for i32 {
|
impl IterBytes for i32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u32).iter_bytes(lsb0, f)
|
(*self as u32).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IterBytes for i64 {
|
impl IterBytes for i64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u64).iter_bytes(lsb0, f)
|
(*self as u64).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IterBytes for char {
|
impl IterBytes for char {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u32).iter_bytes(lsb0, f)
|
(*self as u32).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ pub mod x32 {
|
||||||
|
|
||||||
impl IterBytes for uint {
|
impl IterBytes for uint {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u32).iter_bytes(lsb0, f)
|
(*self as u32).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ pub mod x64 {
|
||||||
|
|
||||||
impl IterBytes for uint {
|
impl IterBytes for uint {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as u64).iter_bytes(lsb0, f)
|
(*self as u64).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,14 +192,14 @@ pub mod x64 {
|
||||||
|
|
||||||
impl IterBytes for int {
|
impl IterBytes for int {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as uint).iter_bytes(lsb0, f)
|
(*self as uint).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for &'self [A] {
|
impl<A:IterBytes> IterBytes for &'self [A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
for (*self).each |elt| {
|
for (*self).each |elt| {
|
||||||
do elt.iter_bytes(lsb0) |bytes| {
|
do elt.iter_bytes(lsb0) |bytes| {
|
||||||
f(bytes)
|
f(bytes)
|
||||||
|
@ -210,7 +210,7 @@ impl<A:IterBytes> IterBytes for &'self [A] {
|
||||||
|
|
||||||
impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
|
impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
(ref a, ref b) => {
|
(ref a, ref b) => {
|
||||||
iter_bytes_2(a, b, lsb0, f);
|
iter_bytes_2(a, b, lsb0, f);
|
||||||
|
@ -221,7 +221,7 @@ impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
|
||||||
|
|
||||||
impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
|
impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
(ref a, ref b, ref c) => {
|
(ref a, ref b, ref c) => {
|
||||||
iter_bytes_3(a, b, c, lsb0, f);
|
iter_bytes_3(a, b, c, lsb0, f);
|
||||||
|
@ -231,25 +231,25 @@ impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move this to vec, probably.
|
// Move this to vec, probably.
|
||||||
pure fn borrow<A>(a: &'x [A]) -> &'x [A] {
|
fn borrow<A>(a: &'x [A]) -> &'x [A] {
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for ~[A] {
|
impl<A:IterBytes> IterBytes for ~[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
borrow(*self).iter_bytes(lsb0, f)
|
borrow(*self).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for @[A] {
|
impl<A:IterBytes> IterBytes for @[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
borrow(*self).iter_bytes(lsb0, f)
|
borrow(*self).iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
|
pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
|
||||||
lsb0: bool, z: Cb) {
|
lsb0: bool, z: Cb) {
|
||||||
let mut flag = true;
|
let mut flag = true;
|
||||||
a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
||||||
|
@ -257,7 +257,7 @@ pub pure fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
|
||||||
b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn iter_bytes_3<A: IterBytes,
|
pub fn iter_bytes_3<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes>(a: &A, b: &B, c: &C,
|
C: IterBytes>(a: &A, b: &B, c: &C,
|
||||||
lsb0: bool, z: Cb) {
|
lsb0: bool, z: Cb) {
|
||||||
|
@ -269,7 +269,7 @@ pub pure fn iter_bytes_3<A: IterBytes,
|
||||||
c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn iter_bytes_4<A: IterBytes,
|
pub fn iter_bytes_4<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes,
|
C: IterBytes,
|
||||||
D: IterBytes>(a: &A, b: &B, c: &C,
|
D: IterBytes>(a: &A, b: &B, c: &C,
|
||||||
|
@ -285,7 +285,7 @@ pub pure fn iter_bytes_4<A: IterBytes,
|
||||||
d.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
d.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn iter_bytes_5<A: IterBytes,
|
pub fn iter_bytes_5<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes,
|
C: IterBytes,
|
||||||
D: IterBytes,
|
D: IterBytes,
|
||||||
|
@ -304,7 +304,7 @@ pub pure fn iter_bytes_5<A: IterBytes,
|
||||||
e.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
e.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn iter_bytes_6<A: IterBytes,
|
pub fn iter_bytes_6<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes,
|
C: IterBytes,
|
||||||
D: IterBytes,
|
D: IterBytes,
|
||||||
|
@ -326,7 +326,7 @@ pub pure fn iter_bytes_6<A: IterBytes,
|
||||||
f.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
f.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn iter_bytes_7<A: IterBytes,
|
pub fn iter_bytes_7<A: IterBytes,
|
||||||
B: IterBytes,
|
B: IterBytes,
|
||||||
C: IterBytes,
|
C: IterBytes,
|
||||||
D: IterBytes,
|
D: IterBytes,
|
||||||
|
@ -354,7 +354,7 @@ pub pure fn iter_bytes_7<A: IterBytes,
|
||||||
|
|
||||||
impl IterBytes for &'self str {
|
impl IterBytes for &'self str {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
||||||
do str::byte_slice(*self) |bytes| {
|
do str::byte_slice(*self) |bytes| {
|
||||||
f(bytes);
|
f(bytes);
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ impl IterBytes for &'self str {
|
||||||
|
|
||||||
impl IterBytes for ~str {
|
impl IterBytes for ~str {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
||||||
do str::byte_slice(*self) |bytes| {
|
do str::byte_slice(*self) |bytes| {
|
||||||
f(bytes);
|
f(bytes);
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ impl IterBytes for ~str {
|
||||||
|
|
||||||
impl IterBytes for @str {
|
impl IterBytes for @str {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
|
||||||
do str::byte_slice(*self) |bytes| {
|
do str::byte_slice(*self) |bytes| {
|
||||||
f(bytes);
|
f(bytes);
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ impl IterBytes for @str {
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for Option<A> {
|
impl<A:IterBytes> IterBytes for Option<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
Some(ref a) => iter_bytes_2(&0u8, a, lsb0, f),
|
Some(ref a) => iter_bytes_2(&0u8, a, lsb0, f),
|
||||||
None => 1u8.iter_bytes(lsb0, f)
|
None => 1u8.iter_bytes(lsb0, f)
|
||||||
|
@ -391,21 +391,21 @@ impl<A:IterBytes> IterBytes for Option<A> {
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for &'self A {
|
impl<A:IterBytes> IterBytes for &'self A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(**self).iter_bytes(lsb0, f);
|
(**self).iter_bytes(lsb0, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for @A {
|
impl<A:IterBytes> IterBytes for @A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(**self).iter_bytes(lsb0, f);
|
(**self).iter_bytes(lsb0, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:IterBytes> IterBytes for ~A {
|
impl<A:IterBytes> IterBytes for ~A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(**self).iter_bytes(lsb0, f);
|
(**self).iter_bytes(lsb0, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ impl<A:IterBytes> IterBytes for ~A {
|
||||||
// to the target; it just gives you the pointer-bytes.
|
// to the target; it just gives you the pointer-bytes.
|
||||||
impl<A> IterBytes for *const A {
|
impl<A> IterBytes for *const A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(*self as uint).iter_bytes(lsb0, f);
|
(*self as uint).iter_bytes(lsb0, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,23 +17,23 @@ The `ToStr` trait for converting to strings
|
||||||
use str;
|
use str;
|
||||||
|
|
||||||
pub trait ToStr {
|
pub trait ToStr {
|
||||||
pure fn to_str(&self) -> ~str;
|
fn to_str(&self) -> ~str;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToStr for bool {
|
impl ToStr for bool {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str { ::bool::to_str(*self) }
|
fn to_str(&self) -> ~str { ::bool::to_str(*self) }
|
||||||
}
|
}
|
||||||
impl ToStr for () {
|
impl ToStr for () {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str { ~"()" }
|
fn to_str(&self) -> ~str { ~"()" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME #4898: impl for one-tuples
|
// FIXME #4898: impl for one-tuples
|
||||||
|
|
||||||
impl<A:ToStr,B:ToStr> ToStr for (A, B) {
|
impl<A:ToStr,B:ToStr> ToStr for (A, B) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
// FIXME(#4760): this causes an llvm assertion
|
// FIXME(#4760): this causes an llvm assertion
|
||||||
//let &(ref a, ref b) = self;
|
//let &(ref a, ref b) = self;
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -45,7 +45,7 @@ impl<A:ToStr,B:ToStr> ToStr for (A, B) {
|
||||||
}
|
}
|
||||||
impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
|
impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
// FIXME(#4760): this causes an llvm assertion
|
// FIXME(#4760): this causes an llvm assertion
|
||||||
//let &(ref a, ref b, ref c) = self;
|
//let &(ref a, ref b, ref c) = self;
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -62,7 +62,7 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
|
||||||
|
|
||||||
impl<A:ToStr> ToStr for &'self [A] {
|
impl<A:ToStr> ToStr for &'self [A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
// FIXME #4568
|
// FIXME #4568
|
||||||
// Bleh -- not really unsafe
|
// Bleh -- not really unsafe
|
||||||
|
@ -83,7 +83,7 @@ impl<A:ToStr> ToStr for &'self [A] {
|
||||||
|
|
||||||
impl<A:ToStr> ToStr for ~[A] {
|
impl<A:ToStr> ToStr for ~[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
// FIXME #4568
|
// FIXME #4568
|
||||||
// Bleh -- not really unsafe
|
// Bleh -- not really unsafe
|
||||||
|
@ -104,7 +104,7 @@ impl<A:ToStr> ToStr for ~[A] {
|
||||||
|
|
||||||
impl<A:ToStr> ToStr for @[A] {
|
impl<A:ToStr> ToStr for @[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
// FIXME #4568
|
// FIXME #4568
|
||||||
// Bleh -- not really unsafe
|
// Bleh -- not really unsafe
|
||||||
|
|
|
@ -32,17 +32,17 @@ pub struct TrieMap<T> {
|
||||||
impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> {
|
impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> {
|
||||||
/// Visit all key-value pairs in order
|
/// Visit all key-value pairs in order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
|
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
|
||||||
self.root.each(f);
|
self.root.each(f);
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
|
impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
|
||||||
/// Visit all key-value pairs in reverse order
|
/// Visit all key-value pairs in reverse order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
|
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
|
||||||
self.root.each_reverse(f);
|
self.root.each_reverse(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,11 @@ impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
|
||||||
impl<T> Container for TrieMap<T> {
|
impl<T> Container for TrieMap<T> {
|
||||||
/// Return the number of elements in the map
|
/// Return the number of elements in the map
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn len(&const self) -> uint { self.length }
|
fn len(&const self) -> uint { self.length }
|
||||||
|
|
||||||
/// Return true if the map contains no elements
|
/// Return true if the map contains no elements
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_empty(&const self) -> bool { self.len() == 0 }
|
fn is_empty(&const self) -> bool { self.len() == 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Mutable for TrieMap<T> {
|
impl<T> Mutable for TrieMap<T> {
|
||||||
|
@ -69,19 +69,19 @@ impl<T> Mutable for TrieMap<T> {
|
||||||
impl<T> Map<uint, T> for TrieMap<T> {
|
impl<T> Map<uint, T> for TrieMap<T> {
|
||||||
/// Return true if the map contains a value for the specified key
|
/// Return true if the map contains a value for the specified key
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn contains_key(&self, key: &uint) -> bool {
|
fn contains_key(&self, key: &uint) -> bool {
|
||||||
self.find(key).is_some()
|
self.find(key).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all keys in order
|
/// Visit all keys in order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each_key(&self, f: &fn(&uint) -> bool) {
|
fn each_key(&self, f: &fn(&uint) -> bool) {
|
||||||
self.each(|&(k, _)| f(&k))
|
self.each(|&(k, _)| f(&k))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all values in order
|
/// Visit all values in order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each_value(&self, f: &fn(&T) -> bool) {
|
fn each_value(&self, f: &fn(&T) -> bool) {
|
||||||
self.each(|&(_, v)| f(v))
|
self.each(|&(_, v)| f(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||||
|
|
||||||
/// Return the value corresponding to the key in the map
|
/// Return the value corresponding to the key in the map
|
||||||
#[inline(hint)]
|
#[inline(hint)]
|
||||||
pure fn find(&self, key: &uint) -> Option<&'self T> {
|
fn find(&self, key: &uint) -> Option<&'self T> {
|
||||||
let mut node: &'self TrieNode<T> = &self.root;
|
let mut node: &'self TrieNode<T> = &self.root;
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
loop {
|
loop {
|
||||||
|
@ -139,19 +139,19 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||||
pub impl<T> TrieMap<T> {
|
pub impl<T> TrieMap<T> {
|
||||||
/// Create an empty TrieMap
|
/// Create an empty TrieMap
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn new() -> TrieMap<T> {
|
fn new() -> TrieMap<T> {
|
||||||
TrieMap{root: TrieNode::new(), length: 0}
|
TrieMap{root: TrieNode::new(), length: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all keys in reverse order
|
/// Visit all keys in reverse order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
|
fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
|
||||||
self.each_reverse(|&(k, _)| f(&k))
|
self.each_reverse(|&(k, _)| f(&k))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all values in reverse order
|
/// Visit all values in reverse order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn each_value_reverse(&self, f: &fn(&T) -> bool) {
|
fn each_value_reverse(&self, f: &fn(&T) -> bool) {
|
||||||
self.each_reverse(|&(_, v)| f(v))
|
self.each_reverse(|&(_, v)| f(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,13 +162,13 @@ pub struct TrieSet {
|
||||||
|
|
||||||
impl BaseIter<uint> for TrieSet {
|
impl BaseIter<uint> for TrieSet {
|
||||||
/// Visit all values in order
|
/// Visit all values in order
|
||||||
pure fn each(&self, f: &fn(&uint) -> bool) { self.map.each_key(f) }
|
fn each(&self, f: &fn(&uint) -> bool) { self.map.each_key(f) }
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReverseIter<uint> for TrieSet {
|
impl ReverseIter<uint> for TrieSet {
|
||||||
/// Visit all values in reverse order
|
/// Visit all values in reverse order
|
||||||
pure fn each_reverse(&self, f: &fn(&uint) -> bool) {
|
fn each_reverse(&self, f: &fn(&uint) -> bool) {
|
||||||
self.map.each_key_reverse(f)
|
self.map.each_key_reverse(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,11 +176,11 @@ impl ReverseIter<uint> for TrieSet {
|
||||||
impl Container for TrieSet {
|
impl Container for TrieSet {
|
||||||
/// Return the number of elements in the set
|
/// Return the number of elements in the set
|
||||||
#[inline(always)]
|
#[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
|
/// Return true if the set contains no elements
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_empty(&const self) -> bool { self.map.is_empty() }
|
fn is_empty(&const self) -> bool { self.map.is_empty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mutable for TrieSet {
|
impl Mutable for TrieSet {
|
||||||
|
@ -192,13 +192,13 @@ impl Mutable for TrieSet {
|
||||||
impl TrieSet {
|
impl TrieSet {
|
||||||
/// Create an empty TrieSet
|
/// Create an empty TrieSet
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn new() -> TrieSet {
|
fn new() -> TrieSet {
|
||||||
TrieSet{map: TrieMap::new()}
|
TrieSet{map: TrieMap::new()}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if the set contains a value
|
/// Return true if the set contains a value
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn contains(&self, value: &uint) -> bool {
|
fn contains(&self, value: &uint) -> bool {
|
||||||
self.map.contains_key(value)
|
self.map.contains_key(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ struct TrieNode<T> {
|
||||||
|
|
||||||
impl<T> TrieNode<T> {
|
impl<T> TrieNode<T> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn new() -> TrieNode<T> {
|
fn new() -> TrieNode<T> {
|
||||||
// FIXME: #5244: [Nothing, ..SIZE] should be possible without Copy
|
// FIXME: #5244: [Nothing, ..SIZE] should be possible without Copy
|
||||||
TrieNode{count: 0,
|
TrieNode{count: 0,
|
||||||
children: [Nothing, Nothing, Nothing, Nothing,
|
children: [Nothing, Nothing, Nothing, Nothing,
|
||||||
|
@ -231,7 +231,7 @@ impl<T> TrieNode<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> TrieNode<T> {
|
impl<T> TrieNode<T> {
|
||||||
pure fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
|
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
|
||||||
for uint::range(0, self.children.len()) |idx| {
|
for uint::range(0, self.children.len()) |idx| {
|
||||||
match self.children[idx] {
|
match self.children[idx] {
|
||||||
Internal(ref x) => if !x.each(f) { return false },
|
Internal(ref x) => if !x.each(f) { return false },
|
||||||
|
@ -242,7 +242,7 @@ impl<T> TrieNode<T> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
|
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
|
||||||
for uint::range_rev(self.children.len(), 0) |idx| {
|
for uint::range_rev(self.children.len(), 0) |idx| {
|
||||||
match self.children[idx - 1] {
|
match self.children[idx - 1] {
|
||||||
Internal(ref x) => if !x.each_reverse(f) { return false },
|
Internal(ref x) => if !x.each_reverse(f) { return false },
|
||||||
|
@ -269,7 +269,7 @@ impl<T> TrieNode<T> {
|
||||||
|
|
||||||
// if this was done via a trait, the key could be generic
|
// if this was done via a trait, the key could be generic
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn chunk(n: uint, idx: uint) -> uint {
|
fn chunk(n: uint, idx: uint) -> uint {
|
||||||
let sh = uint::bits - (SHIFT * (idx + 1));
|
let sh = uint::bits - (SHIFT * (idx + 1));
|
||||||
(n >> sh) & MASK
|
(n >> sh) & MASK
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,30 +16,30 @@ use vec;
|
||||||
#[cfg(notest)] use cmp::{Eq, Ord};
|
#[cfg(notest)] use cmp::{Eq, Ord};
|
||||||
|
|
||||||
pub trait CopyableTuple<T, U> {
|
pub trait CopyableTuple<T, U> {
|
||||||
pure fn first(&self) -> T;
|
fn first(&self) -> T;
|
||||||
pure fn second(&self) -> U;
|
fn second(&self) -> U;
|
||||||
pure fn swap(&self) -> (U, T);
|
fn swap(&self) -> (U, T);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
|
impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
|
||||||
|
|
||||||
/// Return the first element of self
|
/// Return the first element of self
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn first(&self) -> T {
|
fn first(&self) -> T {
|
||||||
let (t, _) = *self;
|
let (t, _) = *self;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the second element of self
|
/// Return the second element of self
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn second(&self) -> U {
|
fn second(&self) -> U {
|
||||||
let (_, u) = *self;
|
let (_, u) = *self;
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the results of swapping the two elements of self
|
/// Return the results of swapping the two elements of self
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn swap(&self) -> (U, T) {
|
fn swap(&self) -> (U, T) {
|
||||||
let (t, u) = *self;
|
let (t, u) = *self;
|
||||||
return (u, t);
|
return (u, t);
|
||||||
}
|
}
|
||||||
|
@ -47,19 +47,19 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ImmutableTuple<T, U> {
|
pub trait ImmutableTuple<T, U> {
|
||||||
pure fn first_ref(&self) -> &'self T;
|
fn first_ref(&self) -> &'self T;
|
||||||
pure fn second_ref(&self) -> &'self U;
|
fn second_ref(&self) -> &'self U;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn first_ref(&self) -> &'self T {
|
fn first_ref(&self) -> &'self T {
|
||||||
match *self {
|
match *self {
|
||||||
(ref t, _) => t,
|
(ref t, _) => t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn second_ref(&self) -> &'self U {
|
fn second_ref(&self) -> &'self U {
|
||||||
match *self {
|
match *self {
|
||||||
(_, ref u) => u,
|
(_, ref u) => u,
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<A:Eq,B:Eq> Eq for (A, B) {
|
impl<A:Eq,B:Eq> Eq for (A, B) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &(A, B)) -> bool {
|
fn eq(&self, other: &(A, B)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
(ref self_a, ref self_b) => match other {
|
(ref self_a, ref self_b) => match other {
|
||||||
&(ref other_a, ref other_b) => {
|
&(ref other_a, ref other_b) => {
|
||||||
|
@ -127,13 +127,13 @@ impl<A:Eq,B:Eq> Eq for (A, B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &(A, B)) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &(A, B)) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<A:Ord,B:Ord> Ord for (A, B) {
|
impl<A:Ord,B:Ord> Ord for (A, B) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &(A, B)) -> bool {
|
fn lt(&self, other: &(A, B)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
(ref self_a, ref self_b) => {
|
(ref self_a, ref self_b) => {
|
||||||
match (*other) {
|
match (*other) {
|
||||||
|
@ -148,17 +148,17 @@ impl<A:Ord,B:Ord> Ord for (A, B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &(A, B)) -> bool { !(*other).lt(&(*self)) }
|
fn le(&self, other: &(A, B)) -> bool { !(*other).lt(&(*self)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &(A, B)) -> bool { !(*self).lt(other) }
|
fn ge(&self, other: &(A, B)) -> bool { !(*self).lt(other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &(A, B)) -> bool { (*other).lt(&(*self)) }
|
fn gt(&self, other: &(A, B)) -> bool { (*other).lt(&(*self)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<A:Eq,B:Eq,C:Eq> Eq for (A, B, C) {
|
impl<A:Eq,B:Eq,C:Eq> Eq for (A, B, C) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn eq(&self, other: &(A, B, C)) -> bool {
|
fn eq(&self, other: &(A, B, C)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
(ref self_a, ref self_b, ref self_c) => match other {
|
(ref self_a, ref self_b, ref self_c) => match other {
|
||||||
&(ref other_a, ref other_b, ref other_c) => {
|
&(ref other_a, ref other_b, ref other_c) => {
|
||||||
|
@ -169,13 +169,13 @@ impl<A:Eq,B:Eq,C:Eq> Eq for (A, B, C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ne(&self, other: &(A, B, C)) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &(A, B, C)) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
|
impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &(A, B, C)) -> bool {
|
fn lt(&self, other: &(A, B, C)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
(ref self_a, ref self_b, ref self_c) => {
|
(ref self_a, ref self_b, ref self_c) => {
|
||||||
match (*other) {
|
match (*other) {
|
||||||
|
@ -192,11 +192,11 @@ impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn le(&self, other: &(A, B, C)) -> bool { !(*other).lt(&(*self)) }
|
fn le(&self, other: &(A, B, C)) -> bool { !(*other).lt(&(*self)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn ge(&self, other: &(A, B, C)) -> bool { !(*self).lt(other) }
|
fn ge(&self, other: &(A, B, C)) -> bool { !(*self).lt(other) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn gt(&self, other: &(A, B, C)) -> bool { (*other).lt(&(*self)) }
|
fn gt(&self, other: &(A, B, C)) -> bool { (*other).lt(&(*self)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#[doc(hidden)]; // FIXME #3538
|
#[doc(hidden)]; // FIXME #3538
|
||||||
|
|
||||||
pub mod general_category {
|
pub mod general_category {
|
||||||
pub pure fn Cc(c: char) -> bool {
|
pub fn Cc(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x00' .. '\x1f'
|
'\x00' .. '\x1f'
|
||||||
| '\x7f' .. '\x9f' => true,
|
| '\x7f' .. '\x9f' => true,
|
||||||
|
@ -19,7 +19,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Cf(c: char) -> bool {
|
pub fn Cf(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\xad'
|
'\xad'
|
||||||
| '\u0600' .. '\u0603'
|
| '\u0600' .. '\u0603'
|
||||||
|
@ -38,21 +38,21 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Co(c: char) -> bool {
|
pub fn Co(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\ue000' .. '\uf8ff' => true,
|
'\ue000' .. '\uf8ff' => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Cs(c: char) -> bool {
|
pub fn Cs(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\ud800' .. '\udfff' => true,
|
'\ud800' .. '\udfff' => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Ll(c: char) -> bool {
|
pub fn Ll(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x61' .. '\x7a'
|
'\x61' .. '\x7a'
|
||||||
| '\xaa'
|
| '\xaa'
|
||||||
|
@ -657,7 +657,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Lm(c: char) -> bool {
|
pub fn Lm(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u02b0' .. '\u02c1'
|
'\u02b0' .. '\u02c1'
|
||||||
| '\u02c6' .. '\u02d1'
|
| '\u02c6' .. '\u02d1'
|
||||||
|
@ -713,7 +713,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Lo(c: char) -> bool {
|
pub fn Lo(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u01bb'
|
'\u01bb'
|
||||||
| '\u01c0' .. '\u01c3'
|
| '\u01c0' .. '\u01c3'
|
||||||
|
@ -899,7 +899,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Lt(c: char) -> bool {
|
pub fn Lt(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u01c5'
|
'\u01c5'
|
||||||
| '\u01c8'
|
| '\u01c8'
|
||||||
|
@ -916,7 +916,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Lu(c: char) -> bool {
|
pub fn Lu(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x41' .. '\x5a'
|
'\x41' .. '\x5a'
|
||||||
| '\xc0' .. '\xd6'
|
| '\xc0' .. '\xd6'
|
||||||
|
@ -1508,7 +1508,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Mc(c: char) -> bool {
|
pub fn Mc(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u0903'
|
'\u0903'
|
||||||
| '\u093b'
|
| '\u093b'
|
||||||
|
@ -1619,7 +1619,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Me(c: char) -> bool {
|
pub fn Me(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u0488' .. '\u0489'
|
'\u0488' .. '\u0489'
|
||||||
| '\u20dd' .. '\u20e0'
|
| '\u20dd' .. '\u20e0'
|
||||||
|
@ -1630,7 +1630,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Mn(c: char) -> bool {
|
pub fn Mn(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u0300' .. '\u036f'
|
'\u0300' .. '\u036f'
|
||||||
| '\u0483' .. '\u0487'
|
| '\u0483' .. '\u0487'
|
||||||
|
@ -1823,7 +1823,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Nd(c: char) -> bool {
|
pub fn Nd(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x30' .. '\x39'
|
'\x30' .. '\x39'
|
||||||
| '\u0660' .. '\u0669'
|
| '\u0660' .. '\u0669'
|
||||||
|
@ -1867,7 +1867,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Nl(c: char) -> bool {
|
pub fn Nl(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u16ee' .. '\u16f0'
|
'\u16ee' .. '\u16f0'
|
||||||
| '\u2160' .. '\u2182'
|
| '\u2160' .. '\u2182'
|
||||||
|
@ -1886,7 +1886,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn No(c: char) -> bool {
|
pub fn No(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\xb2' .. '\xb3'
|
'\xb2' .. '\xb3'
|
||||||
| '\xb9'
|
| '\xb9'
|
||||||
|
@ -1934,7 +1934,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Pc(c: char) -> bool {
|
pub fn Pc(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x5f'
|
'\x5f'
|
||||||
| '\u203f' .. '\u2040'
|
| '\u203f' .. '\u2040'
|
||||||
|
@ -1947,7 +1947,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Pd(c: char) -> bool {
|
pub fn Pd(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x2d'
|
'\x2d'
|
||||||
| '\u058a'
|
| '\u058a'
|
||||||
|
@ -1969,7 +1969,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Pe(c: char) -> bool {
|
pub fn Pe(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x29'
|
'\x29'
|
||||||
| '\x5d'
|
| '\x5d'
|
||||||
|
@ -2046,7 +2046,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Pf(c: char) -> bool {
|
pub fn Pf(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\xbb'
|
'\xbb'
|
||||||
| '\u2019'
|
| '\u2019'
|
||||||
|
@ -2063,7 +2063,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Pi(c: char) -> bool {
|
pub fn Pi(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\xab'
|
'\xab'
|
||||||
| '\u2018'
|
| '\u2018'
|
||||||
|
@ -2081,7 +2081,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Po(c: char) -> bool {
|
pub fn Po(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x21' .. '\x23'
|
'\x21' .. '\x23'
|
||||||
| '\x25' .. '\x27'
|
| '\x25' .. '\x27'
|
||||||
|
@ -2214,7 +2214,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Ps(c: char) -> bool {
|
pub fn Ps(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x28'
|
'\x28'
|
||||||
| '\x5b'
|
| '\x5b'
|
||||||
|
@ -2293,7 +2293,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Sc(c: char) -> bool {
|
pub fn Sc(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x24'
|
'\x24'
|
||||||
| '\xa2' .. '\xa5'
|
| '\xa2' .. '\xa5'
|
||||||
|
@ -2316,7 +2316,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Sk(c: char) -> bool {
|
pub fn Sk(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x5e'
|
'\x5e'
|
||||||
| '\x60'
|
| '\x60'
|
||||||
|
@ -2350,7 +2350,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Sm(c: char) -> bool {
|
pub fn Sm(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x2b'
|
'\x2b'
|
||||||
| '\x3c' .. '\x3e'
|
| '\x3c' .. '\x3e'
|
||||||
|
@ -2421,7 +2421,7 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn So(c: char) -> bool {
|
pub fn So(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\xa6' .. '\xa7'
|
'\xa6' .. '\xa7'
|
||||||
| '\xa9'
|
| '\xa9'
|
||||||
|
@ -2540,21 +2540,21 @@ pub mod general_category {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Zl(c: char) -> bool {
|
pub fn Zl(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u2028' => true,
|
'\u2028' => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Zp(c: char) -> bool {
|
pub fn Zp(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\u2029' => true,
|
'\u2029' => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn Zs(c: char) -> bool {
|
pub fn Zs(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x20'
|
'\x20'
|
||||||
| '\xa0'
|
| '\xa0'
|
||||||
|
@ -2572,7 +2572,7 @@ pub mod general_category {
|
||||||
}
|
}
|
||||||
mod derived_property {
|
mod derived_property {
|
||||||
/// Check if a character has the alphabetic unicode property
|
/// Check if a character has the alphabetic unicode property
|
||||||
pub pure fn Alphabetic(c: char) -> bool {
|
pub fn Alphabetic(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x41' .. '\x5a'
|
'\x41' .. '\x5a'
|
||||||
| '\x61' .. '\x7a'
|
| '\x61' .. '\x7a'
|
||||||
|
@ -3310,7 +3310,7 @@ mod derived_property {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn XID_Continue(c: char) -> bool {
|
pub fn XID_Continue(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x30' .. '\x39'
|
'\x30' .. '\x39'
|
||||||
| '\x41' .. '\x5a'
|
| '\x41' .. '\x5a'
|
||||||
|
@ -4181,7 +4181,7 @@ mod derived_property {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn XID_Start(c: char) -> bool {
|
pub fn XID_Start(c: char) -> bool {
|
||||||
return match c {
|
return match c {
|
||||||
'\x41' .. '\x5a'
|
'\x41' .. '\x5a'
|
||||||
| '\x61' .. '\x7a'
|
| '\x61' .. '\x7a'
|
||||||
|
|
|
@ -140,7 +140,7 @@ pub mod ct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T> Parsed<T> {
|
pub impl<T> Parsed<T> {
|
||||||
pure fn new(val: T, next: uint) -> Parsed<T> {
|
fn new(val: T, next: uint) -> Parsed<T> {
|
||||||
Parsed {val: val, next: next}
|
Parsed {val: val, next: next}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -496,7 +496,7 @@ pub mod rt {
|
||||||
ty: Ty,
|
ty: Ty,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn conv_int(cv: Conv, i: int) -> ~str {
|
pub fn conv_int(cv: Conv, i: int) -> ~str {
|
||||||
let radix = 10;
|
let radix = 10;
|
||||||
let prec = get_int_precision(cv);
|
let prec = get_int_precision(cv);
|
||||||
let mut s : ~str = int_to_str_prec(i, radix, prec);
|
let mut s : ~str = int_to_str_prec(i, radix, prec);
|
||||||
|
@ -509,7 +509,7 @@ pub mod rt {
|
||||||
}
|
}
|
||||||
return unsafe { pad(cv, s, PadSigned) };
|
return unsafe { pad(cv, s, PadSigned) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
|
pub fn conv_uint(cv: Conv, u: uint) -> ~str {
|
||||||
let prec = get_int_precision(cv);
|
let prec = get_int_precision(cv);
|
||||||
let mut rs =
|
let mut rs =
|
||||||
match cv.ty {
|
match cv.ty {
|
||||||
|
@ -521,17 +521,17 @@ pub mod rt {
|
||||||
};
|
};
|
||||||
return unsafe { pad(cv, rs, PadUnsigned) };
|
return unsafe { pad(cv, rs, PadUnsigned) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
|
pub fn conv_bool(cv: Conv, b: bool) -> ~str {
|
||||||
let s = if b { ~"true" } else { ~"false" };
|
let s = if b { ~"true" } else { ~"false" };
|
||||||
// run the boolean conversion through the string conversion logic,
|
// run the boolean conversion through the string conversion logic,
|
||||||
// giving it the same rules for precision, etc.
|
// giving it the same rules for precision, etc.
|
||||||
return conv_str(cv, s);
|
return conv_str(cv, s);
|
||||||
}
|
}
|
||||||
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
|
pub fn conv_char(cv: Conv, c: char) -> ~str {
|
||||||
let mut s = str::from_char(c);
|
let mut s = str::from_char(c);
|
||||||
return unsafe { pad(cv, s, PadNozero) };
|
return unsafe { pad(cv, s, PadNozero) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
|
pub fn conv_str(cv: Conv, s: &str) -> ~str {
|
||||||
// For strings, precision is the maximum characters
|
// For strings, precision is the maximum characters
|
||||||
// displayed
|
// displayed
|
||||||
let mut unpadded = match cv.precision {
|
let mut unpadded = match cv.precision {
|
||||||
|
@ -544,7 +544,7 @@ pub mod rt {
|
||||||
};
|
};
|
||||||
return unsafe { pad(cv, unpadded, PadNozero) };
|
return unsafe { pad(cv, unpadded, PadNozero) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
|
pub fn conv_float(cv: Conv, f: float) -> ~str {
|
||||||
let (to_str, digits) = match cv.precision {
|
let (to_str, digits) = match cv.precision {
|
||||||
CountIs(c) => (float::to_str_exact, c as uint),
|
CountIs(c) => (float::to_str_exact, c as uint),
|
||||||
CountImplied => (float::to_str_digits, 6u)
|
CountImplied => (float::to_str_digits, 6u)
|
||||||
|
@ -559,14 +559,14 @@ pub mod rt {
|
||||||
}
|
}
|
||||||
return unsafe { pad(cv, s, PadFloat) };
|
return unsafe { pad(cv, s, PadFloat) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
|
pub fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
|
||||||
let s = sys::log_str(v);
|
let s = sys::log_str(v);
|
||||||
return conv_str(cv, s);
|
return conv_str(cv, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert an int to string with minimum number of digits. If precision is
|
// Convert an int to string with minimum number of digits. If precision is
|
||||||
// 0 and num is 0 then the result is the empty string.
|
// 0 and num is 0 then the result is the empty string.
|
||||||
pub pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
|
pub fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
|
||||||
return if num < 0 {
|
return if num < 0 {
|
||||||
~"-" + uint_to_str_prec(-num as uint, radix, prec)
|
~"-" + uint_to_str_prec(-num as uint, radix, prec)
|
||||||
} else { uint_to_str_prec(num as uint, radix, prec) };
|
} else { uint_to_str_prec(num as uint, radix, prec) };
|
||||||
|
@ -575,7 +575,7 @@ pub mod rt {
|
||||||
// Convert a uint to string with a minimum number of digits. If precision
|
// Convert a uint to string with a minimum number of digits. If precision
|
||||||
// is 0 and num is 0 then the result is the empty string. Could move this
|
// is 0 and num is 0 then the result is the empty string. Could move this
|
||||||
// to uint: but it doesn't seem all that useful.
|
// to uint: but it doesn't seem all that useful.
|
||||||
pub pure fn uint_to_str_prec(num: uint, radix: uint,
|
pub fn uint_to_str_prec(num: uint, radix: uint,
|
||||||
prec: uint) -> ~str {
|
prec: uint) -> ~str {
|
||||||
return if prec == 0u && num == 0u {
|
return if prec == 0u && num == 0u {
|
||||||
~""
|
~""
|
||||||
|
@ -589,7 +589,7 @@ pub mod rt {
|
||||||
} else { s }
|
} else { s }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub pure fn get_int_precision(cv: Conv) -> uint {
|
pub fn get_int_precision(cv: Conv) -> uint {
|
||||||
return match cv.precision {
|
return match cv.precision {
|
||||||
CountIs(c) => c as uint,
|
CountIs(c) => c as uint,
|
||||||
CountImplied => 1u
|
CountImplied => 1u
|
||||||
|
@ -619,7 +619,7 @@ pub mod rt {
|
||||||
PadFloat => (true, true),
|
PadFloat => (true, true),
|
||||||
PadUnsigned => (true, false)
|
PadUnsigned => (true, false)
|
||||||
};
|
};
|
||||||
pure fn have_precision(cv: Conv) -> bool {
|
fn have_precision(cv: Conv) -> bool {
|
||||||
return match cv.precision { CountImplied => false, _ => true };
|
return match cv.precision { CountImplied => false, _ => true };
|
||||||
}
|
}
|
||||||
let zero_padding = {
|
let zero_padding = {
|
||||||
|
@ -649,7 +649,7 @@ pub mod rt {
|
||||||
}
|
}
|
||||||
return padstr + s;
|
return padstr + s;
|
||||||
}
|
}
|
||||||
pub pure fn have_flag(flags: u32, f: u32) -> bool {
|
pub fn have_flag(flags: u32, f: u32) -> bool {
|
||||||
flags & f != 0
|
flags & f != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,11 @@ use prelude::*;
|
||||||
|
|
||||||
/// The identity function.
|
/// The identity function.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn id<T>(x: T) -> T { x }
|
pub fn id<T>(x: T) -> T { x }
|
||||||
|
|
||||||
/// Ignores a value.
|
/// Ignores a value.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn ignore<T>(_x: T) { }
|
pub fn ignore<T>(_x: T) { }
|
||||||
|
|
||||||
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
||||||
/// original value of `*ptr`.
|
/// original value of `*ptr`.
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue