librustc: Separate most trait bounds with '+'. rs=plussing
This commit is contained in:
parent
a307608781
commit
bf2a225c0b
204 changed files with 729 additions and 726 deletions
|
@ -101,7 +101,7 @@ pub pure fn build_sized_opt<A>(size: Option<uint>,
|
||||||
|
|
||||||
// Appending
|
// Appending
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
|
pub pure 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]); }
|
||||||
|
@ -137,7 +137,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 pure 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; }
|
||||||
|
@ -173,7 +173,7 @@ pub mod traits {
|
||||||
use kinds::Copy;
|
use kinds::Copy;
|
||||||
use ops::Add;
|
use ops::Add;
|
||||||
|
|
||||||
pub impl<T: Copy> Add<&[const T],@[T]> for @[T] {
|
pub impl<T:Copy> Add<&[const T],@[T]> for @[T] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn add(&self, rhs: & &self/[const T]) -> @[T] {
|
pure fn add(&self, rhs: & &self/[const T]) -> @[T] {
|
||||||
append(*self, (*rhs))
|
append(*self, (*rhs))
|
||||||
|
|
|
@ -56,41 +56,41 @@ pub trait Ord {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn lt<T: Ord>(v1: &T, v2: &T) -> bool {
|
pub pure 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 pure 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 pure 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 pure 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 pure 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 pure fn gt<T:Ord>(v1: &T, v2: &T) -> bool {
|
||||||
(*v1).gt(v2)
|
(*v1).gt(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn min<T: Ord>(v1: T, v2: T) -> T {
|
pub pure 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 pure fn max<T:Ord>(v1: T, v2: T) -> T {
|
||||||
if v1 > v2 { v1 } else { v2 }
|
if v1 > v2 { v1 } else { v2 }
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ pub pure fn from_elem<T>(data: T) -> @mut DList<T> {
|
||||||
list
|
list
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_vec<T: Copy>(vec: &[T]) -> @mut DList<T> {
|
pub fn from_vec<T:Copy>(vec: &[T]) -> @mut DList<T> {
|
||||||
do vec::foldl(DList(), vec) |list,data| {
|
do vec::foldl(DList(), vec) |list,data| {
|
||||||
list.push(*data); // Iterating left-to-right -- add newly to the tail.
|
list.push(*data); // Iterating left-to-right -- add newly to the tail.
|
||||||
list
|
list
|
||||||
|
@ -457,7 +457,7 @@ impl<T> DList<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> DList<T> {
|
impl<T:Copy> DList<T> {
|
||||||
/// Remove data from the head of the list. O(1).
|
/// Remove data from the head of the list. O(1).
|
||||||
fn pop(@mut self) -> Option<T> {
|
fn pop(@mut self) -> Option<T> {
|
||||||
self.pop_n().map(|nobe| nobe.data)
|
self.pop_n().map(|nobe| nobe.data)
|
||||||
|
|
|
@ -227,7 +227,7 @@ impl<A> DVec<A> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy> DVec<A> {
|
impl<A:Copy> DVec<A> {
|
||||||
/**
|
/**
|
||||||
* Append all elements of a vector to the end of the list
|
* Append all elements of a vector to the end of the list
|
||||||
*
|
*
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub fn either<T, U, V>(f_left: fn(&T) -> V,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
|
pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] {
|
||||||
//! Extracts from a vector of either all the left values
|
//! Extracts from a vector of either all the left values
|
||||||
|
|
||||||
do vec::build_sized(eithers.len()) |push| {
|
do vec::build_sized(eithers.len()) |push| {
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub trait HashUtil {
|
||||||
pure fn hash() -> u64;
|
pure fn hash() -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Hash> HashUtil for A {
|
impl<A:Hash> HashUtil for A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn hash() -> u64 { self.hash_keyed(0,0) }
|
pure fn hash() -> u64 { self.hash_keyed(0,0) }
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ pub trait Streaming {
|
||||||
fn reset();
|
fn reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: IterBytes> Hash for A {
|
impl<A:IterBytes> Hash for A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn hash_keyed(k0: u64, k1: u64) -> u64 {
|
pure fn hash_keyed(k0: u64, k1: u64) -> u64 {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -56,14 +56,14 @@ pub mod linear {
|
||||||
((capacity as float) * 3. / 4.) as uint
|
((capacity as float) * 3. / 4.) as uint
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn linear_map_with_capacity<K: Eq Hash, V>(
|
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
|
||||||
initial_capacity: uint) -> LinearMap<K, V> {
|
initial_capacity: uint) -> LinearMap<K, V> {
|
||||||
let r = rand::task_rng();
|
let r = rand::task_rng();
|
||||||
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
|
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
|
||||||
initial_capacity)
|
initial_capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn linear_map_with_capacity_and_keys<K: Eq Hash, V>(
|
pure 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 {
|
||||||
|
@ -74,7 +74,7 @@ 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 {
|
pure 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
|
||||||
|
@ -246,7 +246,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Hash IterBytes Eq, V> BaseIter<(&K, &V)> for LinearMap<K, V> {
|
impl<K:Hash + IterBytes + Eq,V> BaseIter<(&K, &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) {
|
pure 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| {
|
||||||
|
@ -263,7 +263,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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(&self) -> uint { self.size }
|
pure fn len(&self) -> uint { self.size }
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ pub mod linear {
|
||||||
pure fn is_empty(&self) -> bool { self.len() == 0 }
|
pure fn is_empty(&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> {
|
||||||
/// Clear the map, removing all key-value pairs.
|
/// Clear the map, removing all key-value pairs.
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
for uint::range(0, self.buckets.len()) |idx| {
|
for uint::range(0, self.buckets.len()) |idx| {
|
||||||
|
@ -281,7 +281,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 {
|
pure fn contains_key(&self, k: &K) -> bool {
|
||||||
match self.bucket_for_key(k) {
|
match self.bucket_for_key(k) {
|
||||||
|
@ -333,7 +333,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<K:Hash IterBytes Eq, V> LinearMap<K, V> {
|
pub impl<K:Hash + IterBytes + Eq,V> LinearMap<K, V> {
|
||||||
/// Create an empty LinearMap
|
/// Create an empty LinearMap
|
||||||
static fn new() -> LinearMap<K, V> {
|
static fn new() -> LinearMap<K, V> {
|
||||||
linear_map_with_capacity(INITIAL_CAPACITY)
|
linear_map_with_capacity(INITIAL_CAPACITY)
|
||||||
|
@ -457,7 +457,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 {
|
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
|
||||||
if self.len() != other.len() { return false; }
|
if self.len() != other.len() { return false; }
|
||||||
|
|
||||||
|
@ -478,13 +478,13 @@ pub mod linear {
|
||||||
priv map: LinearMap<T, ()>
|
priv map: LinearMap<T, ()>
|
||||||
}
|
}
|
||||||
|
|
||||||
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) }
|
pure fn each(&self, f: fn(&T) -> bool) { self.map.each_key(f) }
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
pure 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 {
|
pure fn eq(&self, other: &LinearSet<T>) -> bool {
|
||||||
self.map == other.map
|
self.map == other.map
|
||||||
}
|
}
|
||||||
|
@ -493,7 +493,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(&self) -> uint { self.map.len() }
|
pure fn len(&self) -> uint { self.map.len() }
|
||||||
|
|
||||||
|
@ -501,12 +501,12 @@ pub mod linear {
|
||||||
pure fn is_empty(&self) -> bool { self.map.is_empty() }
|
pure fn is_empty(&self) -> bool { self.map.is_empty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Hash IterBytes Eq> Mutable for LinearSet<T> {
|
impl<T:Hash + IterBytes + Eq> Mutable for LinearSet<T> {
|
||||||
/// Clear the set, removing all values.
|
/// Clear the set, removing all values.
|
||||||
fn clear(&mut self) { self.map.clear() }
|
fn clear(&mut self) { self.map.clear() }
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
pure fn contains(&self, value: &T) -> bool {
|
||||||
self.map.contains_key(value)
|
self.map.contains_key(value)
|
||||||
|
@ -575,7 +575,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl <T: Hash IterBytes Eq> LinearSet<T> {
|
pub impl <T:Hash + IterBytes + Eq> LinearSet<T> {
|
||||||
/// Create an empty LinearSet
|
/// Create an empty LinearSet
|
||||||
static fn new() -> LinearSet<T> { LinearSet{map: LinearMap::new()} }
|
static fn new() -> LinearSet<T> { LinearSet{map: LinearMap::new()} }
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ pub trait ReaderUtil {
|
||||||
fn read_i8(&self) -> i8;
|
fn read_i8(&self) -> i8;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Reader> ReaderUtil for T {
|
impl<T:Reader> ReaderUtil for T {
|
||||||
|
|
||||||
fn read_bytes(&self,len: uint) -> ~[u8] {
|
fn read_bytes(&self,len: uint) -> ~[u8] {
|
||||||
let mut bytes = vec::with_capacity(len);
|
let mut bytes = vec::with_capacity(len);
|
||||||
|
@ -193,7 +193,7 @@ impl<T: Reader> ReaderUtil for T {
|
||||||
|
|
||||||
fn read_chars(&self, n: uint) -> ~[char] {
|
fn read_chars(&self, n: uint) -> ~[char] {
|
||||||
// returns the (consumed offset, n_req), appends characters to &chars
|
// returns the (consumed offset, n_req), appends characters to &chars
|
||||||
fn chars_from_bytes<T: Reader>(bytes: &~[u8], chars: &mut ~[char])
|
fn chars_from_bytes<T:Reader>(bytes: &~[u8], chars: &mut ~[char])
|
||||||
-> (uint, uint) {
|
-> (uint, uint) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let bytes_len = bytes.len();
|
let bytes_len = bytes.len();
|
||||||
|
@ -460,7 +460,7 @@ struct Wrapper<T, C> {
|
||||||
// A forwarding impl of reader that also holds on to a resource for the
|
// A forwarding impl of reader that also holds on to a resource for the
|
||||||
// duration of its lifetime.
|
// duration of its lifetime.
|
||||||
// FIXME there really should be a better way to do this // #2004
|
// FIXME there really should be a better way to do this // #2004
|
||||||
impl<R: Reader, C> Reader for Wrapper<R, C> {
|
impl<R:Reader,C> Reader for Wrapper<R, C> {
|
||||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
||||||
self.base.read(bytes, len)
|
self.base.read(bytes, len)
|
||||||
}
|
}
|
||||||
|
@ -589,7 +589,7 @@ pub trait Writer {
|
||||||
fn get_type(&self) -> WriterType;
|
fn get_type(&self) -> WriterType;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: Writer, C> Writer for Wrapper<W, C> {
|
impl<W:Writer,C> Writer for Wrapper<W, C> {
|
||||||
fn write(&self, bs: &[const u8]) { self.base.write(bs); }
|
fn write(&self, bs: &[const u8]) { self.base.write(bs); }
|
||||||
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
|
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
|
||||||
fn tell(&self) -> uint { self.base.tell() }
|
fn tell(&self) -> uint { self.base.tell() }
|
||||||
|
@ -890,7 +890,7 @@ pub trait WriterUtil {
|
||||||
fn write_i8(&self, n: i8);
|
fn write_i8(&self, n: i8);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Writer> WriterUtil for T {
|
impl<T:Writer> WriterUtil for T {
|
||||||
fn write_char(&self, ch: char) {
|
fn write_char(&self, ch: char) {
|
||||||
if ch as uint < 128u {
|
if ch as uint < 128u {
|
||||||
self.write(&[ch as u8]);
|
self.write(&[ch as u8]);
|
||||||
|
@ -1112,7 +1112,7 @@ pub mod fsync {
|
||||||
arg: Arg<t>,
|
arg: Arg<t>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> Drop for Res<T> {
|
impl<T:Copy> Drop for Res<T> {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
match self.arg.opt_level {
|
match self.arg.opt_level {
|
||||||
None => (),
|
None => (),
|
||||||
|
|
|
@ -60,14 +60,14 @@ impl<A> iter::ExtendedIter<A> for IMPL_T<A> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Eq> iter::EqIter<A> for IMPL_T<A> {
|
impl<A:Eq> iter::EqIter<A> for IMPL_T<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy> iter::CopyableIter<A> for IMPL_T<A> {
|
impl<A:Copy> iter::CopyableIter<A> for IMPL_T<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
||||||
iter::filter_to_vec(self, pred)
|
iter::filter_to_vec(self, pred)
|
||||||
|
@ -80,7 +80,7 @@ impl<A: Copy> iter::CopyableIter<A> for IMPL_T<A> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy Ord> iter::CopyableOrderedIter<A> for IMPL_T<A> {
|
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for IMPL_T<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn min(&self) -> A { iter::min(self) }
|
pure fn min(&self) -> A { iter::min(self) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub trait CopyableIter<A:Copy> {
|
||||||
pure fn find(&self, p: fn(&A) -> bool) -> Option<A>;
|
pure 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;
|
pure fn min(&self) -> A;
|
||||||
pure fn max(&self) -> A;
|
pure fn max(&self) -> A;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,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 pure 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 => {
|
||||||
|
@ -226,7 +226,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 pure 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 => {
|
||||||
|
@ -241,7 +241,7 @@ 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 pure fn find<A:Copy,IA:BaseIter<A>>(self: &IA,
|
||||||
f: fn(&A) -> bool) -> Option<A> {
|
f: fn(&A) -> bool) -> Option<A> {
|
||||||
for self.each |i| {
|
for self.each |i| {
|
||||||
if f(i) { return Some(*i) }
|
if f(i) { return Some(*i) }
|
||||||
|
@ -323,7 +323,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 pure 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;
|
||||||
|
@ -333,7 +333,7 @@ pub pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint,
|
||||||
|
|
||||||
/// Appending two generic sequences
|
/// Appending two generic sequences
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
pub pure fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(
|
||||||
lhs: &IT, rhs: &IT) -> BT {
|
lhs: &IT, rhs: &IT) -> 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));
|
||||||
|
@ -346,7 +346,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 pure 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); }
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub enum RoundMode {
|
||||||
* ~~~
|
* ~~~
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn cast<T:NumCast, U:NumCast>(n: T) -> U {
|
pub pure fn cast<T:NumCast,U:NumCast>(n: T) -> U {
|
||||||
NumCast::from(n)
|
NumCast::from(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub impl<T:Ord> Ord for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get<T: Copy>(opt: Option<T>) -> T {
|
pub pure fn get<T:Copy>(opt: Option<T>) -> T {
|
||||||
/*!
|
/*!
|
||||||
Gets the value out of an option
|
Gets the value out of an option
|
||||||
|
|
||||||
|
@ -207,14 +207,14 @@ pub pure fn is_some<T>(opt: &Option<T>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn get_or_zero<T: Copy Zero>(opt: Option<T>) -> T {
|
pub pure 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 pure 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 }
|
||||||
|
@ -393,7 +393,7 @@ impl<T> Option<T> {
|
||||||
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
|
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> Option<T> {
|
impl<T:Copy> Option<T> {
|
||||||
/**
|
/**
|
||||||
Gets the value out of an option
|
Gets the value out of an option
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ impl<T: Copy> Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy Zero> Option<T> {
|
impl<T:Copy + Zero> Option<T> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get_or_zero(self) -> T { get_or_zero(self) }
|
pure fn get_or_zero(self) -> T { get_or_zero(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ impl PacketHeader {
|
||||||
reinterpret_cast(&self.buffer)
|
reinterpret_cast(&self.buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_buffer<T: Owned>(b: ~Buffer<T>) {
|
fn set_buffer<T:Owned>(b: ~Buffer<T>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.buffer = reinterpret_cast(&b);
|
self.buffer = reinterpret_cast(&b);
|
||||||
}
|
}
|
||||||
|
@ -207,14 +207,14 @@ pub trait HasBuffer {
|
||||||
fn set_buffer(b: *libc::c_void);
|
fn set_buffer(b: *libc::c_void);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> HasBuffer for Packet<T> {
|
impl<T:Owned> HasBuffer for Packet<T> {
|
||||||
fn set_buffer(b: *libc::c_void) {
|
fn set_buffer(b: *libc::c_void) {
|
||||||
self.header.buffer = b;
|
self.header.buffer = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn mk_packet<T: Owned>() -> Packet<T> {
|
pub fn mk_packet<T:Owned>() -> Packet<T> {
|
||||||
Packet {
|
Packet {
|
||||||
header: PacketHeader(),
|
header: PacketHeader(),
|
||||||
payload: None,
|
payload: None,
|
||||||
|
@ -246,7 +246,7 @@ pub fn packet<T>() -> *Packet<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn entangle_buffer<T: Owned, Tstart: Owned>(
|
pub fn entangle_buffer<T:Owned,Tstart:Owned>(
|
||||||
buffer: ~Buffer<T>,
|
buffer: ~Buffer<T>,
|
||||||
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
|
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
|
||||||
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
||||||
|
@ -432,7 +432,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
|
||||||
Fails if the sender closes the connection.
|
Fails if the sender closes the connection.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
pub fn recv<T: Owned, Tbuffer: Owned>(
|
pub fn recv<T:Owned,Tbuffer:Owned>(
|
||||||
p: RecvPacketBuffered<T, Tbuffer>) -> T {
|
p: RecvPacketBuffered<T, Tbuffer>) -> T {
|
||||||
try_recv(p).expect("connection closed")
|
try_recv(p).expect("connection closed")
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ Returns `None` if the sender has closed the connection without sending
|
||||||
a message, or `Some(T)` if a message was received.
|
a message, or `Some(T)` if a message was received.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
||||||
-> Option<T>
|
-> Option<T>
|
||||||
{
|
{
|
||||||
let p_ = p.unwrap();
|
let p_ = p.unwrap();
|
||||||
|
@ -553,7 +553,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 pure 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"),
|
||||||
|
@ -561,14 +561,14 @@ pub pure fn peek<T: Owned, Tb: Owned>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, Tb: Owned> Peekable<T> for RecvPacketBuffered<T, Tb> {
|
impl<T:Owned,Tb:Owned> Peekable<T> for RecvPacketBuffered<T, Tb> {
|
||||||
pure fn peek() -> bool {
|
pure fn peek() -> bool {
|
||||||
peek(&self)
|
peek(&self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn sender_terminate<T: Owned>(p: *Packet<T>) {
|
fn sender_terminate<T:Owned>(p: *Packet<T>) {
|
||||||
let p = unsafe { &*p };
|
let p = unsafe { &*p };
|
||||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||||
Empty => {
|
Empty => {
|
||||||
|
@ -599,7 +599,7 @@ fn sender_terminate<T: Owned>(p: *Packet<T>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn receiver_terminate<T: Owned>(p: *Packet<T>) {
|
fn receiver_terminate<T:Owned>(p: *Packet<T>) {
|
||||||
let p = unsafe { &*p };
|
let p = unsafe { &*p };
|
||||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||||
Empty => {
|
Empty => {
|
||||||
|
@ -632,7 +632,7 @@ that vector. The index points to an endpoint that has either been
|
||||||
closed by the sender or has a message waiting to be received.
|
closed by the sender or has a message waiting to be received.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
fn wait_many<T: Selectable>(pkts: &[T]) -> uint {
|
fn wait_many<T:Selectable>(pkts: &[T]) -> uint {
|
||||||
let this = unsafe { rustrt::rust_get_task() };
|
let this = unsafe { rustrt::rust_get_task() };
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -714,7 +714,7 @@ Sometimes messages will be available on both endpoints at once. In
|
||||||
this case, `select2` may return either `left` or `right`.
|
this case, `select2` may return either `left` or `right`.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
pub fn select2<A: Owned, Ab: Owned, B: Owned, Bb: Owned>(
|
pub fn select2<A:Owned,Ab:Owned,B:Owned,Bb:Owned>(
|
||||||
a: RecvPacketBuffered<A, Ab>,
|
a: RecvPacketBuffered<A, Ab>,
|
||||||
b: RecvPacketBuffered<B, Bb>)
|
b: RecvPacketBuffered<B, Bb>)
|
||||||
-> Either<(Option<A>, RecvPacketBuffered<B, Bb>),
|
-> Either<(Option<A>, RecvPacketBuffered<B, Bb>),
|
||||||
|
@ -739,12 +739,12 @@ impl Selectable for *PacketHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the index of an endpoint that is ready to receive.
|
/// Returns the index of an endpoint that is ready to receive.
|
||||||
pub fn selecti<T: Selectable>(endpoints: &[T]) -> uint {
|
pub fn selecti<T:Selectable>(endpoints: &[T]) -> uint {
|
||||||
wait_many(endpoints)
|
wait_many(endpoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns 0 or 1 depending on which endpoint is ready to receive
|
/// Returns 0 or 1 depending on which endpoint is ready to receive
|
||||||
pub fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) ->
|
pub fn select2i<A:Selectable,B:Selectable>(a: &A, b: &B) ->
|
||||||
Either<(), ()> {
|
Either<(), ()> {
|
||||||
match wait_many([a.header(), b.header()]) {
|
match wait_many([a.header(), b.header()]) {
|
||||||
0 => Left(()),
|
0 => Left(()),
|
||||||
|
@ -757,7 +757,7 @@ pub fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) ->
|
||||||
list of the remaining endpoints.
|
list of the remaining endpoints.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
pub fn select<T: Owned, Tb: Owned>(endpoints: ~[RecvPacketBuffered<T, Tb>])
|
pub fn select<T:Owned,Tb:Owned>(endpoints: ~[RecvPacketBuffered<T, Tb>])
|
||||||
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
|
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
|
||||||
{
|
{
|
||||||
let ready = wait_many(endpoints.map(|p| p.header()));
|
let ready = wait_many(endpoints.map(|p| p.header()));
|
||||||
|
@ -852,7 +852,7 @@ pub struct RecvPacketBuffered<T, Tbuffer> {
|
||||||
mut buffer: Option<BufferResource<Tbuffer>>,
|
mut buffer: Option<BufferResource<Tbuffer>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Owned, Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
|
impl<T:Owned,Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
//if self.p != none {
|
//if self.p != none {
|
||||||
// debug!("drop recv %?", option::get(self.p));
|
// debug!("drop recv %?", option::get(self.p));
|
||||||
|
@ -869,7 +869,7 @@ impl<T:Owned, Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, Tbuffer: Owned> RecvPacketBuffered<T, Tbuffer> {
|
impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||||
fn unwrap() -> *Packet<T> {
|
fn unwrap() -> *Packet<T> {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
p <-> self.p;
|
p <-> self.p;
|
||||||
|
@ -884,7 +884,7 @@ 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() -> *PacketHeader {
|
pure fn header() -> *PacketHeader {
|
||||||
match self.p {
|
match self.p {
|
||||||
Some(packet) => unsafe {
|
Some(packet) => unsafe {
|
||||||
|
@ -923,7 +923,7 @@ endpoint. The send endpoint is returned to the caller and the receive
|
||||||
endpoint is passed to the new task.
|
endpoint is passed to the new task.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
pub fn spawn_service<T: Owned, Tb: Owned>(
|
pub fn spawn_service<T:Owned,Tb:Owned>(
|
||||||
init: extern fn() -> (SendPacketBuffered<T, Tb>,
|
init: extern fn() -> (SendPacketBuffered<T, Tb>,
|
||||||
RecvPacketBuffered<T, Tb>),
|
RecvPacketBuffered<T, Tb>),
|
||||||
service: fn~(v: RecvPacketBuffered<T, Tb>))
|
service: fn~(v: RecvPacketBuffered<T, Tb>))
|
||||||
|
@ -947,7 +947,7 @@ pub fn spawn_service<T: Owned, Tb: Owned>(
|
||||||
receive state.
|
receive state.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
pub fn spawn_service_recv<T: Owned, Tb: Owned>(
|
pub fn spawn_service_recv<T:Owned,Tb:Owned>(
|
||||||
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
|
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
|
||||||
SendPacketBuffered<T, Tb>),
|
SendPacketBuffered<T, Tb>),
|
||||||
service: fn~(v: SendPacketBuffered<T, Tb>))
|
service: fn~(v: SendPacketBuffered<T, Tb>))
|
||||||
|
@ -970,7 +970,7 @@ pub fn spawn_service_recv<T: Owned, Tb: Owned>(
|
||||||
// Streams - Make pipes a little easier in general.
|
// Streams - Make pipes a little easier in general.
|
||||||
|
|
||||||
proto! streamp (
|
proto! streamp (
|
||||||
Open:send<T: Owned> {
|
Open:send<T:Owned> {
|
||||||
data(T) -> Open<T>
|
data(T) -> Open<T>
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1036,7 +1036,7 @@ pub fn stream<T:Owned>() -> (Port<T>, Chan<T>) {
|
||||||
(Port_(Port_ { endp: Some(s) }), Chan_(Chan_{ endp: Some(c) }))
|
(Port_(Port_ { endp: Some(s) }), Chan_(Chan_{ endp: Some(c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericChan<T> for Chan<T> {
|
impl<T:Owned> GenericChan<T> for Chan<T> {
|
||||||
fn send(x: T) {
|
fn send(x: T) {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
|
@ -1045,7 +1045,7 @@ impl<T: Owned> GenericChan<T> for Chan<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericSmartChan<T> for Chan<T> {
|
impl<T:Owned> GenericSmartChan<T> for Chan<T> {
|
||||||
|
|
||||||
fn try_send(x: T) -> bool {
|
fn try_send(x: T) -> bool {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
|
@ -1060,7 +1060,7 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericPort<T> for Port<T> {
|
impl<T:Owned> GenericPort<T> for Port<T> {
|
||||||
fn recv() -> T {
|
fn recv() -> T {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
|
@ -1082,7 +1082,7 @@ impl<T: Owned> GenericPort<T> for Port<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Peekable<T> for Port<T> {
|
impl<T:Owned> Peekable<T> for Port<T> {
|
||||||
pure fn peek() -> bool {
|
pure fn peek() -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
|
@ -1097,7 +1097,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Selectable for Port<T> {
|
impl<T:Owned> Selectable for Port<T> {
|
||||||
pure fn header() -> *PacketHeader {
|
pure fn header() -> *PacketHeader {
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.endp {
|
match self.endp {
|
||||||
|
@ -1113,13 +1113,13 @@ pub struct PortSet<T> {
|
||||||
mut ports: ~[pipes::Port<T>],
|
mut ports: ~[pipes::Port<T>],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn PortSet<T: Owned>() -> PortSet<T>{
|
pub fn PortSet<T:Owned>() -> PortSet<T>{
|
||||||
PortSet {
|
PortSet {
|
||||||
ports: ~[]
|
ports: ~[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> PortSet<T> {
|
impl<T:Owned> PortSet<T> {
|
||||||
|
|
||||||
fn add(port: pipes::Port<T>) {
|
fn add(port: pipes::Port<T>) {
|
||||||
self.ports.push(port)
|
self.ports.push(port)
|
||||||
|
@ -1132,7 +1132,7 @@ impl<T: Owned> PortSet<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericPort<T> for PortSet<T> {
|
impl<T:Owned> GenericPort<T> for PortSet<T> {
|
||||||
|
|
||||||
fn try_recv() -> Option<T> {
|
fn try_recv() -> Option<T> {
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
|
@ -1162,7 +1162,7 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Peekable<T> for PortSet<T> {
|
impl<T:Owned> Peekable<T> for PortSet<T> {
|
||||||
pure fn peek() -> bool {
|
pure fn peek() -> 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.
|
||||||
|
@ -1176,7 +1176,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
|
||||||
/// A channel that can be shared between many senders.
|
/// A channel that can be shared between many senders.
|
||||||
pub type SharedChan<T> = private::Exclusive<Chan<T>>;
|
pub type SharedChan<T> = private::Exclusive<Chan<T>>;
|
||||||
|
|
||||||
impl<T: Owned> GenericChan<T> for SharedChan<T> {
|
impl<T:Owned> GenericChan<T> for SharedChan<T> {
|
||||||
fn send(x: T) {
|
fn send(x: T) {
|
||||||
let mut xx = Some(x);
|
let mut xx = Some(x);
|
||||||
do self.with_imm |chan| {
|
do self.with_imm |chan| {
|
||||||
|
@ -1187,7 +1187,7 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
|
impl<T:Owned> GenericSmartChan<T> for SharedChan<T> {
|
||||||
fn try_send(x: T) -> bool {
|
fn try_send(x: T) -> bool {
|
||||||
let mut xx = Some(x);
|
let mut xx = Some(x);
|
||||||
do self.with_imm |chan| {
|
do self.with_imm |chan| {
|
||||||
|
@ -1204,7 +1204,7 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message from one of two endpoints.
|
/// Receive a message from one of two endpoints.
|
||||||
pub trait Select2<T: Owned, U: Owned> {
|
pub trait Select2<T:Owned,U:Owned> {
|
||||||
/// Receive a message or return `None` if a connection closes.
|
/// Receive a message or return `None` if a connection closes.
|
||||||
fn try_select() -> Either<Option<T>, Option<U>>;
|
fn try_select() -> Either<Option<T>, Option<U>>;
|
||||||
/// Receive a message or fail if a connection closes.
|
/// Receive a message or fail if a connection closes.
|
||||||
|
@ -1247,17 +1247,17 @@ pub type ChanOne<T> = oneshot::client::Oneshot<T>;
|
||||||
pub type PortOne<T> = oneshot::server::Oneshot<T>;
|
pub type PortOne<T> = oneshot::server::Oneshot<T>;
|
||||||
|
|
||||||
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
|
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
|
||||||
pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
|
pub fn oneshot<T:Owned>() -> (PortOne<T>, ChanOne<T>) {
|
||||||
let (chan, port) = oneshot::init();
|
let (chan, port) = oneshot::init();
|
||||||
(port, chan)
|
(port, chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> PortOne<T> {
|
impl<T:Owned> PortOne<T> {
|
||||||
fn recv(self) -> T { recv_one(self) }
|
fn recv(self) -> T { recv_one(self) }
|
||||||
fn try_recv(self) -> Option<T> { try_recv_one(self) }
|
fn try_recv(self) -> Option<T> { try_recv_one(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> ChanOne<T> {
|
impl<T:Owned> ChanOne<T> {
|
||||||
fn send(self, data: T) { send_one(self, data) }
|
fn send(self, data: T) { send_one(self, data) }
|
||||||
fn try_send(self, data: T) -> bool { try_send_one(self, data) }
|
fn try_send(self, data: T) -> bool { try_send_one(self, data) }
|
||||||
}
|
}
|
||||||
|
@ -1266,13 +1266,13 @@ impl<T: Owned> ChanOne<T> {
|
||||||
* Receive a message from a oneshot pipe, failing if the connection was
|
* Receive a message from a oneshot pipe, failing if the connection was
|
||||||
* closed.
|
* closed.
|
||||||
*/
|
*/
|
||||||
pub fn recv_one<T: Owned>(port: PortOne<T>) -> T {
|
pub fn recv_one<T:Owned>(port: PortOne<T>) -> T {
|
||||||
let oneshot::send(message) = recv(port);
|
let oneshot::send(message) = recv(port);
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message from a oneshot pipe unless the connection was closed.
|
/// Receive a message from a oneshot pipe unless the connection was closed.
|
||||||
pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
|
pub fn try_recv_one<T:Owned> (port: PortOne<T>) -> Option<T> {
|
||||||
let message = try_recv(port);
|
let message = try_recv(port);
|
||||||
|
|
||||||
if message.is_none() { None }
|
if message.is_none() { None }
|
||||||
|
@ -1283,7 +1283,7 @@ pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message on a oneshot pipe, failing if the connection was closed.
|
/// Send a message on a oneshot pipe, failing if the connection was closed.
|
||||||
pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
|
pub fn send_one<T:Owned>(chan: ChanOne<T>, data: T) {
|
||||||
oneshot::client::send(chan, data);
|
oneshot::client::send(chan, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1291,7 +1291,7 @@ pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
|
||||||
* Send a message on a oneshot pipe, or return false if the connection was
|
* Send a message on a oneshot pipe, or return false if the connection was
|
||||||
* closed.
|
* closed.
|
||||||
*/
|
*/
|
||||||
pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
|
pub fn try_send_one<T:Owned>(chan: ChanOne<T>, data: T)
|
||||||
-> bool {
|
-> bool {
|
||||||
oneshot::client::try_send(chan, data).is_some()
|
oneshot::client::try_send(chan, data).is_some()
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ fn ArcDestruct<T>(data: *libc::c_void) -> ArcDestruct<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
|
pub unsafe fn unwrap_shared_mutable_state<T:Owned>(rc: SharedMutableState<T>)
|
||||||
-> T {
|
-> T {
|
||||||
struct DeathThroes<T> {
|
struct DeathThroes<T> {
|
||||||
mut ptr: Option<~ArcData<T>>,
|
mut ptr: Option<~ArcData<T>>,
|
||||||
|
@ -246,7 +246,7 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
|
||||||
*/
|
*/
|
||||||
pub type SharedMutableState<T> = ArcDestruct<T>;
|
pub type SharedMutableState<T> = ArcDestruct<T>;
|
||||||
|
|
||||||
pub unsafe fn shared_mutable_state<T: Owned>(data: T) ->
|
pub unsafe fn shared_mutable_state<T:Owned>(data: T) ->
|
||||||
SharedMutableState<T> {
|
SharedMutableState<T> {
|
||||||
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -256,7 +256,7 @@ pub unsafe fn shared_mutable_state<T: Owned>(data: T) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn get_shared_mutable_state<T: Owned>(
|
pub unsafe fn get_shared_mutable_state<T:Owned>(
|
||||||
rc: *SharedMutableState<T>) -> *mut T
|
rc: *SharedMutableState<T>) -> *mut T
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -268,7 +268,7 @@ pub unsafe fn get_shared_mutable_state<T: Owned>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn get_shared_immutable_state<T: Owned>(
|
pub unsafe fn get_shared_immutable_state<T:Owned>(
|
||||||
rc: &a/SharedMutableState<T>) -> &a/T {
|
rc: &a/SharedMutableState<T>) -> &a/T {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||||
|
@ -280,7 +280,7 @@ pub unsafe fn get_shared_immutable_state<T: Owned>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn clone_shared_mutable_state<T: Owned>(rc: &SharedMutableState<T>)
|
pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
|
||||||
-> SharedMutableState<T> {
|
-> SharedMutableState<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||||
|
@ -291,7 +291,7 @@ pub unsafe fn clone_shared_mutable_state<T: Owned>(rc: &SharedMutableState<T>)
|
||||||
ArcDestruct((*rc).data)
|
ArcDestruct((*rc).data)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Clone for SharedMutableState<T> {
|
impl<T:Owned> Clone for SharedMutableState<T> {
|
||||||
fn clone(&self) -> SharedMutableState<T> {
|
fn clone(&self) -> SharedMutableState<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
clone_shared_mutable_state(self)
|
clone_shared_mutable_state(self)
|
||||||
|
@ -353,21 +353,21 @@ struct ExData<T> { lock: LittleLock, mut failed: bool, mut data: T, }
|
||||||
*/
|
*/
|
||||||
pub struct Exclusive<T> { x: SharedMutableState<ExData<T>> }
|
pub struct Exclusive<T> { x: SharedMutableState<ExData<T>> }
|
||||||
|
|
||||||
pub fn exclusive<T:Owned >(user_data: T) -> Exclusive<T> {
|
pub fn exclusive<T:Owned>(user_data: T) -> Exclusive<T> {
|
||||||
let data = ExData {
|
let data = ExData {
|
||||||
lock: LittleLock(), mut failed: false, mut data: user_data
|
lock: LittleLock(), mut failed: false, mut data: user_data
|
||||||
};
|
};
|
||||||
Exclusive { x: unsafe { shared_mutable_state(data) } }
|
Exclusive { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Clone for Exclusive<T> {
|
impl<T:Owned> Clone for Exclusive<T> {
|
||||||
// Duplicate an exclusive ARC, as std::arc::clone.
|
// Duplicate an exclusive ARC, as std::arc::clone.
|
||||||
fn clone(&self) -> Exclusive<T> {
|
fn clone(&self) -> Exclusive<T> {
|
||||||
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Exclusive<T> {
|
impl<T:Owned> Exclusive<T> {
|
||||||
// Exactly like std::arc::mutex_arc,access(), but with the little_lock
|
// Exactly like std::arc::mutex_arc,access(), but with the little_lock
|
||||||
// instead of a proper mutex. Same reason for being unsafe.
|
// instead of a proper mutex. Same reason for being unsafe.
|
||||||
//
|
//
|
||||||
|
@ -400,7 +400,7 @@ impl<T: Owned> Exclusive<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#3724) make this a by-move method on the exclusive
|
// FIXME(#3724) make this a by-move method on the exclusive
|
||||||
pub fn unwrap_exclusive<T: Owned>(arc: Exclusive<T>) -> T {
|
pub fn unwrap_exclusive<T:Owned>(arc: Exclusive<T>) -> T {
|
||||||
let Exclusive { x: x } = arc;
|
let Exclusive { x: x } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let ExData { data: data, _ } = inner;
|
let ExData { data: data, _ } = inner;
|
||||||
|
|
|
@ -43,7 +43,7 @@ use uint;
|
||||||
|
|
||||||
pub type GlobalDataKey<T> = &fn(v: T);
|
pub type GlobalDataKey<T> = &fn(v: T);
|
||||||
|
|
||||||
pub unsafe fn global_data_clone_create<T: Owned Clone>(
|
pub unsafe fn global_data_clone_create<T:Owned + Clone>(
|
||||||
key: GlobalDataKey<T>, create: &fn() -> ~T) -> T {
|
key: GlobalDataKey<T>, create: &fn() -> ~T) -> T {
|
||||||
/*!
|
/*!
|
||||||
* Clone a global value or, if it has not been created,
|
* Clone a global value or, if it has not been created,
|
||||||
|
@ -59,7 +59,7 @@ pub unsafe fn global_data_clone_create<T: Owned Clone>(
|
||||||
global_data_clone_create_(key_ptr(key), create)
|
global_data_clone_create_(key_ptr(key), create)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn global_data_clone_create_<T: Owned Clone>(
|
unsafe fn global_data_clone_create_<T:Owned + Clone>(
|
||||||
key: uint, create: &fn() -> ~T) -> T {
|
key: uint, create: &fn() -> ~T) -> T {
|
||||||
|
|
||||||
let mut clone_value: Option<T> = None;
|
let mut clone_value: Option<T> = None;
|
||||||
|
@ -79,13 +79,13 @@ unsafe fn global_data_clone_create_<T: Owned Clone>(
|
||||||
return clone_value.unwrap();
|
return clone_value.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn global_data_modify<T: Owned>(
|
unsafe fn global_data_modify<T:Owned>(
|
||||||
key: GlobalDataKey<T>, op: &fn(Option<~T>) -> Option<~T>) {
|
key: GlobalDataKey<T>, op: &fn(Option<~T>) -> Option<~T>) {
|
||||||
|
|
||||||
global_data_modify_(key_ptr(key), op)
|
global_data_modify_(key_ptr(key), op)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn global_data_modify_<T: Owned>(
|
unsafe fn global_data_modify_<T:Owned>(
|
||||||
key: uint, op: &fn(Option<~T>) -> Option<~T>) {
|
key: uint, op: &fn(Option<~T>) -> Option<~T>) {
|
||||||
|
|
||||||
let mut old_dtor = None;
|
let mut old_dtor = None;
|
||||||
|
@ -124,7 +124,7 @@ unsafe fn global_data_modify_<T: Owned>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn global_data_clone<T: Owned Clone>(
|
pub unsafe fn global_data_clone<T:Owned + Clone>(
|
||||||
key: GlobalDataKey<T>) -> Option<T> {
|
key: GlobalDataKey<T>) -> Option<T> {
|
||||||
let mut maybe_clone: Option<T> = None;
|
let mut maybe_clone: Option<T> = None;
|
||||||
do global_data_modify(key) |current| {
|
do global_data_modify(key) |current| {
|
||||||
|
@ -220,7 +220,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_ptr<T: Owned>(key: GlobalDataKey<T>) -> uint {
|
fn key_ptr<T:Owned>(key: GlobalDataKey<T>) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
let closure: Closure = reinterpret_cast(&key);
|
let closure: Closure = reinterpret_cast(&key);
|
||||||
return transmute(closure.code);
|
return transmute(closure.code);
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl Rand for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Rand> Rand for Option<T> {
|
impl<T:Rand> Rand for Option<T> {
|
||||||
static fn rand(rng: rand::Rng) -> Option<T> {
|
static fn rand(rng: rand::Rng) -> Option<T> {
|
||||||
if rng.gen_bool() { Some(Rand::rand(rng)) }
|
if rng.gen_bool() { Some(Rand::rand(rng)) }
|
||||||
else { None }
|
else { None }
|
||||||
|
@ -143,7 +143,7 @@ pub struct Weighted<T> {
|
||||||
/// Extension methods for random number generators
|
/// Extension methods for random number generators
|
||||||
impl Rng {
|
impl Rng {
|
||||||
/// Return a random value for a Rand type
|
/// Return a random value for a Rand type
|
||||||
fn gen<T: Rand>() -> T {
|
fn gen<T:Rand>() -> T {
|
||||||
Rand::rand(self)
|
Rand::rand(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ impl Rng {
|
||||||
* Choose an item respecting the relative weights, failing if the sum of
|
* Choose an item respecting the relative weights, failing if the sum of
|
||||||
* the weights is 0
|
* the weights is 0
|
||||||
*/
|
*/
|
||||||
fn choose_weighted<T: Copy>(v : &[Weighted<T>]) -> T {
|
fn choose_weighted<T:Copy>(v : &[Weighted<T>]) -> T {
|
||||||
self.choose_weighted_option(v).get()
|
self.choose_weighted_option(v).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,11 @@ pub fn align(size: uint, align: uint) -> uint {
|
||||||
pub struct MovePtrAdaptor<V> {
|
pub struct MovePtrAdaptor<V> {
|
||||||
inner: V
|
inner: V
|
||||||
}
|
}
|
||||||
pub fn MovePtrAdaptor<V: TyVisitor MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
||||||
MovePtrAdaptor { inner: v }
|
MovePtrAdaptor { inner: v }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V> {
|
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn bump(sz: uint) {
|
fn bump(sz: uint) {
|
||||||
do self.inner.move_ptr() |p| {
|
do self.inner.move_ptr() |p| {
|
||||||
|
@ -72,7 +72,7 @@ impl<V: TyVisitor MovePtr> MovePtrAdaptor<V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Abstract type-directed pointer-movement using the MovePtr trait
|
/// Abstract type-directed pointer-movement using the MovePtr trait
|
||||||
impl<V: TyVisitor MovePtr> TyVisitor for MovePtrAdaptor<V> {
|
impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
|
||||||
fn visit_bot(&self) -> bool {
|
fn visit_bot(&self) -> bool {
|
||||||
self.align_to::<()>();
|
self.align_to::<()>();
|
||||||
if ! self.inner.visit_bot() { return false; }
|
if ! self.inner.visit_bot() { return false; }
|
||||||
|
|
|
@ -37,7 +37,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 pure 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 {
|
||||||
|
@ -100,7 +100,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 pure 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),
|
||||||
|
@ -220,7 +220,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 pure 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),
|
||||||
|
@ -261,7 +261,7 @@ impl<T, E> Result<T, E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy, E> Result<T, E> {
|
impl<T:Copy,E> Result<T, E> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn get(&self) -> T { get(self) }
|
pure fn get(&self) -> T { get(self) }
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ pub type LocalDataKey<T> = &fn(v: @T);
|
||||||
* Remove a task-local data value from the table, returning the
|
* Remove a task-local data value from the table, returning the
|
||||||
* reference that was originally created to insert it.
|
* reference that was originally created to insert it.
|
||||||
*/
|
*/
|
||||||
pub unsafe fn local_data_pop<T: Durable>(
|
pub unsafe fn local_data_pop<T:Durable>(
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_pop(rt::rust_get_task(), key)
|
local_pop(rt::rust_get_task(), key)
|
||||||
|
@ -60,7 +60,7 @@ pub unsafe fn local_data_pop<T: Durable>(
|
||||||
* Retrieve a task-local data value. It will also be kept alive in the
|
* Retrieve a task-local data value. It will also be kept alive in the
|
||||||
* table until explicitly removed.
|
* table until explicitly removed.
|
||||||
*/
|
*/
|
||||||
pub unsafe fn local_data_get<T: Durable>(
|
pub unsafe fn local_data_get<T:Durable>(
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_get(rt::rust_get_task(), key)
|
local_get(rt::rust_get_task(), key)
|
||||||
|
@ -69,7 +69,7 @@ pub unsafe fn local_data_get<T: Durable>(
|
||||||
* Store a value in task-local data. If this key already has a value,
|
* Store a value in task-local data. If this key already has a value,
|
||||||
* that value is overwritten (and its destructor is run).
|
* that value is overwritten (and its destructor is run).
|
||||||
*/
|
*/
|
||||||
pub unsafe fn local_data_set<T: Durable>(
|
pub unsafe fn local_data_set<T:Durable>(
|
||||||
key: LocalDataKey<T>, data: @T) {
|
key: LocalDataKey<T>, data: @T) {
|
||||||
|
|
||||||
local_set(rt::rust_get_task(), key, data)
|
local_set(rt::rust_get_task(), key, data)
|
||||||
|
@ -78,7 +78,7 @@ pub unsafe fn local_data_set<T: Durable>(
|
||||||
* Modify a task-local data value. If the function returns 'None', the
|
* Modify a task-local data value. If the function returns 'None', the
|
||||||
* data is removed (and its reference dropped).
|
* data is removed (and its reference dropped).
|
||||||
*/
|
*/
|
||||||
pub unsafe fn local_data_modify<T: Durable>(
|
pub unsafe fn local_data_modify<T:Durable>(
|
||||||
key: LocalDataKey<T>,
|
key: LocalDataKey<T>,
|
||||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ use rt::rust_task;
|
||||||
type rust_task = libc::c_void;
|
type rust_task = libc::c_void;
|
||||||
|
|
||||||
pub trait LocalData { }
|
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 {
|
pure fn eq(&self, other: &@LocalData) -> bool {
|
||||||
|
@ -79,7 +79,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn key_to_key_value<T: Durable>(
|
unsafe fn key_to_key_value<T:Durable>(
|
||||||
key: LocalDataKey<T>) -> *libc::c_void {
|
key: LocalDataKey<T>) -> *libc::c_void {
|
||||||
|
|
||||||
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
|
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
|
||||||
|
@ -89,7 +89,7 @@ unsafe fn key_to_key_value<T: Durable>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If returning Some(..), returns with @T with the map's reference. Careful!
|
// If returning Some(..), returns with @T with the map's reference. Careful!
|
||||||
unsafe fn local_data_lookup<T: Durable>(
|
unsafe fn local_data_lookup<T:Durable>(
|
||||||
map: TaskLocalMap, key: LocalDataKey<T>)
|
map: TaskLocalMap, key: LocalDataKey<T>)
|
||||||
-> Option<(uint, *libc::c_void)> {
|
-> Option<(uint, *libc::c_void)> {
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ unsafe fn local_data_lookup<T: Durable>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn local_get_helper<T: Durable>(
|
unsafe fn local_get_helper<T:Durable>(
|
||||||
task: *rust_task, key: LocalDataKey<T>,
|
task: *rust_task, key: LocalDataKey<T>,
|
||||||
do_pop: bool) -> Option<@T> {
|
do_pop: bool) -> Option<@T> {
|
||||||
|
|
||||||
|
@ -129,21 +129,21 @@ unsafe fn local_get_helper<T: Durable>(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub unsafe fn local_pop<T: Durable>(
|
pub unsafe fn local_pop<T:Durable>(
|
||||||
task: *rust_task,
|
task: *rust_task,
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_get_helper(task, key, true)
|
local_get_helper(task, key, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn local_get<T: Durable>(
|
pub unsafe fn local_get<T:Durable>(
|
||||||
task: *rust_task,
|
task: *rust_task,
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_get_helper(task, key, false)
|
local_get_helper(task, key, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn local_set<T: Durable>(
|
pub unsafe fn local_set<T:Durable>(
|
||||||
task: *rust_task, key: LocalDataKey<T>, data: @T) {
|
task: *rust_task, key: LocalDataKey<T>, data: @T) {
|
||||||
|
|
||||||
let map = get_task_local_map(task);
|
let map = get_task_local_map(task);
|
||||||
|
@ -175,7 +175,7 @@ pub unsafe fn local_set<T: Durable>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn local_modify<T: Durable>(
|
pub unsafe fn local_modify<T:Durable>(
|
||||||
task: *rust_task, key: LocalDataKey<T>,
|
task: *rust_task, key: LocalDataKey<T>,
|
||||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||||
|
|
||||||
|
|
|
@ -396,7 +396,7 @@ impl TaskBuilder {
|
||||||
spawn::spawn_raw(opts, (x.gen_body)(f));
|
spawn::spawn_raw(opts, (x.gen_body)(f));
|
||||||
}
|
}
|
||||||
/// Runs a task, while transfering ownership of one argument to the child.
|
/// Runs a task, while transfering ownership of one argument to the child.
|
||||||
fn spawn_with<A: Owned>(arg: A, f: fn~(v: A)) {
|
fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
|
||||||
let arg = ~mut Some(arg);
|
let arg = ~mut Some(arg);
|
||||||
do self.spawn || {
|
do self.spawn || {
|
||||||
f(option::swap_unwrap(arg))
|
f(option::swap_unwrap(arg))
|
||||||
|
@ -416,7 +416,7 @@ impl TaskBuilder {
|
||||||
* # Failure
|
* # Failure
|
||||||
* Fails if a future_result was already set for this task.
|
* Fails if a future_result was already set for this task.
|
||||||
*/
|
*/
|
||||||
fn try<T: Owned>(f: fn~() -> T) -> Result<T,()> {
|
fn try<T:Owned>(f: fn~() -> T) -> Result<T,()> {
|
||||||
let (po, ch) = stream::<T>();
|
let (po, ch) = stream::<T>();
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl IterBytes for int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
for (*self).each |elt| {
|
for (*self).each |elt| {
|
||||||
|
@ -208,7 +208,7 @@ impl<A: IterBytes> IterBytes for &[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) {
|
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -219,7 +219,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) {
|
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -235,21 +235,21 @@ pure 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) {
|
pure 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) {
|
pure 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 pure 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});
|
||||||
|
@ -379,7 +379,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) {
|
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -389,21 +389,21 @@ impl<A: IterBytes> IterBytes for Option<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) {
|
pure 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) {
|
pure 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) {
|
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
|
||||||
(**self).iter_bytes(lsb0, f);
|
(**self).iter_bytes(lsb0, f);
|
||||||
|
@ -424,7 +424,7 @@ trait ToBytes {
|
||||||
fn to_bytes(&self, lsb0: bool) -> ~[u8];
|
fn to_bytes(&self, lsb0: bool) -> ~[u8];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: IterBytes> ToBytes for A {
|
impl<A:IterBytes> ToBytes for A {
|
||||||
fn to_bytes(&self, lsb0: bool) -> ~[u8] {
|
fn to_bytes(&self, lsb0: bool) -> ~[u8] {
|
||||||
do io::with_bytes_writer |wr| {
|
do io::with_bytes_writer |wr| {
|
||||||
for self.iter_bytes(lsb0) |bytes| {
|
for self.iter_bytes(lsb0) |bytes| {
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl ToStr for @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 {
|
pure fn to_str(&self) -> ~str {
|
||||||
// FIXME(#4760): this causes an llvm assertion
|
// FIXME(#4760): this causes an llvm assertion
|
||||||
|
@ -57,7 +57,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 {
|
pure fn to_str(&self) -> ~str {
|
||||||
// FIXME(#4760): this causes an llvm assertion
|
// FIXME(#4760): this causes an llvm assertion
|
||||||
|
@ -74,7 +74,7 @@ impl<A: ToStr, B: ToStr, C: ToStr> ToStr for (A, B, C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToStr> ToStr for ~[A] {
|
impl<A:ToStr> ToStr for ~[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str {
|
pure fn to_str(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -94,11 +94,11 @@ 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 { ~"@" + (**self).to_str() }
|
pure fn to_str(&self) -> ~str { ~"@" + (**self).to_str() }
|
||||||
}
|
}
|
||||||
impl<A: ToStr> ToStr for ~A {
|
impl<A:ToStr> ToStr for ~A {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() }
|
pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub trait CopyableTuple<T, U> {
|
||||||
pure fn swap() -> (U, T);
|
pure fn swap() -> (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)]
|
||||||
|
@ -70,7 +70,7 @@ pub trait ExtendedTupleOps<A,B> {
|
||||||
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C];
|
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy, B: Copy> ExtendedTupleOps<A,B> for (&[A], &[B]) {
|
impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&[A], &[B]) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zip(&self) -> ~[(A, B)] {
|
fn zip(&self) -> ~[(A, B)] {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -90,7 +90,7 @@ impl<A: Copy, B: Copy> ExtendedTupleOps<A,B> for (&[A], &[B]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy, B: Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
|
impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zip(&self) -> ~[(A, B)] {
|
fn zip(&self) -> ~[(A, B)] {
|
||||||
|
@ -114,7 +114,7 @@ impl<A: Copy, B: Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
|
||||||
// FIXME #4898: impl for one-tuples
|
// FIXME #4898: impl for one-tuples
|
||||||
|
|
||||||
#[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 {
|
pure fn eq(&self, other: &(A, B)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
|
@ -130,7 +130,7 @@ impl<A: Eq, B: Eq> Eq for (A, B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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 {
|
pure fn lt(&self, other: &(A, B)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
|
@ -155,7 +155,7 @@ impl<A: Ord, B: Ord> Ord for (A, B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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 {
|
pure fn eq(&self, other: &(A, B, C)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
|
@ -172,7 +172,7 @@ impl<A: Eq, B: Eq, C: Eq> Eq for (A, B, C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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 {
|
pure fn lt(&self, other: &(A, B, C)) -> bool {
|
||||||
match (*self) {
|
match (*self) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub pure 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`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn with<T: Copy, R>(
|
pub fn with<T:Copy,R>(
|
||||||
ptr: &mut T,
|
ptr: &mut T,
|
||||||
new_value: T,
|
new_value: T,
|
||||||
op: &fn() -> R) -> R
|
op: &fn() -> R) -> R
|
||||||
|
|
|
@ -135,12 +135,12 @@ 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 pure fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] {
|
||||||
from_fn(n_elts, |_i| copy t)
|
from_fn(n_elts, |_i| copy t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new unique vector with the same contents as the slice
|
/// Creates a new unique vector with the same contents as the slice
|
||||||
pub pure fn from_slice<T: Copy>(t: &[T]) -> ~[T] {
|
pub pure fn from_slice<T:Copy>(t: &[T]) -> ~[T] {
|
||||||
from_fn(t.len(), |i| t[i])
|
from_fn(t.len(), |i| t[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,10 +216,10 @@ pub pure fn cast_from_mut<T>(v: ~[mut T]) -> ~[T] {
|
||||||
// Accessors
|
// Accessors
|
||||||
|
|
||||||
/// Returns the first element of a vector
|
/// Returns the first element of a vector
|
||||||
pub pure fn head<T: Copy>(v: &[const T]) -> T { v[0] }
|
pub pure fn head<T:Copy>(v: &[const T]) -> T { v[0] }
|
||||||
|
|
||||||
/// Returns a vector containing all but the first element of a slice
|
/// Returns a vector containing all but the first element of a slice
|
||||||
pub pure fn tail<T: Copy>(v: &[const T]) -> ~[T] {
|
pub pure fn tail<T:Copy>(v: &[const T]) -> ~[T] {
|
||||||
slice(v, 1u, len(v)).to_vec()
|
slice(v, 1u, len(v)).to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,18 +227,18 @@ pub pure fn tail<T: Copy>(v: &[const T]) -> ~[T] {
|
||||||
* Returns a vector containing all but the first `n` \
|
* Returns a vector containing all but the first `n` \
|
||||||
* elements of a slice
|
* elements of a slice
|
||||||
*/
|
*/
|
||||||
pub pure fn tailn<T: Copy>(v: &[const T], n: uint) -> ~[T] {
|
pub pure fn tailn<T:Copy>(v: &[const T], n: uint) -> ~[T] {
|
||||||
slice(v, n, len(v)).to_vec()
|
slice(v, n, len(v)).to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a vector containing all but the last element of a slice
|
/// Returns a vector containing all but the last element of a slice
|
||||||
pub pure fn init<T: Copy>(v: &[const T]) -> ~[T] {
|
pub pure fn init<T:Copy>(v: &[const T]) -> ~[T] {
|
||||||
assert len(v) != 0u;
|
assert len(v) != 0u;
|
||||||
slice(v, 0u, len(v) - 1u).to_vec()
|
slice(v, 0u, len(v) - 1u).to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the last element of the slice `v`, failing if the slice is empty.
|
/// Returns the last element of the slice `v`, failing if the slice is empty.
|
||||||
pub pure fn last<T: Copy>(v: &[const T]) -> T {
|
pub pure fn last<T:Copy>(v: &[const T]) -> T {
|
||||||
if len(v) == 0u { fail!(~"last_unsafe: empty vector") }
|
if len(v) == 0u { fail!(~"last_unsafe: empty vector") }
|
||||||
v[len(v) - 1u]
|
v[len(v) - 1u]
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ pub pure fn last<T: Copy>(v: &[const T]) -> T {
|
||||||
* Returns `Some(x)` where `x` is the last element of the slice `v`,
|
* Returns `Some(x)` where `x` is the last element of the slice `v`,
|
||||||
* or `none` if the vector is empty.
|
* or `none` if the vector is empty.
|
||||||
*/
|
*/
|
||||||
pub pure fn last_opt<T: Copy>(v: &[const T]) -> Option<T> {
|
pub pure fn last_opt<T:Copy>(v: &[const T]) -> Option<T> {
|
||||||
if len(v) == 0u { return None; }
|
if len(v) == 0u { return None; }
|
||||||
Some(v[len(v) - 1u])
|
Some(v[len(v) - 1u])
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ pub pure fn const_slice<T>(v: &r/[const T], start: uint,
|
||||||
/// Copies
|
/// Copies
|
||||||
|
|
||||||
/// Split the vector `v` by applying each element against the predicate `f`.
|
/// Split the vector `v` by applying each element against the predicate `f`.
|
||||||
pub fn split<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
|
pub fn split<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
let ln = len(v);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ pub fn split<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
* Split the vector `v` by applying each element against the predicate `f` up
|
* Split the vector `v` by applying each element against the predicate `f` up
|
||||||
* to `n` times.
|
* to `n` times.
|
||||||
*/
|
*/
|
||||||
pub fn splitn<T: Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
|
pub fn splitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
let ln = len(v);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ pub fn splitn<T: Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
* Reverse split the vector `v` by applying each element against the predicate
|
* Reverse split the vector `v` by applying each element against the predicate
|
||||||
* `f`.
|
* `f`.
|
||||||
*/
|
*/
|
||||||
pub fn rsplit<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
|
pub fn rsplit<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
let ln = len(v);
|
let ln = len(v);
|
||||||
if (ln == 0) { return ~[] }
|
if (ln == 0) { return ~[] }
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ pub fn rsplit<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
* Reverse split the vector `v` by applying each element against the predicate
|
* Reverse split the vector `v` by applying each element against the predicate
|
||||||
* `f` up to `n times.
|
* `f` up to `n times.
|
||||||
*/
|
*/
|
||||||
pub fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
|
pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
|
||||||
let ln = len(v);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ pub fn partition<T>(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
|
||||||
* Partitions a vector into two new vectors: those that satisfies the
|
* Partitions a vector into two new vectors: those that satisfies the
|
||||||
* predicate, and those that do not.
|
* predicate, and those that do not.
|
||||||
*/
|
*/
|
||||||
pub pure fn partitioned<T: Copy>(v: &[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
|
pub pure fn partitioned<T:Copy>(v: &[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
|
||||||
let mut lefts = ~[];
|
let mut lefts = ~[];
|
||||||
let mut rights = ~[];
|
let mut rights = ~[];
|
||||||
|
|
||||||
|
@ -616,7 +616,7 @@ fn push_slow<T>(v: &mut ~[T], initval: T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn push_all<T: Copy>(v: &mut ~[T], rhs: &[const T]) {
|
pub fn push_all<T:Copy>(v: &mut ~[T], rhs: &[const T]) {
|
||||||
let new_len = v.len() + rhs.len();
|
let new_len = v.len() + rhs.len();
|
||||||
reserve(&mut *v, new_len);
|
reserve(&mut *v, new_len);
|
||||||
|
|
||||||
|
@ -662,7 +662,7 @@ pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
|
||||||
* Remove consecutive repeated elements from a vector; if the vector is
|
* Remove consecutive repeated elements from a vector; if the vector is
|
||||||
* sorted, this removes all duplicates.
|
* sorted, this removes all duplicates.
|
||||||
*/
|
*/
|
||||||
pub fn dedup<T: Eq>(v: &mut ~[T]) {
|
pub fn dedup<T:Eq>(v: &mut ~[T]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if v.len() < 1 { return; }
|
if v.len() < 1 { return; }
|
||||||
let mut last_written = 0, next_to_read = 1;
|
let mut last_written = 0, next_to_read = 1;
|
||||||
|
@ -700,7 +700,7 @@ pub fn dedup<T: Eq>(v: &mut ~[T]) {
|
||||||
|
|
||||||
// Appending
|
// Appending
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn append<T: Copy>(lhs: ~[T], rhs: &[const T]) -> ~[T] {
|
pub pure fn append<T:Copy>(lhs: ~[T], rhs: &[const T]) -> ~[T] {
|
||||||
let mut v = lhs;
|
let mut v = lhs;
|
||||||
unsafe {
|
unsafe {
|
||||||
v.push_all(rhs);
|
v.push_all(rhs);
|
||||||
|
@ -724,7 +724,7 @@ pub pure fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
|
||||||
* * n - The number of elements to add
|
* * n - The number of elements to add
|
||||||
* * initval - The value for the new elements
|
* * initval - The value for the new elements
|
||||||
*/
|
*/
|
||||||
pub fn grow<T: Copy>(v: &mut ~[T], n: uint, initval: &T) {
|
pub fn grow<T:Copy>(v: &mut ~[T], n: uint, initval: &T) {
|
||||||
let new_len = v.len() + n;
|
let new_len = v.len() + n;
|
||||||
reserve_at_least(&mut *v, new_len);
|
reserve_at_least(&mut *v, new_len);
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
|
@ -766,7 +766,7 @@ pub fn grow_fn<T>(v: &mut ~[T], n: uint, op: iter::InitOp<T>) {
|
||||||
* of the vector, expands the vector by replicating `initval` to fill the
|
* of the vector, expands the vector by replicating `initval` to fill the
|
||||||
* intervening space.
|
* intervening space.
|
||||||
*/
|
*/
|
||||||
pub fn grow_set<T: Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) {
|
pub fn grow_set<T:Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) {
|
||||||
let l = v.len();
|
let l = v.len();
|
||||||
if index >= l { grow(&mut *v, index - l + 1u, initval); }
|
if index >= l { grow(&mut *v, index - l + 1u, initval); }
|
||||||
v[index] = val;
|
v[index] = val;
|
||||||
|
@ -813,7 +813,7 @@ pub pure fn flat_map<T, U>(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a function to each pair of elements and return the results
|
/// Apply a function to each pair of elements and return the results
|
||||||
pub pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U],
|
pub pure fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
|
||||||
f: fn(t: &T, v: &U) -> V) -> ~[V] {
|
f: fn(t: &T, v: &U) -> V) -> ~[V] {
|
||||||
let v0_len = len(v0);
|
let v0_len = len(v0);
|
||||||
if v0_len != len(v1) { fail!(); }
|
if v0_len != len(v1) { fail!(); }
|
||||||
|
@ -891,7 +891,7 @@ pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] {
|
||||||
* Apply function `f` to each element of `v` and return a vector containing
|
* Apply function `f` to each element of `v` and return a vector containing
|
||||||
* only those elements for which `f` returned true.
|
* only those elements for which `f` returned true.
|
||||||
*/
|
*/
|
||||||
pub pure fn filtered<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] {
|
pub pure fn filtered<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] {
|
||||||
let mut result = ~[];
|
let mut result = ~[];
|
||||||
for each(v) |elem| {
|
for each(v) |elem| {
|
||||||
if f(elem) { unsafe { result.push(*elem); } }
|
if f(elem) { unsafe { result.push(*elem); } }
|
||||||
|
@ -924,14 +924,14 @@ pub fn retain<T>(v: &mut ~[T], f: pure fn(t: &T) -> bool) {
|
||||||
*
|
*
|
||||||
* Flattens a vector of vectors of T into a single vector of T.
|
* Flattens a vector of vectors of T into a single vector of T.
|
||||||
*/
|
*/
|
||||||
pub pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] {
|
pub pure fn concat<T:Copy>(v: &[~[T]]) -> ~[T] {
|
||||||
let mut r = ~[];
|
let mut r = ~[];
|
||||||
for each(v) |inner| { unsafe { r.push_all(*inner); } }
|
for each(v) |inner| { unsafe { r.push_all(*inner); } }
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Concatenate a vector of vectors, placing a given separator between each
|
/// Concatenate a vector of vectors, placing a given separator between each
|
||||||
pub pure fn connect<T: Copy>(v: &[~[T]], sep: &T) -> ~[T] {
|
pub pure fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] {
|
||||||
let mut r: ~[T] = ~[];
|
let mut r: ~[T] = ~[];
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for each(v) |inner| {
|
for each(v) |inner| {
|
||||||
|
@ -1060,13 +1060,13 @@ pub pure fn all2<T, U>(v0: &[T], v1: &[U],
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if a vector contains an element with the given value
|
/// Return true if a vector contains an element with the given value
|
||||||
pub pure fn contains<T: Eq>(v: &[T], x: &T) -> bool {
|
pub pure fn contains<T:Eq>(v: &[T], x: &T) -> bool {
|
||||||
for each(v) |elt| { if *x == *elt { return true; } }
|
for each(v) |elt| { if *x == *elt { return true; } }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of elements that are equal to a given value
|
/// Returns the number of elements that are equal to a given value
|
||||||
pub pure fn count<T: Eq>(v: &[T], x: &T) -> uint {
|
pub pure fn count<T:Eq>(v: &[T], x: &T) -> uint {
|
||||||
let mut cnt = 0u;
|
let mut cnt = 0u;
|
||||||
for each(v) |elt| { if *x == *elt { cnt += 1u; } }
|
for each(v) |elt| { if *x == *elt { cnt += 1u; } }
|
||||||
return cnt;
|
return cnt;
|
||||||
|
@ -1079,7 +1079,7 @@ pub pure fn count<T: Eq>(v: &[T], x: &T) -> uint {
|
||||||
* When function `f` returns true then an option containing the element
|
* When function `f` returns true then an option containing the element
|
||||||
* is returned. If `f` matches no elements then none is returned.
|
* is returned. If `f` matches no elements then none is returned.
|
||||||
*/
|
*/
|
||||||
pub pure fn find<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
|
pub pure fn find<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
|
||||||
find_between(v, 0u, len(v), f)
|
find_between(v, 0u, len(v), f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1090,7 +1090,7 @@ pub pure fn find<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
|
||||||
* [`start`, `end`). When function `f` returns true then an option containing
|
* [`start`, `end`). When function `f` returns true then an option containing
|
||||||
* the element is returned. If `f` matches no elements then none is returned.
|
* the element is returned. If `f` matches no elements then none is returned.
|
||||||
*/
|
*/
|
||||||
pub pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint,
|
pub pure fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
|
||||||
f: fn(t: &T) -> bool) -> Option<T> {
|
f: fn(t: &T) -> bool) -> Option<T> {
|
||||||
position_between(v, start, end, f).map(|i| v[*i])
|
position_between(v, start, end, f).map(|i| v[*i])
|
||||||
}
|
}
|
||||||
|
@ -1102,7 +1102,7 @@ pub pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint,
|
||||||
* `f` returns true then an option containing the element is returned. If `f`
|
* `f` returns true then an option containing the element is returned. If `f`
|
||||||
* matches no elements then none is returned.
|
* matches no elements then none is returned.
|
||||||
*/
|
*/
|
||||||
pub pure fn rfind<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
|
pub pure fn rfind<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
|
||||||
rfind_between(v, 0u, len(v), f)
|
rfind_between(v, 0u, len(v), f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1113,13 +1113,13 @@ pub pure fn rfind<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
|
||||||
* [`start`, `end`). When function `f` returns true then an option containing
|
* [`start`, `end`). When function `f` returns true then an option containing
|
||||||
* the element is returned. If `f` matches no elements then none is return.
|
* the element is returned. If `f` matches no elements then none is return.
|
||||||
*/
|
*/
|
||||||
pub pure fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint,
|
pub pure fn rfind_between<T:Copy>(v: &[T], start: uint, end: uint,
|
||||||
f: fn(t: &T) -> bool) -> Option<T> {
|
f: fn(t: &T) -> bool) -> Option<T> {
|
||||||
rposition_between(v, start, end, f).map(|i| v[*i])
|
rposition_between(v, start, end, f).map(|i| v[*i])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the first index containing a matching value
|
/// Find the first index containing a matching value
|
||||||
pub pure fn position_elem<T: Eq>(v: &[T], x: &T) -> Option<uint> {
|
pub pure fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
|
||||||
position(v, |y| *x == *y)
|
position(v, |y| *x == *y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1151,7 +1151,7 @@ pub pure fn position_between<T>(v: &[T], start: uint, end: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the last index containing a matching value
|
/// Find the last index containing a matching value
|
||||||
pure fn rposition_elem<T: Eq>(v: &[T], x: &T) -> Option<uint> {
|
pure fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
|
||||||
rposition(v, |y| *x == *y)
|
rposition(v, |y| *x == *y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1193,7 +1193,7 @@ pub pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
|
||||||
/**
|
/**
|
||||||
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
|
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
|
||||||
*/
|
*/
|
||||||
pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
pure fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
||||||
let mut ts = ~[], us = ~[];
|
let mut ts = ~[], us = ~[];
|
||||||
for each(v) |p| {
|
for each(v) |p| {
|
||||||
let (t, u) = *p;
|
let (t, u) = *p;
|
||||||
|
@ -1228,7 +1228,7 @@ pub pure fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
|
||||||
/**
|
/**
|
||||||
* Convert two vectors to a vector of pairs, by reference. As zip().
|
* Convert two vectors to a vector of pairs, by reference. As zip().
|
||||||
*/
|
*/
|
||||||
pub pure fn zip_slice<T: Copy, U: Copy>(v: &[const T], u: &[const U])
|
pub pure fn zip_slice<T:Copy,U:Copy>(v: &[const T], u: &[const U])
|
||||||
-> ~[(T, U)] {
|
-> ~[(T, U)] {
|
||||||
let mut zipped = ~[];
|
let mut zipped = ~[];
|
||||||
let sz = len(v);
|
let sz = len(v);
|
||||||
|
@ -1279,7 +1279,7 @@ pub fn reverse<T>(v: &mut [T]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a vector with the order of elements reversed
|
/// Returns a vector with the order of elements reversed
|
||||||
pub pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
|
pub pure fn reversed<T:Copy>(v: &[const T]) -> ~[T] {
|
||||||
let mut rs: ~[T] = ~[];
|
let mut rs: ~[T] = ~[];
|
||||||
let mut i = len::<T>(v);
|
let mut i = len::<T>(v);
|
||||||
if i == 0 { return (rs); } else { i -= 1; }
|
if i == 0 { return (rs); } else { i -= 1; }
|
||||||
|
@ -1445,7 +1445,7 @@ pub fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
|
||||||
* The total number of permutations produced is `len(v)!`. If `v` contains
|
* The total number of permutations produced is `len(v)!`. If `v` contains
|
||||||
* repeated elements, then some permutations are repeated.
|
* repeated elements, then some permutations are repeated.
|
||||||
*/
|
*/
|
||||||
pure fn each_permutation<T: Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
|
pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
|
||||||
let ln = len(v);
|
let ln = len(v);
|
||||||
if ln <= 1 {
|
if ln <= 1 {
|
||||||
put(v);
|
put(v);
|
||||||
|
@ -1469,7 +1469,7 @@ pure fn each_permutation<T: Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
pub pure fn windowed<TT:Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
||||||
let mut ww = ~[];
|
let mut ww = ~[];
|
||||||
assert 1u <= nn;
|
assert 1u <= nn;
|
||||||
for vec::eachi (xx) |ii, _x| {
|
for vec::eachi (xx) |ii, _x| {
|
||||||
|
@ -1536,7 +1536,7 @@ pub pure fn as_mut_buf<T,U>(s: &mut [T],
|
||||||
|
|
||||||
// Equality
|
// Equality
|
||||||
|
|
||||||
pure fn eq<T: Eq>(a: &[T], b: &[T]) -> bool {
|
pure fn eq<T:Eq>(a: &[T], b: &[T]) -> bool {
|
||||||
let (a_len, b_len) = (a.len(), b.len());
|
let (a_len, b_len) = (a.len(), b.len());
|
||||||
if a_len != b_len { return false; }
|
if a_len != b_len { return false; }
|
||||||
|
|
||||||
|
@ -1550,7 +1550,7 @@ pure fn eq<T: Eq>(a: &[T], b: &[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: & &self/[T]) -> bool { eq((*self), (*other)) }
|
pure fn eq(&self, other: & &self/[T]) -> bool { eq((*self), (*other)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1559,7 +1559,7 @@ impl<T: Eq> Eq for &[T] {
|
||||||
|
|
||||||
|
|
||||||
#[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 { eq((*self), (*other)) }
|
pure fn eq(&self, other: &~[T]) -> bool { eq((*self), (*other)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1567,7 +1567,7 @@ impl<T: Eq> Eq for ~[T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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 { eq((*self), (*other)) }
|
pure fn eq(&self, other: &@[T]) -> bool { eq((*self), (*other)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1576,7 +1576,7 @@ impl<T: Eq> Eq for @[T] {
|
||||||
|
|
||||||
// Lexicographical comparison
|
// Lexicographical comparison
|
||||||
|
|
||||||
pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
|
pure fn lt<T:Ord>(a: &[T], b: &[T]) -> bool {
|
||||||
let (a_len, b_len) = (a.len(), b.len());
|
let (a_len, b_len) = (a.len(), b.len());
|
||||||
let mut end = uint::min(a_len, b_len);
|
let mut end = uint::min(a_len, b_len);
|
||||||
|
|
||||||
|
@ -1591,12 +1591,12 @@ pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
|
||||||
return a_len < b_len;
|
return a_len < b_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn le<T: Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
|
pure fn le<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
|
||||||
pure fn ge<T: Ord>(a: &[T], b: &[T]) -> bool { !lt(a, b) }
|
pure fn ge<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(a, b) }
|
||||||
pure fn gt<T: Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) }
|
pure fn gt<T:Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) }
|
||||||
|
|
||||||
#[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: & &self/[T]) -> bool { lt((*self), (*other)) }
|
pure fn lt(&self, other: & &self/[T]) -> bool { lt((*self), (*other)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1608,7 +1608,7 @@ impl<T: Ord> Ord for &[T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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 { lt((*self), (*other)) }
|
pure fn lt(&self, other: &~[T]) -> bool { lt((*self), (*other)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1620,7 +1620,7 @@ impl<T: Ord> Ord for ~[T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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 { lt((*self), (*other)) }
|
pure fn lt(&self, other: &@[T]) -> bool { lt((*self), (*other)) }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1637,7 +1637,7 @@ pub mod traits {
|
||||||
use ops::Add;
|
use ops::Add;
|
||||||
use vec::append;
|
use vec::append;
|
||||||
|
|
||||||
impl<T: Copy> Add<&[const T],~[T]> for ~[T] {
|
impl<T:Copy> Add<&[const T],~[T]> for ~[T] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn add(&self, rhs: & &self/[const T]) -> ~[T] {
|
pure fn add(&self, rhs: & &self/[const T]) -> ~[T] {
|
||||||
append(copy *self, (*rhs))
|
append(copy *self, (*rhs))
|
||||||
|
@ -1664,7 +1664,7 @@ pub trait CopyableVector<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for vectors
|
/// Extension methods for vectors
|
||||||
impl<T: Copy> CopyableVector<T> for &[const T] {
|
impl<T:Copy> CopyableVector<T> for &[const T] {
|
||||||
/// Returns the first element of a vector
|
/// Returns the first element of a vector
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn head(&self) -> T { head(*self) }
|
pure fn head(&self) -> T { head(*self) }
|
||||||
|
@ -1690,13 +1690,13 @@ impl<T: Copy> CopyableVector<T> for &[const T] {
|
||||||
|
|
||||||
pub trait ImmutableVector<T> {
|
pub trait ImmutableVector<T> {
|
||||||
pure fn view(&self, start: uint, end: uint) -> &self/[T];
|
pure fn view(&self, start: uint, end: uint) -> &self/[T];
|
||||||
pure fn foldr<U: Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U;
|
pure fn foldr<U:Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U;
|
||||||
pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U];
|
pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U];
|
||||||
pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U];
|
pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U];
|
||||||
fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U];
|
fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U];
|
||||||
pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool;
|
pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool;
|
||||||
pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U];
|
pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U];
|
||||||
pure fn filter_mapped<U: Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U];
|
pure fn filter_mapped<U:Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for vectors
|
/// Extension methods for vectors
|
||||||
|
@ -1709,7 +1709,7 @@ impl<T> ImmutableVector<T> for &[T] {
|
||||||
|
|
||||||
/// Reduce a vector from right to left
|
/// Reduce a vector from right to left
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn foldr<U: Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U {
|
pure fn foldr<U:Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U {
|
||||||
foldr(*self, z, p)
|
foldr(*self, z, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1759,19 +1759,19 @@ impl<T> ImmutableVector<T> for &[T] {
|
||||||
* the resulting vector.
|
* the resulting vector.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn filter_mapped<U: Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U] {
|
pure fn filter_mapped<U:Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U] {
|
||||||
filter_mapped(*self, f)
|
filter_mapped(*self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ImmutableEqVector<T: Eq> {
|
pub trait ImmutableEqVector<T:Eq> {
|
||||||
pure fn position(&self, f: fn(t: &T) -> bool) -> Option<uint>;
|
pure fn position(&self, f: fn(t: &T) -> bool) -> Option<uint>;
|
||||||
pure fn position_elem(&self, t: &T) -> Option<uint>;
|
pure fn position_elem(&self, t: &T) -> Option<uint>;
|
||||||
pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option<uint>;
|
pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option<uint>;
|
||||||
pure fn rposition_elem(&self, t: &T) -> Option<uint>;
|
pure fn rposition_elem(&self, t: &T) -> Option<uint>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Eq> ImmutableEqVector<T> for &[T] {
|
impl<T:Eq> ImmutableEqVector<T> for &[T] {
|
||||||
/**
|
/**
|
||||||
* Find the first index matching some predicate
|
* Find the first index matching some predicate
|
||||||
*
|
*
|
||||||
|
@ -1816,7 +1816,7 @@ pub trait ImmutableCopyableVector<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for vectors
|
/// Extension methods for vectors
|
||||||
impl<T: Copy> ImmutableCopyableVector<T> for &[T] {
|
impl<T:Copy> ImmutableCopyableVector<T> for &[T] {
|
||||||
/**
|
/**
|
||||||
* Construct a new vector from the elements of a vector for which some
|
* Construct a new vector from the elements of a vector for which some
|
||||||
* predicate holds.
|
* predicate holds.
|
||||||
|
@ -1949,13 +1949,13 @@ impl<T> Mutable for ~[T] {
|
||||||
fn clear(&mut self) { self.truncate(0) }
|
fn clear(&mut self) { self.truncate(0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait OwnedCopyableVector<T: Copy> {
|
pub trait OwnedCopyableVector<T:Copy> {
|
||||||
fn push_all(&mut self, rhs: &[const T]);
|
fn push_all(&mut self, rhs: &[const T]);
|
||||||
fn grow(&mut self, n: uint, initval: &T);
|
fn grow(&mut self, n: uint, initval: &T);
|
||||||
fn grow_set(&mut self, index: uint, initval: &T, val: T);
|
fn grow_set(&mut self, index: uint, initval: &T, val: T);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> OwnedCopyableVector<T> for ~[T] {
|
impl<T:Copy> OwnedCopyableVector<T> for ~[T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn push_all(&mut self, rhs: &[const T]) {
|
fn push_all(&mut self, rhs: &[const T]) {
|
||||||
push_all(self, rhs);
|
push_all(self, rhs);
|
||||||
|
@ -1972,11 +1972,11 @@ impl<T: Copy> OwnedCopyableVector<T> for ~[T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait OwnedEqVector<T: Eq> {
|
trait OwnedEqVector<T:Eq> {
|
||||||
fn dedup(&mut self);
|
fn dedup(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Eq> OwnedEqVector<T> for ~[T] {
|
impl<T:Eq> OwnedEqVector<T> for ~[T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dedup(&mut self) {
|
fn dedup(&mut self) {
|
||||||
dedup(self)
|
dedup(self)
|
||||||
|
@ -2086,7 +2086,7 @@ pub mod raw {
|
||||||
* Unchecked vector indexing.
|
* Unchecked vector indexing.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn get<T: Copy>(v: &[const T], i: uint) -> T {
|
pub unsafe fn get<T:Copy>(v: &[const T], i: uint) -> T {
|
||||||
as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
|
as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2324,24 +2324,24 @@ impl<A> iter::ExtendedIter<A> for @[A] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Eq> iter::EqIter<A> for &[A] {
|
impl<A:Eq> iter::EqIter<A> for &[A] {
|
||||||
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||||
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#4148): This should be redundant
|
// FIXME(#4148): This should be redundant
|
||||||
impl<A: Eq> iter::EqIter<A> for ~[A] {
|
impl<A:Eq> iter::EqIter<A> for ~[A] {
|
||||||
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||||
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#4148): This should be redundant
|
// FIXME(#4148): This should be redundant
|
||||||
impl<A: Eq> iter::EqIter<A> for @[A] {
|
impl<A:Eq> iter::EqIter<A> for @[A] {
|
||||||
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||||
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy> iter::CopyableIter<A> for &[A] {
|
impl<A:Copy> iter::CopyableIter<A> for &[A] {
|
||||||
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
||||||
iter::filter_to_vec(self, pred)
|
iter::filter_to_vec(self, pred)
|
||||||
}
|
}
|
||||||
|
@ -2352,7 +2352,7 @@ impl<A: Copy> iter::CopyableIter<A> for &[A] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#4148): This should be redundant
|
// FIXME(#4148): This should be redundant
|
||||||
impl<A: Copy> iter::CopyableIter<A> for ~[A] {
|
impl<A:Copy> iter::CopyableIter<A> for ~[A] {
|
||||||
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
||||||
iter::filter_to_vec(self, pred)
|
iter::filter_to_vec(self, pred)
|
||||||
}
|
}
|
||||||
|
@ -2363,7 +2363,7 @@ impl<A: Copy> iter::CopyableIter<A> for ~[A] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#4148): This should be redundant
|
// FIXME(#4148): This should be redundant
|
||||||
impl<A: Copy> iter::CopyableIter<A> for @[A] {
|
impl<A:Copy> iter::CopyableIter<A> for @[A] {
|
||||||
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
|
||||||
iter::filter_to_vec(self, pred)
|
iter::filter_to_vec(self, pred)
|
||||||
}
|
}
|
||||||
|
@ -2373,19 +2373,19 @@ impl<A: Copy> iter::CopyableIter<A> for @[A] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Copy Ord> iter::CopyableOrderedIter<A> for &[A] {
|
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for &[A] {
|
||||||
pure fn min(&self) -> A { iter::min(self) }
|
pure fn min(&self) -> A { iter::min(self) }
|
||||||
pure fn max(&self) -> A { iter::max(self) }
|
pure fn max(&self) -> A { iter::max(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#4148): This should be redundant
|
// FIXME(#4148): This should be redundant
|
||||||
impl<A: Copy Ord> iter::CopyableOrderedIter<A> for ~[A] {
|
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for ~[A] {
|
||||||
pure fn min(&self) -> A { iter::min(self) }
|
pure fn min(&self) -> A { iter::min(self) }
|
||||||
pure fn max(&self) -> A { iter::max(self) }
|
pure fn max(&self) -> A { iter::max(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#4148): This should be redundant
|
// FIXME(#4148): This should be redundant
|
||||||
impl<A: Copy Ord> iter::CopyableOrderedIter<A> for @[A] {
|
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for @[A] {
|
||||||
pure fn min(&self) -> A { iter::min(self) }
|
pure fn min(&self) -> A { iter::min(self) }
|
||||||
pure fn max(&self) -> A { iter::max(self) }
|
pure fn max(&self) -> A { iter::max(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn under(r : rand::rng, n : uint) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
// random choice from a vec
|
// random choice from a vec
|
||||||
fn choice<T: copy>(r : rand::rng, v : ~[const T]) -> T {
|
fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T {
|
||||||
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
|
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,22 +32,22 @@ extern mod std;
|
||||||
use vec::slice;
|
use vec::slice;
|
||||||
use vec::len;
|
use vec::len;
|
||||||
|
|
||||||
fn vec_omit<T: copy>(v: ~[T], i: uint) -> ~[T] {
|
fn vec_omit<T:copy>(v: ~[T], i: uint) -> ~[T] {
|
||||||
slice(v, 0u, i) + slice(v, i + 1u, len(v))
|
slice(v, 0u, i) + slice(v, i + 1u, len(v))
|
||||||
}
|
}
|
||||||
fn vec_dup<T: copy>(v: ~[T], i: uint) -> ~[T] {
|
fn vec_dup<T:copy>(v: ~[T], i: uint) -> ~[T] {
|
||||||
slice(v, 0u, i) + [v[i]] + slice(v, i, len(v))
|
slice(v, 0u, i) + [v[i]] + slice(v, i, len(v))
|
||||||
}
|
}
|
||||||
fn vec_swadj<T: copy>(v: ~[T], i: uint) -> ~[T] {
|
fn vec_swadj<T:copy>(v: ~[T], i: uint) -> ~[T] {
|
||||||
slice(v, 0u, i) + [v[i + 1u], v[i]] + slice(v, i + 2u, len(v))
|
slice(v, 0u, i) + [v[i + 1u], v[i]] + slice(v, i + 2u, len(v))
|
||||||
}
|
}
|
||||||
fn vec_prefix<T: copy>(v: ~[T], i: uint) -> ~[T] { slice(v, 0u, i) }
|
fn vec_prefix<T:copy>(v: ~[T], i: uint) -> ~[T] { slice(v, 0u, i) }
|
||||||
fn vec_suffix<T: copy>(v: ~[T], i: uint) -> ~[T] { slice(v, i, len(v)) }
|
fn vec_suffix<T:copy>(v: ~[T], i: uint) -> ~[T] { slice(v, i, len(v)) }
|
||||||
|
|
||||||
fn vec_poke<T: copy>(v: ~[T], i: uint, x: T) -> ~[T] {
|
fn vec_poke<T:copy>(v: ~[T], i: uint, x: T) -> ~[T] {
|
||||||
slice(v, 0u, i) + ~[x] + slice(v, i + 1u, len(v))
|
slice(v, 0u, i) + ~[x] + slice(v, i + 1u, len(v))
|
||||||
}
|
}
|
||||||
fn vec_insert<T: copy>(v: ~[T], i: uint, x: T) -> ~[T] {
|
fn vec_insert<T:copy>(v: ~[T], i: uint, x: T) -> ~[T] {
|
||||||
slice(v, 0u, i) + ~[x] + slice(v, i, len(v))
|
slice(v, 0u, i) + ~[x] + slice(v, i, len(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ fn ix(skip_low: uint, skip_high: uint, length: uint, it: block(uint)) {
|
||||||
|
|
||||||
// Returns a bunch of modified versions of v, some of which introduce
|
// Returns a bunch of modified versions of v, some of which introduce
|
||||||
// new elements (borrowed from xs).
|
// new elements (borrowed from xs).
|
||||||
fn vec_edits<T: copy>(v: ~[T], xs: ~[T]) -> ~[~[T]] {
|
fn vec_edits<T:copy>(v: ~[T], xs: ~[T]) -> ~[~[T]] {
|
||||||
let edits: ~[~[T]] = ~[];
|
let edits: ~[~[T]] = ~[];
|
||||||
let Lv: uint = len(v);
|
let Lv: uint = len(v);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn under(r : rand::rng, n : uint) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
// random choice from a vec
|
// random choice from a vec
|
||||||
fn choice<T: copy>(r : rand::rng, v : ~[T]) -> T {
|
fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T {
|
||||||
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
|
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ fn shuffle<T>(r : rand::rng, &v : ~[T]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a shuffled copy of a vec
|
// create a shuffled copy of a vec
|
||||||
fn shuffled<T: copy>(r : rand::rng, v : ~[T]) -> ~[T] {
|
fn shuffled<T:copy>(r : rand::rng, v : ~[T]) -> ~[T] {
|
||||||
let w = vec::to_mut(v);
|
let w = vec::to_mut(v);
|
||||||
shuffle(r, w);
|
shuffle(r, w);
|
||||||
vec::from_mut(w) // Shouldn't this happen automatically?
|
vec::from_mut(w) // Shouldn't this happen automatically?
|
||||||
|
@ -48,7 +48,7 @@ fn shuffled<T: copy>(r : rand::rng, v : ~[T]) -> ~[T] {
|
||||||
// * weighted_choice is O(number of choices) time
|
// * weighted_choice is O(number of choices) time
|
||||||
// * weighted_vec is O(total weight) space
|
// * weighted_vec is O(total weight) space
|
||||||
type weighted<T> = { weight: uint, item: T };
|
type weighted<T> = { weight: uint, item: T };
|
||||||
fn weighted_choice<T: copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
|
fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
|
||||||
assert vec::len(v) != 0u;
|
assert vec::len(v) != 0u;
|
||||||
let total = 0u;
|
let total = 0u;
|
||||||
for {weight: weight, item: _} in v {
|
for {weight: weight, item: _} in v {
|
||||||
|
@ -66,7 +66,7 @@ fn weighted_choice<T: copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
|
||||||
core::unreachable();
|
core::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn weighted_vec<T: copy>(v : ~[weighted<T>]) -> ~[T] {
|
fn weighted_vec<T:copy>(v : ~[weighted<T>]) -> ~[T] {
|
||||||
let r = ~[];
|
let r = ~[];
|
||||||
for {weight: weight, item: item} in v {
|
for {weight: weight, item: item} in v {
|
||||||
let i = 0u;
|
let i = 0u;
|
||||||
|
|
|
@ -294,7 +294,7 @@ pub fn basic_options() -> @options {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seems out of place, but it uses session, so I'm putting it here
|
// Seems out of place, but it uses session, so I'm putting it here
|
||||||
pub fn expect<T: Copy>(sess: Session,
|
pub fn expect<T:Copy>(sess: Session,
|
||||||
opt: Option<T>,
|
opt: Option<T>,
|
||||||
msg: fn() -> ~str)
|
msg: fn() -> ~str)
|
||||||
-> T {
|
-> T {
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn use_core(crate: @ast::crate) -> bool {
|
||||||
|
|
||||||
fn inject_libcore_ref(sess: Session,
|
fn inject_libcore_ref(sess: Session,
|
||||||
crate: @ast::crate) -> @ast::crate {
|
crate: @ast::crate) -> @ast::crate {
|
||||||
fn spanned<T: Copy>(x: T) -> codemap::spanned<T> {
|
fn spanned<T:Copy>(x: T) -> codemap::spanned<T> {
|
||||||
codemap::spanned { node: x, span: dummy_sp() }
|
codemap::spanned { node: x, span: dummy_sp() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
|
||||||
return @item;
|
return @item;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nospan<T: Copy>(t: T) -> codemap::spanned<T> {
|
fn nospan<T:Copy>(t: T) -> codemap::spanned<T> {
|
||||||
codemap::spanned { node: t, span: dummy_sp() }
|
codemap::spanned { node: t, span: dummy_sp() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -969,7 +969,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||||
|
|
||||||
// Path and definition ID indexing
|
// Path and definition ID indexing
|
||||||
|
|
||||||
fn create_index<T: Copy Hash IterBytes>(index: ~[entry<T>]) ->
|
fn create_index<T:Copy + Hash + IterBytes>(index: ~[entry<T>]) ->
|
||||||
~[@~[entry<T>]] {
|
~[@~[entry<T>]] {
|
||||||
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
|
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
|
||||||
for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); };
|
for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); };
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>,
|
||||||
} as FileSearch
|
} as FileSearch
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search<T: Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> {
|
pub fn search<T:Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> {
|
||||||
let mut rslt = None;
|
let mut rslt = None;
|
||||||
for filesearch.lib_search_paths().each |lib_search_path| {
|
for filesearch.lib_search_paths().each |lib_search_path| {
|
||||||
debug!("searching %s", lib_search_path.to_str());
|
debug!("searching %s", lib_search_path.to_str());
|
||||||
|
|
|
@ -248,7 +248,7 @@ trait def_id_encoder_helpers {
|
||||||
fn emit_def_id(did: ast::def_id);
|
fn emit_def_id(did: ast::def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: serialize::Encoder> def_id_encoder_helpers for S {
|
impl<S:serialize::Encoder> def_id_encoder_helpers for S {
|
||||||
fn emit_def_id(did: ast::def_id) {
|
fn emit_def_id(did: ast::def_id) {
|
||||||
did.encode(&self)
|
did.encode(&self)
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ trait def_id_decoder_helpers {
|
||||||
fn read_def_id(xcx: @ExtendedDecodeContext) -> ast::def_id;
|
fn read_def_id(xcx: @ExtendedDecodeContext) -> ast::def_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: serialize::Decoder> def_id_decoder_helpers for D {
|
impl<D:serialize::Decoder> def_id_decoder_helpers for D {
|
||||||
|
|
||||||
fn read_def_id(xcx: @ExtendedDecodeContext) -> ast::def_id {
|
fn read_def_id(xcx: @ExtendedDecodeContext) -> ast::def_id {
|
||||||
let did: ast::def_id = Decodable::decode(&self);
|
let did: ast::def_id = Decodable::decode(&self);
|
||||||
|
@ -1276,14 +1276,14 @@ fn test_more() {
|
||||||
fn test_simplification() {
|
fn test_simplification() {
|
||||||
let ext_cx = mk_ctxt();
|
let ext_cx = mk_ctxt();
|
||||||
let item_in = ast::ii_item(quote_item!(
|
let item_in = ast::ii_item(quote_item!(
|
||||||
fn new_int_alist<B: Copy>() -> alist<int, B> {
|
fn new_int_alist<B:Copy>() -> alist<int, B> {
|
||||||
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return {eq_fn: eq_int, data: ~[]};
|
return {eq_fn: eq_int, data: ~[]};
|
||||||
}
|
}
|
||||||
).get());
|
).get());
|
||||||
let item_out = simplify_ast(item_in);
|
let item_out = simplify_ast(item_in);
|
||||||
let item_exp = ast::ii_item(quote_item!(
|
let item_exp = ast::ii_item(quote_item!(
|
||||||
fn new_int_alist<B: Copy>() -> alist<int, B> {
|
fn new_int_alist<B:Copy>() -> alist<int, B> {
|
||||||
return {eq_fn: eq_int, data: ~[]};
|
return {eq_fn: eq_int, data: ~[]};
|
||||||
}
|
}
|
||||||
).get());
|
).get());
|
||||||
|
|
|
@ -491,7 +491,7 @@ pub impl BorrowckCtxt {
|
||||||
cat_def(self.tcx, self.method_map, id, span, ty, def)
|
cat_def(self.tcx, self.method_map, id, span, ty, def)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_variant<N: ast_node>(&self,
|
fn cat_variant<N:ast_node>(&self,
|
||||||
arg: N,
|
arg: N,
|
||||||
enum_did: ast::def_id,
|
enum_did: ast::def_id,
|
||||||
cmt: cmt) -> cmt {
|
cmt: cmt) -> cmt {
|
||||||
|
|
|
@ -526,7 +526,7 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
|
fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
|
||||||
pure fn is_valid<T: cmp::Ord>(binop: ast::binop, v: T,
|
pure fn is_valid<T:cmp::Ord>(binop: ast::binop, v: T,
|
||||||
min: T, max: T) -> bool {
|
min: T, max: T) -> bool {
|
||||||
match binop {
|
match binop {
|
||||||
ast::lt => v <= max,
|
ast::lt => v <= max,
|
||||||
|
|
|
@ -263,7 +263,7 @@ pub fn cat_def(
|
||||||
return mcx.cat_def(expr_id, expr_span, expr_ty, def);
|
return mcx.cat_def(expr_id, expr_span, expr_ty, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_variant<N: ast_node>(
|
pub fn cat_variant<N:ast_node>(
|
||||||
tcx: ty::ctxt,
|
tcx: ty::ctxt,
|
||||||
method_map: typeck::method_map,
|
method_map: typeck::method_map,
|
||||||
arg: N,
|
arg: N,
|
||||||
|
@ -292,11 +292,11 @@ pub impl ast_node for @ast::pat {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait get_type_for_node {
|
pub trait get_type_for_node {
|
||||||
fn ty<N: ast_node>(node: N) -> ty::t;
|
fn ty<N:ast_node>(node: N) -> ty::t;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl get_type_for_node for ty::ctxt {
|
pub impl get_type_for_node for ty::ctxt {
|
||||||
fn ty<N: ast_node>(node: N) -> ty::t {
|
fn ty<N:ast_node>(node: N) -> ty::t {
|
||||||
ty::node_id_to_type(self, node.id())
|
ty::node_id_to_type(self, node.id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,7 +575,7 @@ pub impl mem_categorization_ctxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_variant<N: ast_node>(&self,
|
fn cat_variant<N:ast_node>(&self,
|
||||||
arg: N,
|
arg: N,
|
||||||
enum_did: ast::def_id,
|
enum_did: ast::def_id,
|
||||||
cmt: cmt) -> cmt {
|
cmt: cmt) -> cmt {
|
||||||
|
@ -589,7 +589,7 @@ pub impl mem_categorization_ctxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_rvalue<N: ast_node>(&self, elt: N, expr_ty: ty::t) -> cmt {
|
fn cat_rvalue<N:ast_node>(&self, elt: N, expr_ty: ty::t) -> cmt {
|
||||||
@cmt_ {
|
@cmt_ {
|
||||||
id:elt.id(),
|
id:elt.id(),
|
||||||
span:elt.span(),
|
span:elt.span(),
|
||||||
|
@ -739,7 +739,7 @@ pub impl mem_categorization_ctxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_index<N: ast_node>(&self,
|
fn cat_index<N:ast_node>(&self,
|
||||||
elt: N,
|
elt: N,
|
||||||
base_cmt: cmt) -> cmt {
|
base_cmt: cmt) -> cmt {
|
||||||
let mt = match ty::index(self.tcx, base_cmt.ty) {
|
let mt = match ty::index(self.tcx, base_cmt.ty) {
|
||||||
|
@ -792,7 +792,7 @@ pub impl mem_categorization_ctxt {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn comp<N: ast_node>(elt: N, of_cmt: cmt,
|
fn comp<N:ast_node>(elt: N, of_cmt: cmt,
|
||||||
vect: ty::t, mutbl: MutabilityCategory,
|
vect: ty::t, mutbl: MutabilityCategory,
|
||||||
mt: ty::mt) -> cmt
|
mt: ty::mt) -> cmt
|
||||||
{
|
{
|
||||||
|
@ -809,7 +809,7 @@ pub impl mem_categorization_ctxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_tuple_elt<N: ast_node>(&self,
|
fn cat_tuple_elt<N:ast_node>(&self,
|
||||||
elt: N,
|
elt: N,
|
||||||
cmt: cmt) -> cmt {
|
cmt: cmt) -> cmt {
|
||||||
@cmt_ {
|
@cmt_ {
|
||||||
|
@ -822,7 +822,7 @@ pub impl mem_categorization_ctxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_anon_struct_field<N: ast_node>(&self,
|
fn cat_anon_struct_field<N:ast_node>(&self,
|
||||||
elt: N,
|
elt: N,
|
||||||
cmt: cmt) -> cmt {
|
cmt: cmt) -> cmt {
|
||||||
@cmt_ {
|
@cmt_ {
|
||||||
|
|
|
@ -170,7 +170,7 @@ enum debug_metadata {
|
||||||
retval_metadata(@Metadata<RetvalMetadata>),
|
retval_metadata(@Metadata<RetvalMetadata>),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cast_safely<T: Copy, U>(val: T) -> U {
|
fn cast_safely<T:Copy,U>(val: T) -> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
let val2 = val;
|
let val2 = val;
|
||||||
return cast::transmute(val2);
|
return cast::transmute(val2);
|
||||||
|
@ -192,7 +192,7 @@ fn md_from_metadata<T>(val: debug_metadata) -> T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_metadata<T: Copy>(cache: metadata_cache,
|
fn cached_metadata<T:Copy>(cache: metadata_cache,
|
||||||
mdtag: int,
|
mdtag: int,
|
||||||
eq_fn: fn(md: T) -> bool)
|
eq_fn: fn(md: T) -> bool)
|
||||||
-> Option<T> {
|
-> Option<T> {
|
||||||
|
|
|
@ -775,7 +775,7 @@ fn mk_rcache() -> creader_cache {
|
||||||
return oldmap::HashMap();
|
return oldmap::HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_ty_hash<V: Copy>() -> oldmap::HashMap<t, V> {
|
pub fn new_ty_hash<V:Copy>() -> oldmap::HashMap<t, V> {
|
||||||
oldmap::HashMap()
|
oldmap::HashMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3326,7 +3326,7 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) {
|
||||||
|
|
||||||
// Maintains a little union-set tree for inferred modes. `canon()` returns
|
// Maintains a little union-set tree for inferred modes. `canon()` returns
|
||||||
// the current head value for `m0`.
|
// the current head value for `m0`.
|
||||||
fn canon<T:Copy cmp::Eq>(tbl: HashMap<ast::node_id, ast::inferable<T>>,
|
fn canon<T:Copy + cmp::Eq>(tbl: HashMap<ast::node_id, ast::inferable<T>>,
|
||||||
+m0: ast::inferable<T>) -> ast::inferable<T> {
|
+m0: ast::inferable<T>) -> ast::inferable<T> {
|
||||||
match m0 {
|
match m0 {
|
||||||
ast::infer(id) => match tbl.find(&id) {
|
ast::infer(id) => match tbl.find(&id) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ pub fn get_region_reporting_err(tcx: ty::ctxt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ast_region_to_region<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
span: span,
|
span: span,
|
||||||
|
@ -110,7 +110,7 @@ pub fn ast_region_to_region<AC: AstConv, RS: region_scope Copy Durable>(
|
||||||
get_region_reporting_err(self.tcx(), span, res)
|
get_region_reporting_err(self.tcx(), span, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ast_path_to_substs_and_ty<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
did: ast::def_id,
|
did: ast::def_id,
|
||||||
|
@ -166,7 +166,7 @@ pub fn ast_path_to_substs_and_ty<AC: AstConv, RS: region_scope Copy Durable>(
|
||||||
ty_param_substs_and_ty { substs: substs, ty: ty }
|
ty_param_substs_and_ty { substs: substs, ty: ty }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ast_path_to_ty<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ast_path_to_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
did: ast::def_id,
|
did: ast::def_id,
|
||||||
|
@ -192,10 +192,10 @@ pub const NO_TPS: uint = 2;
|
||||||
// Parses the programmer's textual representation of a type into our
|
// Parses the programmer's textual representation of a type into our
|
||||||
// internal notion of a type. `getter` is a function that returns the type
|
// internal notion of a type. `getter` is a function that returns the type
|
||||||
// corresponding to a definition ID:
|
// corresponding to a definition ID:
|
||||||
pub fn ast_ty_to_ty<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ast_ty_to_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC, rscope: RS, &&ast_ty: @ast::Ty) -> ty::t {
|
self: @mut AC, rscope: RS, &&ast_ty: @ast::Ty) -> ty::t {
|
||||||
|
|
||||||
fn ast_mt_to_mt<AC: AstConv, RS: region_scope Copy Durable>(
|
fn ast_mt_to_mt<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC, rscope: RS, mt: ast::mt) -> ty::mt {
|
self: @mut AC, rscope: RS, mt: ast::mt) -> ty::mt {
|
||||||
|
|
||||||
ty::mt {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl}
|
ty::mt {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl}
|
||||||
|
@ -204,7 +204,7 @@ pub fn ast_ty_to_ty<AC: AstConv, RS: region_scope Copy Durable>(
|
||||||
// Handle @, ~, and & being able to mean estrs and evecs.
|
// Handle @, ~, and & being able to mean estrs and evecs.
|
||||||
// If a_seq_ty is a str or a vec, make it an estr/evec.
|
// If a_seq_ty is a str or a vec, make it an estr/evec.
|
||||||
// Also handle function sigils and first-class trait types.
|
// Also handle function sigils and first-class trait types.
|
||||||
fn mk_pointer<AC: AstConv, RS: region_scope Copy Durable>(
|
fn mk_pointer<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
a_seq_ty: ast::mt,
|
a_seq_ty: ast::mt,
|
||||||
|
@ -420,7 +420,7 @@ pub fn ast_ty_to_ty<AC: AstConv, RS: region_scope Copy Durable>(
|
||||||
return typ;
|
return typ;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ty_of_arg<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ty_of_arg<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
a: ast::arg,
|
a: ast::arg,
|
||||||
|
@ -468,7 +468,7 @@ pub fn ty_of_arg<AC: AstConv, RS: region_scope Copy Durable>(
|
||||||
arg {mode: mode, ty: ty}
|
arg {mode: mode, ty: ty}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ty_of_bare_fn<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
purity: ast::purity,
|
purity: ast::purity,
|
||||||
|
@ -494,7 +494,7 @@ pub fn ty_of_bare_fn<AC: AstConv, RS: region_scope Copy Durable>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ty_of_closure<AC: AstConv, RS: region_scope Copy Durable>(
|
pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
|
||||||
self: @mut AC,
|
self: @mut AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
sigil: ast::Sigil,
|
sigil: ast::Sigil,
|
||||||
|
|
|
@ -1590,7 +1590,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||||
// through the `unpack` function. It there is no expected type or
|
// through the `unpack` function. It there is no expected type or
|
||||||
// resolution is not possible (e.g., no constraints yet present), just
|
// resolution is not possible (e.g., no constraints yet present), just
|
||||||
// returns `none`.
|
// returns `none`.
|
||||||
fn unpack_expected<O: Copy>(fcx: @mut FnCtxt,
|
fn unpack_expected<O:Copy>(fcx: @mut FnCtxt,
|
||||||
expected: Option<ty::t>,
|
expected: Option<ty::t>,
|
||||||
unpack: fn(&ty::sty) -> Option<O>)
|
unpack: fn(&ty::sty) -> Option<O>)
|
||||||
-> Option<O> {
|
-> Option<O> {
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl @mut CrateCtxt {
|
pub impl @mut CrateCtxt {
|
||||||
fn to_ty<RS: region_scope Copy Durable>(rs: RS, ast_ty: @ast::Ty)
|
fn to_ty<RS:region_scope + Copy + Durable>(rs: RS, ast_ty: @ast::Ty)
|
||||||
-> ty::t {
|
-> ty::t {
|
||||||
ast_ty_to_ty(self, rs, ast_ty)
|
ast_ty_to_ty(self, rs, ast_ty)
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,7 +290,7 @@ pub fn super_self_tys<C:Combine>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn super_sigils<C: Combine>(
|
pub fn super_sigils<C:Combine>(
|
||||||
self: &C, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> {
|
self: &C, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> {
|
||||||
if p1 == p2 {
|
if p1 == p2 {
|
||||||
Ok(p1)
|
Ok(p1)
|
||||||
|
|
|
@ -173,7 +173,7 @@ pub impl CombineFields {
|
||||||
b_id, a_bounds, b_bounds, node_b.rank)
|
b_id, a_bounds, b_bounds, node_b.rank)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_bnd<T:Copy InferStr LatticeValue>(
|
fn merge_bnd<T:Copy + InferStr + LatticeValue>(
|
||||||
&self,
|
&self,
|
||||||
a: &Bound<T>,
|
a: &Bound<T>,
|
||||||
b: &Bound<T>,
|
b: &Bound<T>,
|
||||||
|
@ -263,7 +263,7 @@ pub impl CombineFields {
|
||||||
uok()
|
uok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bnds<T:Copy InferStr LatticeValue>(
|
fn bnds<T:Copy + InferStr + LatticeValue>(
|
||||||
&self,
|
&self,
|
||||||
a: &Bound<T>,
|
a: &Bound<T>,
|
||||||
b: &Bound<T>) -> ures
|
b: &Bound<T>) -> ures
|
||||||
|
@ -329,7 +329,7 @@ pub impl TyLatticeDir for Glb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn super_lattice_tys<L:LatticeDir TyLatticeDir Combine>(
|
pub fn super_lattice_tys<L:LatticeDir + TyLatticeDir + Combine>(
|
||||||
self: &L,
|
self: &L,
|
||||||
a: ty::t,
|
a: ty::t,
|
||||||
b: ty::t) -> cres<ty::t> {
|
b: ty::t) -> cres<ty::t> {
|
||||||
|
@ -485,7 +485,7 @@ pub fn lattice_var_and_t<L:LatticeDir Combine,
|
||||||
// Random utility functions used by LUB/GLB when computing LUB/GLB of
|
// Random utility functions used by LUB/GLB when computing LUB/GLB of
|
||||||
// fn types
|
// fn types
|
||||||
|
|
||||||
pub fn var_ids<T: Combine>(self: &T, isr: isr_alist) -> ~[RegionVid] {
|
pub fn var_ids<T:Combine>(self: &T, isr: isr_alist) -> ~[RegionVid] {
|
||||||
let mut result = ~[];
|
let mut result = ~[];
|
||||||
for list::each(isr) |pair| {
|
for list::each(isr) |pair| {
|
||||||
match pair.second() {
|
match pair.second() {
|
||||||
|
|
|
@ -351,7 +351,7 @@ pub fn fixup_err_to_str(f: fixup_err) -> ~str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_ValsAndBindings<V:Copy, T:Copy>() -> ValsAndBindings<V, T> {
|
fn new_ValsAndBindings<V:Copy,T:Copy>() -> ValsAndBindings<V, T> {
|
||||||
ValsAndBindings {
|
ValsAndBindings {
|
||||||
vals: oldsmallintmap::mk(),
|
vals: oldsmallintmap::mk(),
|
||||||
bindings: ~[]
|
bindings: ~[]
|
||||||
|
@ -517,7 +517,7 @@ trait CresCompare<T> {
|
||||||
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T>;
|
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Copy Eq> CresCompare<T> for cres<T> {
|
impl<T:Copy + Eq> CresCompare<T> for cres<T> {
|
||||||
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T> {
|
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T> {
|
||||||
do self.chain |s| {
|
do self.chain |s| {
|
||||||
if s == t {
|
if s == t {
|
||||||
|
@ -533,7 +533,7 @@ pub fn uok() -> ures {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rollback_to<V:Copy Vid, T:Copy>(
|
fn rollback_to<V:Copy + Vid,T:Copy>(
|
||||||
vb: &mut ValsAndBindings<V, T>,
|
vb: &mut ValsAndBindings<V, T>,
|
||||||
len: uint)
|
len: uint)
|
||||||
{
|
{
|
||||||
|
@ -632,7 +632,7 @@ impl @mut InferCtxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_simple_var<V: Copy,T: Copy>(
|
fn next_simple_var<V:Copy,T:Copy>(
|
||||||
+counter: &mut uint,
|
+counter: &mut uint,
|
||||||
+bindings: &mut ValsAndBindings<V,Option<T>>)
|
+bindings: &mut ValsAndBindings<V,Option<T>>)
|
||||||
-> uint {
|
-> uint {
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub impl<T:InferStr> InferStr for Bounds<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<V:Vid ToStr, T:InferStr> InferStr for VarValue<V, T> {
|
pub impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
|
||||||
fn inf_str(&self, cx: &InferCtxt) -> ~str {
|
fn inf_str(&self, cx: &InferCtxt) -> ~str {
|
||||||
match *self {
|
match *self {
|
||||||
Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()),
|
Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()),
|
||||||
|
|
|
@ -89,7 +89,7 @@ pub impl InferCtxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set<T:Copy InferStr, V:Copy Vid ToStr UnifyVid<T>>(
|
fn set<T:Copy + InferStr,V:Copy + Vid + ToStr + UnifyVid<T>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
+vid: V,
|
+vid: V,
|
||||||
+new_v: VarValue<V, T>) {
|
+new_v: VarValue<V, T>) {
|
||||||
|
@ -109,7 +109,7 @@ pub impl InferCtxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unify<T:Copy InferStr, V:Copy Vid ToStr UnifyVid<T>>(
|
fn unify<T:Copy + InferStr,V:Copy + Vid + ToStr + UnifyVid<T>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
node_a: &Node<V, T>,
|
node_a: &Node<V, T>,
|
||||||
node_b: &Node<V, T>) -> (V, uint)
|
node_b: &Node<V, T>) -> (V, uint)
|
||||||
|
@ -150,7 +150,7 @@ pub trait SimplyUnifiable {
|
||||||
static fn to_type_err(expected_found<Self>) -> ty::type_err;
|
static fn to_type_err(expected_found<Self>) -> ty::type_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_err<T: SimplyUnifiable>(+a_is_expected: bool,
|
pub fn mk_err<T:SimplyUnifiable>(+a_is_expected: bool,
|
||||||
+a_t: T,
|
+a_t: T,
|
||||||
+b_t: T) -> ures {
|
+b_t: T) -> ures {
|
||||||
if a_is_expected {
|
if a_is_expected {
|
||||||
|
|
|
@ -157,7 +157,7 @@ pub enum vtable_origin {
|
||||||
vtable_static(ast::def_id, ~[ty::t], vtable_res),
|
vtable_static(ast::def_id, ~[ty::t], vtable_res),
|
||||||
/*
|
/*
|
||||||
Dynamic vtable, comes from a parameter that has a bound on it:
|
Dynamic vtable, comes from a parameter that has a bound on it:
|
||||||
fn foo<T: quux, baz, bar>(a: T) -- a's vtable would have a
|
fn foo<T:quux,baz,bar>(a: T) -- a's vtable would have a
|
||||||
vtable_param origin
|
vtable_param origin
|
||||||
|
|
||||||
The first uint is the param number (identifying T in the example),
|
The first uint is the param number (identifying T in the example),
|
||||||
|
|
|
@ -69,9 +69,10 @@ pub fn bound_self_region(rp: Option<ty::region_variance>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct anon_rscope { anon: ty::Region, base: region_scope }
|
pub struct anon_rscope { anon: ty::Region, base: region_scope }
|
||||||
pub fn in_anon_rscope<RS: region_scope Copy Durable>(self: RS, r: ty::Region)
|
pub fn in_anon_rscope<RS:region_scope + Copy + Durable>(self: RS,
|
||||||
|
r: ty::Region)
|
||||||
-> @anon_rscope {
|
-> @anon_rscope {
|
||||||
@anon_rscope { anon: r, base: self as region_scope }
|
@anon_rscope {anon: r, base: self as region_scope}
|
||||||
}
|
}
|
||||||
pub impl region_scope for @anon_rscope {
|
pub impl region_scope for @anon_rscope {
|
||||||
pure fn anon_region(_span: span) -> Result<ty::Region, ~str> {
|
pure fn anon_region(_span: span) -> Result<ty::Region, ~str> {
|
||||||
|
@ -91,7 +92,7 @@ pub struct binding_rscope {
|
||||||
anon_bindings: uint,
|
anon_bindings: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn in_binding_rscope<RS: region_scope Copy Durable>(self: RS)
|
pub fn in_binding_rscope<RS:region_scope + Copy + Durable>(self: RS)
|
||||||
-> @mut binding_rscope {
|
-> @mut binding_rscope {
|
||||||
let base = self as region_scope;
|
let base = self as region_scope;
|
||||||
@mut binding_rscope { base: base, anon_bindings: 0 }
|
@mut binding_rscope { base: base, anon_bindings: 0 }
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub struct Fold<T> {
|
||||||
fold_struct: FoldStruct<T>
|
fold_struct: FoldStruct<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone> Clone for Fold<T> {
|
impl<T:Clone> Clone for Fold<T> {
|
||||||
fn clone(&self) -> Fold<T> {
|
fn clone(&self) -> Fold<T> {
|
||||||
Fold {
|
Fold {
|
||||||
ctxt: self.ctxt.clone(),
|
ctxt: self.ctxt.clone(),
|
||||||
|
@ -103,7 +103,7 @@ fn mk_fold<T>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_any_fold<T: Clone>(ctxt: T) -> Fold<T> {
|
pub fn default_any_fold<T:Clone>(ctxt: T) -> Fold<T> {
|
||||||
mk_fold(
|
mk_fold(
|
||||||
ctxt,
|
ctxt,
|
||||||
|f, d| default_seq_fold_doc(f, d),
|
|f, d| default_seq_fold_doc(f, d),
|
||||||
|
@ -121,7 +121,7 @@ pub fn default_any_fold<T: Clone>(ctxt: T) -> Fold<T> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_seq_fold<T: Clone>(ctxt: T) -> Fold<T> {
|
pub fn default_seq_fold<T:Clone>(ctxt: T) -> Fold<T> {
|
||||||
mk_fold(
|
mk_fold(
|
||||||
ctxt,
|
ctxt,
|
||||||
|f, d| default_seq_fold_doc(f, d),
|
|f, d| default_seq_fold_doc(f, d),
|
||||||
|
@ -139,7 +139,7 @@ pub fn default_seq_fold<T: Clone>(ctxt: T) -> Fold<T> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_par_fold<T: Clone>(ctxt: T) -> Fold<T> {
|
pub fn default_par_fold<T:Clone>(ctxt: T) -> Fold<T> {
|
||||||
mk_fold(
|
mk_fold(
|
||||||
ctxt,
|
ctxt,
|
||||||
|f, d| default_seq_fold_doc(f, d),
|
|f, d| default_seq_fold_doc(f, d),
|
||||||
|
|
|
@ -17,6 +17,6 @@ pub struct NominalOp<T> {
|
||||||
op: T
|
op: T
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> Clone for NominalOp<T> {
|
impl<T:Copy> Clone for NominalOp<T> {
|
||||||
fn clone(&self) -> NominalOp<T> { copy *self }
|
fn clone(&self) -> NominalOp<T> { copy *self }
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl &Condvar {
|
||||||
struct ARC<T> { x: SharedMutableState<T> }
|
struct ARC<T> { x: SharedMutableState<T> }
|
||||||
|
|
||||||
/// Create an atomically reference counted wrapper.
|
/// Create an atomically reference counted wrapper.
|
||||||
pub fn ARC<T: Const Owned>(data: T) -> ARC<T> {
|
pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
|
||||||
ARC { x: unsafe { shared_mutable_state(data) } }
|
ARC { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ pub fn ARC<T: Const Owned>(data: T) -> ARC<T> {
|
||||||
* Access the underlying data in an atomically reference counted
|
* Access the underlying data in an atomically reference counted
|
||||||
* wrapper.
|
* wrapper.
|
||||||
*/
|
*/
|
||||||
pub fn get<T: Const Owned>(rc: &a/ARC<T>) -> &a/T {
|
pub fn get<T:Const + Owned>(rc: &a/ARC<T>) -> &a/T {
|
||||||
unsafe { get_shared_immutable_state(&rc.x) }
|
unsafe { get_shared_immutable_state(&rc.x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ pub fn get<T: Const Owned>(rc: &a/ARC<T>) -> &a/T {
|
||||||
* object. However, one of the `arc` objects can be sent to another task,
|
* object. However, one of the `arc` objects can be sent to another task,
|
||||||
* allowing them to share the underlying data.
|
* allowing them to share the underlying data.
|
||||||
*/
|
*/
|
||||||
pub fn clone<T: Const Owned>(rc: &ARC<T>) -> ARC<T> {
|
pub fn clone<T:Const + Owned>(rc: &ARC<T>) -> ARC<T> {
|
||||||
ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } }
|
ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,12 +112,12 @@ pub fn clone<T: Const Owned>(rc: &ARC<T>) -> ARC<T> {
|
||||||
* unwrap from a task that holds another reference to the same ARC; it is
|
* unwrap from a task that holds another reference to the same ARC; it is
|
||||||
* guaranteed to deadlock.
|
* guaranteed to deadlock.
|
||||||
*/
|
*/
|
||||||
pub fn unwrap<T: Const Owned>(rc: ARC<T>) -> T {
|
pub fn unwrap<T:Const + Owned>(rc: ARC<T>) -> T {
|
||||||
let ARC { x: x } = rc;
|
let ARC { x: x } = rc;
|
||||||
unsafe { unwrap_shared_mutable_state(x) }
|
unsafe { unwrap_shared_mutable_state(x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Const Owned> Clone for ARC<T> {
|
impl<T:Const + Owned> Clone for ARC<T> {
|
||||||
fn clone(&self) -> ARC<T> {
|
fn clone(&self) -> ARC<T> {
|
||||||
clone(self)
|
clone(self)
|
||||||
}
|
}
|
||||||
|
@ -133,14 +133,14 @@ struct MutexARCInner<T> { lock: Mutex, failed: bool, data: T }
|
||||||
struct MutexARC<T> { x: SharedMutableState<MutexARCInner<T>> }
|
struct MutexARC<T> { x: SharedMutableState<MutexARCInner<T>> }
|
||||||
|
|
||||||
/// Create a mutex-protected ARC with the supplied data.
|
/// Create a mutex-protected ARC with the supplied data.
|
||||||
pub fn MutexARC<T: Owned>(user_data: T) -> MutexARC<T> {
|
pub fn MutexARC<T:Owned>(user_data: T) -> MutexARC<T> {
|
||||||
mutex_arc_with_condvars(user_data, 1)
|
mutex_arc_with_condvars(user_data, 1)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a mutex-protected ARC with the supplied data and a specified number
|
* Create a mutex-protected ARC with the supplied data and a specified number
|
||||||
* of condvars (as sync::mutex_with_condvars).
|
* of condvars (as sync::mutex_with_condvars).
|
||||||
*/
|
*/
|
||||||
pub fn mutex_arc_with_condvars<T: Owned>(user_data: T,
|
pub fn mutex_arc_with_condvars<T:Owned>(user_data: T,
|
||||||
num_condvars: uint) -> MutexARC<T> {
|
num_condvars: uint) -> MutexARC<T> {
|
||||||
let data =
|
let data =
|
||||||
MutexARCInner { lock: mutex_with_condvars(num_condvars),
|
MutexARCInner { lock: mutex_with_condvars(num_condvars),
|
||||||
|
@ -148,7 +148,7 @@ pub fn mutex_arc_with_condvars<T: Owned>(user_data: T,
|
||||||
MutexARC { x: unsafe { shared_mutable_state(data) } }
|
MutexARC { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Clone for MutexARC<T> {
|
impl<T:Owned> Clone for MutexARC<T> {
|
||||||
/// Duplicate a mutex-protected ARC, as arc::clone.
|
/// Duplicate a mutex-protected ARC, as arc::clone.
|
||||||
fn clone(&self) -> MutexARC<T> {
|
fn clone(&self) -> MutexARC<T> {
|
||||||
// NB: Cloning the underlying mutex is not necessary. Its reference
|
// NB: Cloning the underlying mutex is not necessary. Its reference
|
||||||
|
@ -157,7 +157,7 @@ impl<T: Owned> Clone for MutexARC<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> &MutexARC<T> {
|
impl<T:Owned> &MutexARC<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the underlying mutable data with mutual exclusion from other
|
* Access the underlying mutable data with mutual exclusion from other
|
||||||
|
@ -219,7 +219,7 @@ impl<T: Owned> &MutexARC<T> {
|
||||||
* Will additionally fail if another task has failed while accessing the arc.
|
* Will additionally fail if another task has failed while accessing the arc.
|
||||||
*/
|
*/
|
||||||
// FIXME(#3724) make this a by-move method on the arc
|
// FIXME(#3724) make this a by-move method on the arc
|
||||||
pub fn unwrap_mutex_arc<T: Owned>(arc: MutexARC<T>) -> T {
|
pub fn unwrap_mutex_arc<T:Owned>(arc: MutexARC<T>) -> T {
|
||||||
let MutexARC { x: x } = arc;
|
let MutexARC { x: x } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let MutexARCInner { failed: failed, data: data, _ } = inner;
|
let MutexARCInner { failed: failed, data: data, _ } = inner;
|
||||||
|
@ -283,14 +283,14 @@ struct RWARC<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a reader/writer ARC with the supplied data.
|
/// Create a reader/writer ARC with the supplied data.
|
||||||
pub fn RWARC<T: Const Owned>(user_data: T) -> RWARC<T> {
|
pub fn RWARC<T:Const + Owned>(user_data: T) -> RWARC<T> {
|
||||||
rw_arc_with_condvars(user_data, 1)
|
rw_arc_with_condvars(user_data, 1)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a reader/writer ARC with the supplied data and a specified number
|
* Create a reader/writer ARC with the supplied data and a specified number
|
||||||
* of condvars (as sync::rwlock_with_condvars).
|
* of condvars (as sync::rwlock_with_condvars).
|
||||||
*/
|
*/
|
||||||
pub fn rw_arc_with_condvars<T: Const Owned>(
|
pub fn rw_arc_with_condvars<T:Const + Owned>(
|
||||||
user_data: T,
|
user_data: T,
|
||||||
num_condvars: uint) -> RWARC<T>
|
num_condvars: uint) -> RWARC<T>
|
||||||
{
|
{
|
||||||
|
@ -300,7 +300,7 @@ pub fn rw_arc_with_condvars<T: Const Owned>(
|
||||||
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
|
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Const Owned> RWARC<T> {
|
impl<T:Const + Owned> RWARC<T> {
|
||||||
/// Duplicate a rwlock-protected ARC, as arc::clone.
|
/// Duplicate a rwlock-protected ARC, as arc::clone.
|
||||||
fn clone(&self) -> RWARC<T> {
|
fn clone(&self) -> RWARC<T> {
|
||||||
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
|
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
|
||||||
|
@ -309,7 +309,7 @@ impl<T: Const Owned> RWARC<T> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Const Owned> &RWARC<T> {
|
impl<T:Const + Owned> &RWARC<T> {
|
||||||
/**
|
/**
|
||||||
* Access the underlying data mutably. Locks the rwlock in write mode;
|
* Access the underlying data mutably. Locks the rwlock in write mode;
|
||||||
* other readers and writers will block.
|
* other readers and writers will block.
|
||||||
|
@ -418,7 +418,7 @@ impl<T: Const Owned> &RWARC<T> {
|
||||||
* in write mode.
|
* in write mode.
|
||||||
*/
|
*/
|
||||||
// FIXME(#3724) make this a by-move method on the arc
|
// FIXME(#3724) make this a by-move method on the arc
|
||||||
pub fn unwrap_rw_arc<T: Const Owned>(arc: RWARC<T>) -> T {
|
pub fn unwrap_rw_arc<T:Const + Owned>(arc: RWARC<T>) -> T {
|
||||||
let RWARC { x: x, _ } = arc;
|
let RWARC { x: x, _ } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let RWARCInner { failed: failed, data: data, _ } = inner;
|
let RWARCInner { failed: failed, data: data, _ } = inner;
|
||||||
|
@ -432,7 +432,7 @@ pub fn unwrap_rw_arc<T: Const Owned>(arc: RWARC<T>) -> T {
|
||||||
// lock it. This wraps the unsafety, with the justification that the 'lock'
|
// lock it. This wraps the unsafety, with the justification that the 'lock'
|
||||||
// field is never overwritten; only 'failed' and 'data'.
|
// field is never overwritten; only 'failed' and 'data'.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn borrow_rwlock<T: Const Owned>(state: *const RWARCInner<T>) -> *RWlock {
|
fn borrow_rwlock<T:Const + Owned>(state: *const RWARCInner<T>) -> *RWlock {
|
||||||
unsafe { cast::transmute(&const (*state).lock) }
|
unsafe { cast::transmute(&const (*state).lock) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +444,7 @@ pub enum RWWriteMode<T> =
|
||||||
/// The "read permission" token used for RWARC.write_downgrade().
|
/// The "read permission" token used for RWARC.write_downgrade().
|
||||||
pub enum RWReadMode<T> = (&T, sync::RWlockReadMode);
|
pub enum RWReadMode<T> = (&T, sync::RWlockReadMode);
|
||||||
|
|
||||||
impl<T: Const Owned> &RWWriteMode<T> {
|
impl<T:Const + Owned> &RWWriteMode<T> {
|
||||||
/// Access the pre-downgrade RWARC in write mode.
|
/// Access the pre-downgrade RWARC in write mode.
|
||||||
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
|
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -474,7 +474,7 @@ impl<T: Const Owned> &RWWriteMode<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Const Owned> &RWReadMode<T> {
|
impl<T:Const + Owned> &RWReadMode<T> {
|
||||||
/// Access the post-downgrade rwlock in read mode.
|
/// Access the post-downgrade rwlock in read mode.
|
||||||
fn read<U>(blk: fn(x: &T) -> U) -> U {
|
fn read<U>(blk: fn(x: &T) -> U) -> U {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -120,7 +120,7 @@ pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
|
||||||
*
|
*
|
||||||
* Fails if `ofs` is greater or equal to the length of the vector
|
* Fails if `ofs` is greater or equal to the length of the vector
|
||||||
*/
|
*/
|
||||||
pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
|
pub fn get<T:Copy>(t: CVec<T>, ofs: uint) -> T {
|
||||||
assert ofs < len(t);
|
assert ofs < len(t);
|
||||||
return unsafe { *ptr::mut_offset(t.base, ofs) };
|
return unsafe { *ptr::mut_offset(t.base, ofs) };
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
|
||||||
*
|
*
|
||||||
* Fails if `ofs` is greater or equal to the length of the vector
|
* Fails if `ofs` is greater or equal to the length of the vector
|
||||||
*/
|
*/
|
||||||
pub fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
|
pub fn set<T:Copy>(t: CVec<T>, ofs: uint, v: T) {
|
||||||
assert ofs < len(t);
|
assert ofs < len(t);
|
||||||
unsafe { *ptr::mut_offset(t.base, ofs) = v };
|
unsafe { *ptr::mut_offset(t.base, ofs) = v };
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,19 +25,19 @@ pub struct DuplexStream<T, U> {
|
||||||
priv port: Port<U>,
|
priv port: Port<U>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> GenericChan<T> for DuplexStream<T, U> {
|
impl<T:Owned,U:Owned> GenericChan<T> for DuplexStream<T, U> {
|
||||||
fn send(x: T) {
|
fn send(x: T) {
|
||||||
self.chan.send(x)
|
self.chan.send(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> GenericSmartChan<T> for DuplexStream<T, U> {
|
impl<T:Owned,U:Owned> GenericSmartChan<T> for DuplexStream<T, U> {
|
||||||
fn try_send(x: T) -> bool {
|
fn try_send(x: T) -> bool {
|
||||||
self.chan.try_send(x)
|
self.chan.try_send(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> GenericPort<U> for DuplexStream<T, U> {
|
impl<T:Owned,U:Owned> GenericPort<U> for DuplexStream<T, U> {
|
||||||
fn recv() -> U {
|
fn recv() -> U {
|
||||||
self.port.recv()
|
self.port.recv()
|
||||||
}
|
}
|
||||||
|
@ -47,20 +47,20 @@ impl<T: Owned, U: Owned> GenericPort<U> for DuplexStream<T, U> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> Peekable<U> for DuplexStream<T, U> {
|
impl<T:Owned,U:Owned> Peekable<U> for DuplexStream<T, U> {
|
||||||
pure fn peek() -> bool {
|
pure fn peek() -> bool {
|
||||||
self.port.peek()
|
self.port.peek()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> Selectable for DuplexStream<T, U> {
|
impl<T:Owned,U:Owned> Selectable for DuplexStream<T, U> {
|
||||||
pure fn header() -> *pipes::PacketHeader {
|
pure fn header() -> *pipes::PacketHeader {
|
||||||
self.port.header()
|
self.port.header()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a bidirectional stream.
|
/// Creates a bidirectional stream.
|
||||||
pub fn DuplexStream<T: Owned, U: Owned>()
|
pub fn DuplexStream<T:Owned,U:Owned>()
|
||||||
-> (DuplexStream<T, U>, DuplexStream<U, T>)
|
-> (DuplexStream<T, U>, DuplexStream<U, T>)
|
||||||
{
|
{
|
||||||
let (p1, c2) = pipes::stream();
|
let (p1, c2) = pipes::stream();
|
||||||
|
|
|
@ -198,7 +198,7 @@ mod tests {
|
||||||
assert *deq.get(3) == d;
|
assert *deq.get(3) == d;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_parameterized<T: Copy Eq Durable>(a: T, b: T, c: T, d: T) {
|
fn test_parameterized<T:Copy + Eq + Durable>(a: T, b: T, c: T, d: T) {
|
||||||
let mut deq = Deque::new();
|
let mut deq = Deque::new();
|
||||||
assert deq.len() == 0;
|
assert deq.len() == 0;
|
||||||
deq.add_front(a);
|
deq.add_front(a);
|
||||||
|
|
|
@ -129,7 +129,7 @@ pub mod serial {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatPort` from a `Port<~[u8]>`
|
/// Create a `FlatPort` from a `Port<~[u8]>`
|
||||||
pub fn pipe_port<T: Decodable<DefaultDecoder>>(
|
pub fn pipe_port<T:Decodable<DefaultDecoder>>(
|
||||||
port: Port<~[u8]>
|
port: Port<~[u8]>
|
||||||
) -> PipePort<T> {
|
) -> PipePort<T> {
|
||||||
let unflat: DeserializingUnflattener<DefaultDecoder, T> =
|
let unflat: DeserializingUnflattener<DefaultDecoder, T> =
|
||||||
|
@ -140,7 +140,7 @@ pub mod serial {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
||||||
pub fn pipe_chan<T: Encodable<DefaultEncoder>>(
|
pub fn pipe_chan<T:Encodable<DefaultEncoder>>(
|
||||||
chan: Chan<~[u8]>
|
chan: Chan<~[u8]>
|
||||||
) -> PipeChan<T> {
|
) -> PipeChan<T> {
|
||||||
let flat: SerializingFlattener<DefaultEncoder, T> =
|
let flat: SerializingFlattener<DefaultEncoder, T> =
|
||||||
|
@ -189,7 +189,7 @@ pub mod pod {
|
||||||
pub type PipeChan<T> = FlatChan<T, PodFlattener<T>, PipeByteChan>;
|
pub type PipeChan<T> = FlatChan<T, PodFlattener<T>, PipeByteChan>;
|
||||||
|
|
||||||
/// Create a `FlatPort` from a `Reader`
|
/// Create a `FlatPort` from a `Reader`
|
||||||
pub fn reader_port<T: Copy Owned, R: Reader>(
|
pub fn reader_port<T:Copy + Owned,R:Reader>(
|
||||||
reader: R
|
reader: R
|
||||||
) -> ReaderPort<T, R> {
|
) -> ReaderPort<T, R> {
|
||||||
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
||||||
|
@ -198,7 +198,7 @@ pub mod pod {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Writer`
|
/// Create a `FlatChan` from a `Writer`
|
||||||
pub fn writer_chan<T: Copy Owned, W: Writer>(
|
pub fn writer_chan<T:Copy + Owned,W:Writer>(
|
||||||
writer: W
|
writer: W
|
||||||
) -> WriterChan<T, W> {
|
) -> WriterChan<T, W> {
|
||||||
let flat: PodFlattener<T> = PodFlattener::new();
|
let flat: PodFlattener<T> = PodFlattener::new();
|
||||||
|
@ -207,21 +207,21 @@ pub mod pod {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatPort` from a `Port<~[u8]>`
|
/// Create a `FlatPort` from a `Port<~[u8]>`
|
||||||
pub fn pipe_port<T: Copy Owned>(port: Port<~[u8]>) -> PipePort<T> {
|
pub fn pipe_port<T:Copy + Owned>(port: Port<~[u8]>) -> PipePort<T> {
|
||||||
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
||||||
let byte_port = PipeBytePort::new(port);
|
let byte_port = PipeBytePort::new(port);
|
||||||
FlatPort::new(unflat, byte_port)
|
FlatPort::new(unflat, byte_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
||||||
pub fn pipe_chan<T: Copy Owned>(chan: Chan<~[u8]>) -> PipeChan<T> {
|
pub fn pipe_chan<T:Copy + Owned>(chan: Chan<~[u8]>) -> PipeChan<T> {
|
||||||
let flat: PodFlattener<T> = PodFlattener::new();
|
let flat: PodFlattener<T> = PodFlattener::new();
|
||||||
let byte_chan = PipeByteChan::new(chan);
|
let byte_chan = PipeByteChan::new(chan);
|
||||||
FlatChan::new(flat, byte_chan)
|
FlatChan::new(flat, byte_chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
|
/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
|
||||||
pub fn pipe_stream<T: Copy Owned>() -> (PipePort<T>, PipeChan<T>) {
|
pub fn pipe_stream<T:Copy + Owned>() -> (PipePort<T>, PipeChan<T>) {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
return (pipe_port(port), pipe_chan(chan));
|
return (pipe_port(port), pipe_chan(chan));
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ pub mod flatteners {
|
||||||
bogus: ()
|
bogus: ()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: Copy Owned> Unflattener<T> for PodUnflattener<T> {
|
pub impl<T:Copy + Owned> Unflattener<T> for PodUnflattener<T> {
|
||||||
fn unflatten(&self, buf: ~[u8]) -> T {
|
fn unflatten(&self, buf: ~[u8]) -> T {
|
||||||
assert size_of::<T>() != 0;
|
assert size_of::<T>() != 0;
|
||||||
assert size_of::<T>() == buf.len();
|
assert size_of::<T>() == buf.len();
|
||||||
|
@ -368,7 +368,7 @@ pub mod flatteners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: Copy Owned> Flattener<T> for PodFlattener<T> {
|
pub impl<T:Copy + Owned> Flattener<T> for PodFlattener<T> {
|
||||||
fn flatten(&self, val: T) -> ~[u8] {
|
fn flatten(&self, val: T) -> ~[u8] {
|
||||||
assert size_of::<T>() != 0;
|
assert size_of::<T>() != 0;
|
||||||
let val: *T = ptr::to_unsafe_ptr(&val);
|
let val: *T = ptr::to_unsafe_ptr(&val);
|
||||||
|
@ -377,7 +377,7 @@ pub mod flatteners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: Copy Owned> PodUnflattener<T> {
|
pub impl<T:Copy + Owned> PodUnflattener<T> {
|
||||||
static fn new() -> PodUnflattener<T> {
|
static fn new() -> PodUnflattener<T> {
|
||||||
PodUnflattener {
|
PodUnflattener {
|
||||||
bogus: ()
|
bogus: ()
|
||||||
|
@ -385,7 +385,7 @@ pub mod flatteners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: Copy Owned> PodFlattener<T> {
|
pub impl<T:Copy + Owned> PodFlattener<T> {
|
||||||
static fn new() -> PodFlattener<T> {
|
static fn new() -> PodFlattener<T> {
|
||||||
PodFlattener {
|
PodFlattener {
|
||||||
bogus: ()
|
bogus: ()
|
||||||
|
@ -406,21 +406,21 @@ pub mod flatteners {
|
||||||
serialize_value: SerializeValue<T>
|
serialize_value: SerializeValue<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> Unflattener<T>
|
pub impl<D:Decoder,T:Decodable<D>> Unflattener<T>
|
||||||
for DeserializingUnflattener<D, T> {
|
for DeserializingUnflattener<D, T> {
|
||||||
fn unflatten(&self, buf: ~[u8]) -> T {
|
fn unflatten(&self, buf: ~[u8]) -> T {
|
||||||
(self.deserialize_buffer)(buf)
|
(self.deserialize_buffer)(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Flattener<T>
|
pub impl<S:Encoder,T:Encodable<S>> Flattener<T>
|
||||||
for SerializingFlattener<S, T> {
|
for SerializingFlattener<S, T> {
|
||||||
fn flatten(&self, val: T) -> ~[u8] {
|
fn flatten(&self, val: T) -> ~[u8] {
|
||||||
(self.serialize_value)(&val)
|
(self.serialize_value)(&val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> DeserializingUnflattener<D, T> {
|
pub impl<D:Decoder,T:Decodable<D>> DeserializingUnflattener<D, T> {
|
||||||
static fn new(deserialize_buffer: DeserializeBuffer<T>)
|
static fn new(deserialize_buffer: DeserializeBuffer<T>)
|
||||||
-> DeserializingUnflattener<D, T> {
|
-> DeserializingUnflattener<D, T> {
|
||||||
DeserializingUnflattener {
|
DeserializingUnflattener {
|
||||||
|
@ -429,7 +429,7 @@ pub mod flatteners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> SerializingFlattener<S, T> {
|
pub impl<S:Encoder,T:Encodable<S>> SerializingFlattener<S, T> {
|
||||||
static fn new(serialize_value: SerializeValue<T>)
|
static fn new(serialize_value: SerializeValue<T>)
|
||||||
-> SerializingFlattener<S, T> {
|
-> SerializingFlattener<S, T> {
|
||||||
SerializingFlattener {
|
SerializingFlattener {
|
||||||
|
@ -519,7 +519,7 @@ pub mod bytepipes {
|
||||||
writer: W
|
writer: W
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<R: Reader> BytePort for ReaderBytePort<R> {
|
pub impl<R:Reader> BytePort for ReaderBytePort<R> {
|
||||||
fn try_recv(&self, count: uint) -> Option<~[u8]> {
|
fn try_recv(&self, count: uint) -> Option<~[u8]> {
|
||||||
let mut left = count;
|
let mut left = count;
|
||||||
let mut bytes = ~[];
|
let mut bytes = ~[];
|
||||||
|
@ -541,13 +541,13 @@ pub mod bytepipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<W: Writer> ByteChan for WriterByteChan<W> {
|
pub impl<W:Writer> ByteChan for WriterByteChan<W> {
|
||||||
fn send(&self, val: ~[u8]) {
|
fn send(&self, val: ~[u8]) {
|
||||||
self.writer.write(val);
|
self.writer.write(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<R: Reader> ReaderBytePort<R> {
|
pub impl<R:Reader> ReaderBytePort<R> {
|
||||||
static fn new(r: R) -> ReaderBytePort<R> {
|
static fn new(r: R) -> ReaderBytePort<R> {
|
||||||
ReaderBytePort {
|
ReaderBytePort {
|
||||||
reader: r
|
reader: r
|
||||||
|
@ -555,7 +555,7 @@ pub mod bytepipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<W: Writer> WriterByteChan<W> {
|
pub impl<W:Writer> WriterByteChan<W> {
|
||||||
static fn new(w: W) -> WriterByteChan<W> {
|
static fn new(w: W) -> WriterByteChan<W> {
|
||||||
WriterByteChan {
|
WriterByteChan {
|
||||||
writer: w
|
writer: w
|
||||||
|
@ -765,7 +765,7 @@ mod test {
|
||||||
type WriterChanFactory<F> =
|
type WriterChanFactory<F> =
|
||||||
~fn(TcpSocketBuf) -> FlatChan<int, F, WriterByteChan<TcpSocketBuf>>;
|
~fn(TcpSocketBuf) -> FlatChan<int, F, WriterByteChan<TcpSocketBuf>>;
|
||||||
|
|
||||||
fn test_some_tcp_stream<U: Unflattener<int>, F: Flattener<int>>(
|
fn test_some_tcp_stream<U:Unflattener<int>,F:Flattener<int>>(
|
||||||
reader_port: ReaderPortFactory<U>,
|
reader_port: ReaderPortFactory<U>,
|
||||||
writer_chan: WriterChanFactory<F>,
|
writer_chan: WriterChanFactory<F>,
|
||||||
port: uint) {
|
port: uint) {
|
||||||
|
@ -901,7 +901,7 @@ mod test {
|
||||||
pod::pipe_port(port)
|
pod::pipe_port(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_try_recv_none1<P: BytePort>(loader: PortLoader<P>) {
|
fn test_try_recv_none1<P:BytePort>(loader: PortLoader<P>) {
|
||||||
let bytes = ~[];
|
let bytes = ~[];
|
||||||
let port = loader(bytes);
|
let port = loader(bytes);
|
||||||
let res: Option<int> = port.try_recv();
|
let res: Option<int> = port.try_recv();
|
||||||
|
@ -917,7 +917,7 @@ mod test {
|
||||||
test_try_recv_none1(pipe_port_loader);
|
test_try_recv_none1(pipe_port_loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_try_recv_none2<P: BytePort>(loader: PortLoader<P>) {
|
fn test_try_recv_none2<P:BytePort>(loader: PortLoader<P>) {
|
||||||
// The control word in the protocol is interrupted
|
// The control word in the protocol is interrupted
|
||||||
let bytes = ~[0];
|
let bytes = ~[0];
|
||||||
let port = loader(bytes);
|
let port = loader(bytes);
|
||||||
|
@ -934,7 +934,7 @@ mod test {
|
||||||
test_try_recv_none2(pipe_port_loader);
|
test_try_recv_none2(pipe_port_loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_try_recv_none3<P: BytePort>(loader: PortLoader<P>) {
|
fn test_try_recv_none3<P:BytePort>(loader: PortLoader<P>) {
|
||||||
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
||||||
// The control word is followed by garbage
|
// The control word is followed by garbage
|
||||||
let bytes = CONTINUE.to_vec() + ~[0];
|
let bytes = CONTINUE.to_vec() + ~[0];
|
||||||
|
@ -952,7 +952,7 @@ mod test {
|
||||||
test_try_recv_none3(pipe_port_loader);
|
test_try_recv_none3(pipe_port_loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_try_recv_none4<P: BytePort>(+loader: PortLoader<P>) {
|
fn test_try_recv_none4<P:BytePort>(+loader: PortLoader<P>) {
|
||||||
assert do task::try || {
|
assert do task::try || {
|
||||||
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
||||||
// The control word is followed by a valid length,
|
// The control word is followed by a valid length,
|
||||||
|
|
|
@ -34,7 +34,7 @@ enum TreeNode<K, V> {
|
||||||
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
|
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
|
||||||
|
|
||||||
/// Insert a value into the map
|
/// Insert a value into the map
|
||||||
pub fn insert<K: Copy Eq Ord, V: Copy>(m: Treemap<K, V>, k: K, v: V)
|
pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V)
|
||||||
-> Treemap<K, V> {
|
-> Treemap<K, V> {
|
||||||
@match m {
|
@match m {
|
||||||
@Empty => Node(@k, @v, @Empty, @Empty),
|
@Empty => Node(@k, @v, @Empty, @Empty),
|
||||||
|
@ -49,7 +49,7 @@ pub fn insert<K: Copy Eq Ord, V: Copy>(m: Treemap<K, V>, k: K, v: V)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find a value based on the key
|
/// Find a value based on the key
|
||||||
pub fn find<K: Eq Ord, V: Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
|
pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
|
||||||
match *m {
|
match *m {
|
||||||
Empty => None,
|
Empty => None,
|
||||||
Node(@ref kk, @copy v, left, right) => {
|
Node(@ref kk, @copy v, left, right) => {
|
||||||
|
|
|
@ -323,7 +323,7 @@ pub impl serialize::Encoder for PrettyEncoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: serialize::Encoder> serialize::Encodable<S> for Json {
|
pub impl<S:serialize::Encoder> serialize::Encodable<S> for Json {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
match *self {
|
match *self {
|
||||||
Number(v) => v.encode(s),
|
Number(v) => v.encode(s),
|
||||||
|
@ -1150,7 +1150,7 @@ impl ToJson for @~str {
|
||||||
fn to_json() -> Json { String(copy *self) }
|
fn to_json() -> Json { String(copy *self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToJson, B: ToJson> ToJson for (A, B) {
|
impl<A:ToJson,B:ToJson> ToJson for (A, B) {
|
||||||
fn to_json() -> Json {
|
fn to_json() -> Json {
|
||||||
match self {
|
match self {
|
||||||
(ref a, ref b) => {
|
(ref a, ref b) => {
|
||||||
|
@ -1160,7 +1160,7 @@ impl<A: ToJson, B: ToJson> ToJson for (A, B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToJson, B: ToJson, C: ToJson> ToJson for (A, B, C) {
|
impl<A:ToJson,B:ToJson,C:ToJson> ToJson for (A, B, C) {
|
||||||
fn to_json() -> Json {
|
fn to_json() -> Json {
|
||||||
match self {
|
match self {
|
||||||
(ref a, ref b, ref c) => {
|
(ref a, ref b, ref c) => {
|
||||||
|
@ -1170,11 +1170,11 @@ impl<A: ToJson, B: ToJson, C: ToJson> ToJson for (A, B, C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToJson> ToJson for ~[A] {
|
impl<A:ToJson> ToJson for ~[A] {
|
||||||
fn to_json() -> Json { List(self.map(|elt| elt.to_json())) }
|
fn to_json() -> Json { List(self.map(|elt| elt.to_json())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToJson Copy> ToJson for LinearMap<~str, A> {
|
impl<A:ToJson + Copy> ToJson for LinearMap<~str, A> {
|
||||||
fn to_json() -> Json {
|
fn to_json() -> Json {
|
||||||
let mut d = LinearMap::new();
|
let mut d = LinearMap::new();
|
||||||
for self.each |&(key, value)| {
|
for self.each |&(key, value)| {
|
||||||
|
@ -1184,7 +1184,7 @@ impl<A: ToJson Copy> ToJson for LinearMap<~str, A> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToJson> ToJson for Option<A> {
|
impl<A:ToJson> ToJson for Option<A> {
|
||||||
fn to_json() -> Json {
|
fn to_json() -> Json {
|
||||||
match self {
|
match self {
|
||||||
None => Null,
|
None => Null,
|
||||||
|
@ -1282,13 +1282,13 @@ mod tests {
|
||||||
|
|
||||||
// two fns copied from libsyntax/util/testing.rs.
|
// two fns copied from libsyntax/util/testing.rs.
|
||||||
// Should they be in their own crate?
|
// Should they be in their own crate?
|
||||||
pub pure fn check_equal_ptr<T : cmp::Eq> (given : &T, expected: &T) {
|
pub pure fn check_equal_ptr<T:cmp::Eq> (given : &T, expected: &T) {
|
||||||
if !((given == expected) && (expected == given )) {
|
if !((given == expected) && (expected == given )) {
|
||||||
fail!(fmt!("given %?, expected %?",given,expected));
|
fail!(fmt!("given %?, expected %?",given,expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn check_equal<T : cmp::Eq> (given : T, expected: T) {
|
pub pure fn check_equal<T:cmp::Eq> (given : T, expected: T) {
|
||||||
if !((given == expected) && (expected == given )) {
|
if !((given == expected) && (expected == given )) {
|
||||||
fail!(fmt!("given %?, expected %?",given,expected));
|
fail!(fmt!("given %?, expected %?",given,expected));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub enum List<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a list from a vector
|
/// Create a list from a vector
|
||||||
pub pure fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
|
pub pure fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
|
||||||
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
|
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ pub pure fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
|
||||||
* * z - The initial value
|
* * z - The initial value
|
||||||
* * f - The function to apply
|
* * f - The function to apply
|
||||||
*/
|
*/
|
||||||
pub fn foldl<T: Copy, U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
|
pub fn foldl<T:Copy,U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
|
||||||
let mut accum: T = z;
|
let mut accum: T = z;
|
||||||
do iter(ls) |elt| { accum = f(&accum, elt);}
|
do iter(ls) |elt| { accum = f(&accum, elt);}
|
||||||
accum
|
accum
|
||||||
|
@ -53,7 +53,7 @@ pub fn foldl<T: Copy, U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
|
||||||
* When function `f` returns true then an option containing the element
|
* When function `f` returns true then an option containing the element
|
||||||
* is returned. If `f` matches no elements then none is returned.
|
* is returned. If `f` matches no elements then none is returned.
|
||||||
*/
|
*/
|
||||||
pub pure fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
|
pub pure fn find<T:Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
|
||||||
let mut ls = ls;
|
let mut ls = ls;
|
||||||
loop {
|
loop {
|
||||||
ls = match *ls {
|
ls = match *ls {
|
||||||
|
@ -67,7 +67,7 @@ pub pure fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if a list contains an element with the given value
|
/// Returns true if a list contains an element with the given value
|
||||||
pub fn has<T: Copy Eq>(ls: @List<T>, elt: T) -> bool {
|
pub fn has<T:Copy + Eq>(ls: @List<T>, elt: T) -> bool {
|
||||||
for each(ls) |e| {
|
for each(ls) |e| {
|
||||||
if *e == elt { return true; }
|
if *e == elt { return true; }
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ pub fn has<T: Copy Eq>(ls: @List<T>, elt: T) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the list is empty
|
/// Returns true if the list is empty
|
||||||
pub pure fn is_empty<T: Copy>(ls: @List<T>) -> bool {
|
pub pure fn is_empty<T:Copy>(ls: @List<T>) -> bool {
|
||||||
match *ls {
|
match *ls {
|
||||||
Nil => true,
|
Nil => true,
|
||||||
_ => false
|
_ => false
|
||||||
|
@ -90,7 +90,7 @@ pub pure fn len<T>(ls: @List<T>) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all but the first element of a list
|
/// Returns all but the first element of a list
|
||||||
pub pure fn tail<T: Copy>(ls: @List<T>) -> @List<T> {
|
pub pure fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
|
||||||
match *ls {
|
match *ls {
|
||||||
Cons(_, tl) => return tl,
|
Cons(_, tl) => return tl,
|
||||||
Nil => fail!(~"list empty")
|
Nil => fail!(~"list empty")
|
||||||
|
@ -98,7 +98,7 @@ pub pure fn tail<T: Copy>(ls: @List<T>) -> @List<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the first element of a list
|
/// Returns the first element of a list
|
||||||
pub pure fn head<T: Copy>(ls: @List<T>) -> T {
|
pub pure fn head<T:Copy>(ls: @List<T>) -> T {
|
||||||
match *ls {
|
match *ls {
|
||||||
Cons(copy hd, _) => hd,
|
Cons(copy hd, _) => hd,
|
||||||
// makes me sad
|
// makes me sad
|
||||||
|
@ -107,7 +107,7 @@ pub pure fn head<T: Copy>(ls: @List<T>) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends one list to another
|
/// Appends one list to another
|
||||||
pub pure fn append<T: Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
|
pub pure fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
|
||||||
match *l {
|
match *l {
|
||||||
Nil => return m,
|
Nil => return m,
|
||||||
Cons(copy x, xs) => {
|
Cons(copy x, xs) => {
|
||||||
|
@ -120,7 +120,7 @@ pub pure fn append<T: Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
|
||||||
/*
|
/*
|
||||||
/// Push one element into the front of a list, returning a new list
|
/// Push one element into the front of a list, returning a new list
|
||||||
/// THIS VERSION DOESN'T ACTUALLY WORK
|
/// THIS VERSION DOESN'T ACTUALLY WORK
|
||||||
pure fn push<T: Copy>(ll: &mut @list<T>, vv: T) {
|
pure fn push<T:Copy>(ll: &mut @list<T>, vv: T) {
|
||||||
ll = &mut @cons(vv, *ll)
|
ll = &mut @cons(vv, *ll)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -76,7 +76,7 @@ pub mod chained {
|
||||||
FoundAfter(@Entry<K,V>, @Entry<K,V>)
|
FoundAfter(@Entry<K,V>, @Entry<K,V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
priv impl<K:Eq IterBytes Hash, V> T<K, V> {
|
priv impl<K:Eq + IterBytes + Hash,V> T<K, V> {
|
||||||
pure fn search_rem(k: &K, h: uint, idx: uint,
|
pure fn search_rem(k: &K, h: uint, idx: uint,
|
||||||
e_root: @Entry<K,V>) -> SearchResult<K,V> {
|
e_root: @Entry<K,V>) -> SearchResult<K,V> {
|
||||||
let mut e0 = e_root;
|
let mut e0 = e_root;
|
||||||
|
@ -156,19 +156,19 @@ pub mod chained {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Eq IterBytes Hash, V> Container for T<K, V> {
|
impl<K:Eq + IterBytes + Hash,V> Container for T<K, V> {
|
||||||
pure fn len(&self) -> uint { self.count }
|
pure fn len(&self) -> uint { self.count }
|
||||||
pure fn is_empty(&self) -> bool { self.count == 0 }
|
pure fn is_empty(&self) -> bool { self.count == 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Eq IterBytes Hash, V> Mutable for T<K, V> {
|
impl<K:Eq + IterBytes + Hash,V> Mutable for T<K, V> {
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.count = 0u;
|
self.count = 0u;
|
||||||
self.chains = chains(initial_capacity);
|
self.chains = chains(initial_capacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Eq IterBytes Hash, V> T<K, V> {
|
impl<K:Eq + IterBytes + Hash,V> T<K, V> {
|
||||||
pure fn contains_key(&self, k: &K) -> bool {
|
pure fn contains_key(&self, k: &K) -> bool {
|
||||||
let hash = k.hash_keyed(0,0) as uint;
|
let hash = k.hash_keyed(0,0) as uint;
|
||||||
match self.search_tbl(k, hash) {
|
match self.search_tbl(k, hash) {
|
||||||
|
@ -252,7 +252,7 @@ pub mod chained {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Eq IterBytes Hash Copy, V: Copy> T<K, V> {
|
impl<K:Eq + IterBytes + Hash + Copy,V:Copy> T<K, V> {
|
||||||
pure fn find(&self, k: &K) -> Option<V> {
|
pure fn find(&self, k: &K) -> Option<V> {
|
||||||
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
|
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
|
||||||
NotFound => None,
|
NotFound => None,
|
||||||
|
@ -325,7 +325,7 @@ pub mod chained {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> T<K, V> {
|
impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> {
|
||||||
fn to_writer(wr: io::Writer) {
|
fn to_writer(wr: io::Writer) {
|
||||||
if self.count == 0u {
|
if self.count == 0u {
|
||||||
wr.write_str(~"{}");
|
wr.write_str(~"{}");
|
||||||
|
@ -347,7 +347,8 @@ pub mod chained {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> ToStr for T<K, V> {
|
impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> ToStr
|
||||||
|
for T<K, V> {
|
||||||
pure fn to_str(&self) -> ~str {
|
pure fn to_str(&self) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Meh -- this should be safe
|
// Meh -- this should be safe
|
||||||
|
@ -356,7 +357,7 @@ pub mod chained {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Eq IterBytes Hash Copy, V: Copy> ops::Index<K, V> for T<K, V> {
|
impl<K:Eq + IterBytes + Hash + Copy,V:Copy> ops::Index<K, V> for T<K, V> {
|
||||||
pure fn index(&self, k: K) -> V {
|
pure fn index(&self, k: K) -> V {
|
||||||
self.get(&k)
|
self.get(&k)
|
||||||
}
|
}
|
||||||
|
@ -366,7 +367,7 @@ pub mod chained {
|
||||||
vec::from_elem(nchains, None)
|
vec::from_elem(nchains, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
|
pub fn mk<K:Eq + IterBytes + Hash,V:Copy>() -> T<K,V> {
|
||||||
let slf: T<K, V> = @HashMap_ {count: 0u,
|
let slf: T<K, V> = @HashMap_ {count: 0u,
|
||||||
chains: chains(initial_capacity)};
|
chains: chains(initial_capacity)};
|
||||||
slf
|
slf
|
||||||
|
@ -378,18 +379,19 @@ Function: hashmap
|
||||||
|
|
||||||
Construct a hashmap.
|
Construct a hashmap.
|
||||||
*/
|
*/
|
||||||
pub fn HashMap<K:Eq IterBytes Hash Const, V: Copy>()
|
pub fn HashMap<K:Eq + IterBytes + Hash + Const,V:Copy>()
|
||||||
-> HashMap<K, V> {
|
-> HashMap<K, V> {
|
||||||
chained::mk()
|
chained::mk()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function for adding keys to a hashmap with nil type keys
|
/// Convenience function for adding keys to a hashmap with nil type keys
|
||||||
pub fn set_add<K:Eq IterBytes Hash Const Copy>(set: Set<K>, key: K) -> bool {
|
pub fn set_add<K:Eq + IterBytes + Hash + Const + Copy>(set: Set<K>, key: K)
|
||||||
|
-> bool {
|
||||||
set.insert(key, ())
|
set.insert(key, ())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a set into a vector.
|
/// Convert a set into a vector.
|
||||||
pub pure fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
|
pub pure fn vec_from_set<T:Eq + IterBytes + Hash + Copy>(s: Set<T>) -> ~[T] {
|
||||||
do vec::build_sized(s.len()) |push| {
|
do vec::build_sized(s.len()) |push| {
|
||||||
for s.each_key() |&k| {
|
for s.each_key() |&k| {
|
||||||
push(k);
|
push(k);
|
||||||
|
@ -398,7 +400,7 @@ pub pure fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap from a vector
|
/// Construct a hashmap from a vector
|
||||||
pub fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
|
pub fn hash_from_vec<K:Eq + IterBytes + Hash + Const + Copy,V:Copy>(
|
||||||
items: &[(K, V)]) -> HashMap<K, V> {
|
items: &[(K, V)]) -> HashMap<K, V> {
|
||||||
let map = HashMap();
|
let map = HashMap();
|
||||||
for vec::each(items) |item| {
|
for vec::each(items) |item| {
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub enum SmallIntMap<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a smallintmap
|
/// Create a smallintmap
|
||||||
pub fn mk<T: Copy>() -> SmallIntMap<T> {
|
pub fn mk<T:Copy>() -> SmallIntMap<T> {
|
||||||
let v = DVec();
|
let v = DVec();
|
||||||
SmallIntMap_(@SmallIntMap_ { v: v } )
|
SmallIntMap_(@SmallIntMap_ { v: v } )
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ pub fn mk<T: Copy>() -> SmallIntMap<T> {
|
||||||
* the specified key then the original value is replaced.
|
* the specified key then the original value is replaced.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, val: T) {
|
pub fn insert<T:Copy>(self: SmallIntMap<T>, key: uint, val: T) {
|
||||||
//io::println(fmt!("%?", key));
|
//io::println(fmt!("%?", key));
|
||||||
self.v.grow_set_elt(key, &None, Some(val));
|
self.v.grow_set_elt(key, &None, Some(val));
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ pub fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, val: T) {
|
||||||
* Get the value for the specified key. If the key does not exist
|
* Get the value for the specified key. If the key does not exist
|
||||||
* in the map then returns none
|
* in the map then returns none
|
||||||
*/
|
*/
|
||||||
pub pure fn find<T: Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> {
|
pub pure fn find<T:Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> {
|
||||||
if key < self.v.len() { return self.v.get_elt(key); }
|
if key < self.v.len() { return self.v.get_elt(key); }
|
||||||
return None::<T>;
|
return None::<T>;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ pub pure fn find<T: Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> {
|
||||||
*
|
*
|
||||||
* If the key does not exist in the map
|
* If the key does not exist in the map
|
||||||
*/
|
*/
|
||||||
pub pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T {
|
pub pure fn get<T:Copy>(self: SmallIntMap<T>, key: uint) -> T {
|
||||||
match find(self, key) {
|
match find(self, key) {
|
||||||
None => {
|
None => {
|
||||||
error!("smallintmap::get(): key not present");
|
error!("smallintmap::get(): key not present");
|
||||||
|
@ -74,7 +74,7 @@ pub pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the map contains a value for the specified key
|
/// Returns true if the map contains a value for the specified key
|
||||||
pub pure fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool {
|
pub pure fn contains_key<T:Copy>(self: SmallIntMap<T>, key: uint) -> bool {
|
||||||
return !find(self, key).is_none();
|
return !find(self, key).is_none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ impl<V> Mutable for SmallIntMap<V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implements the map::map interface for smallintmap
|
/// Implements the map::map interface for smallintmap
|
||||||
impl<V: Copy> SmallIntMap<V> {
|
impl<V:Copy> SmallIntMap<V> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn insert(key: uint, value: V) -> bool {
|
fn insert(key: uint, value: V) -> bool {
|
||||||
let exists = contains_key(self, key);
|
let exists = contains_key(self, key);
|
||||||
|
@ -162,7 +162,7 @@ impl<V: Copy> SmallIntMap<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: Copy> ops::Index<uint, V> for SmallIntMap<V> {
|
impl<V:Copy> ops::Index<uint, V> for SmallIntMap<V> {
|
||||||
pure fn index(&self, key: uint) -> V {
|
pure fn index(&self, key: uint) -> V {
|
||||||
unsafe {
|
unsafe {
|
||||||
get(*self, key)
|
get(*self, key)
|
||||||
|
|
|
@ -34,7 +34,7 @@ const min_granularity : uint = 1024u;
|
||||||
* This is used to build most of the other parallel vector functions,
|
* This is used to build most of the other parallel vector functions,
|
||||||
* like map or alli.
|
* like map or alli.
|
||||||
*/
|
*/
|
||||||
fn map_slices<A: Copy Owned, B: Copy Owned>(
|
fn map_slices<A:Copy + Owned,B:Copy + Owned>(
|
||||||
xs: &[A],
|
xs: &[A],
|
||||||
f: &fn() -> ~fn(uint, v: &[A]) -> B)
|
f: &fn() -> ~fn(uint, v: &[A]) -> B)
|
||||||
-> ~[B] {
|
-> ~[B] {
|
||||||
|
@ -90,7 +90,7 @@ fn map_slices<A: Copy Owned, B: Copy Owned>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A parallel version of map.
|
/// A parallel version of map.
|
||||||
pub fn map<A: Copy Owned, B: Copy Owned>(
|
pub fn map<A:Copy + Owned,B:Copy + Owned>(
|
||||||
xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] {
|
xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] {
|
||||||
vec::concat(map_slices(xs, || {
|
vec::concat(map_slices(xs, || {
|
||||||
let f = fn_factory();
|
let f = fn_factory();
|
||||||
|
@ -101,7 +101,7 @@ pub fn map<A: Copy Owned, B: Copy Owned>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A parallel version of mapi.
|
/// A parallel version of mapi.
|
||||||
pub fn mapi<A: Copy Owned, B: Copy Owned>(
|
pub fn mapi<A:Copy + Owned,B:Copy + Owned>(
|
||||||
xs: &[A],
|
xs: &[A],
|
||||||
fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B]
|
fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B]
|
||||||
{
|
{
|
||||||
|
@ -120,7 +120,7 @@ pub fn mapi<A: Copy Owned, B: Copy Owned>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the function holds for all elements in the vector.
|
/// Returns true if the function holds for all elements in the vector.
|
||||||
pub fn alli<A: Copy Owned>(
|
pub fn alli<A:Copy + Owned>(
|
||||||
xs: &[A],
|
xs: &[A],
|
||||||
fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
|
fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
|
||||||
{
|
{
|
||||||
|
@ -135,7 +135,7 @@ pub fn alli<A: Copy Owned>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the function holds for any elements in the vector.
|
/// Returns true if the function holds for any elements in the vector.
|
||||||
pub fn any<A: Copy Owned>(
|
pub fn any<A:Copy + Owned>(
|
||||||
xs: &[A],
|
xs: &[A],
|
||||||
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
|
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
|
||||||
do vec::any(map_slices(xs, || {
|
do vec::any(map_slices(xs, || {
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct PriorityQueue<T> {
|
||||||
priv data: ~[T],
|
priv data: ~[T],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> BaseIter<T> for PriorityQueue<T> {
|
impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
|
||||||
/// Visit all values in the underlying vector.
|
/// Visit all values in the underlying vector.
|
||||||
///
|
///
|
||||||
/// The values are **not** visited in order.
|
/// The values are **not** visited in order.
|
||||||
|
@ -35,7 +35,7 @@ impl<T: Ord> BaseIter<T> for PriorityQueue<T> {
|
||||||
pure fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
|
pure fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Container for PriorityQueue<T> {
|
impl<T:Ord> Container for PriorityQueue<T> {
|
||||||
/// Returns the length of the queue
|
/// Returns the length of the queue
|
||||||
pure fn len(&self) -> uint { self.data.len() }
|
pure fn len(&self) -> uint { self.data.len() }
|
||||||
|
|
||||||
|
@ -43,12 +43,12 @@ impl<T: Ord> Container for PriorityQueue<T> {
|
||||||
pure fn is_empty(&self) -> bool { self.data.is_empty() }
|
pure fn is_empty(&self) -> bool { self.data.is_empty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Mutable for PriorityQueue<T> {
|
impl<T:Ord> Mutable for PriorityQueue<T> {
|
||||||
/// Drop all items from the queue
|
/// Drop all items from the queue
|
||||||
fn clear(&mut self) { self.data.truncate(0) }
|
fn clear(&mut self) { self.data.truncate(0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <T: Ord> PriorityQueue<T> {
|
impl <T:Ord> PriorityQueue<T> {
|
||||||
/// Returns the greatest item in the queue - fails if empty
|
/// Returns the greatest item in the queue - fails if empty
|
||||||
pure fn top(&self) -> &self/T { &self.data[0] }
|
pure fn top(&self) -> &self/T { &self.data[0] }
|
||||||
|
|
||||||
|
|
|
@ -105,218 +105,218 @@ pub trait Decoder {
|
||||||
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
|
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Encodable<S: Encoder> {
|
pub trait Encodable<S:Encoder> {
|
||||||
fn encode(&self, s: &S);
|
fn encode(&self, s: &S);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Decodable<D: Decoder> {
|
pub trait Decodable<D:Decoder> {
|
||||||
static fn decode(&self, d: &D) -> Self;
|
static fn decode(&self, d: &D) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for uint {
|
pub impl<S:Encoder> Encodable<S> for uint {
|
||||||
fn encode(&self, s: &S) { s.emit_uint(*self) }
|
fn encode(&self, s: &S) { s.emit_uint(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for uint {
|
pub impl<D:Decoder> Decodable<D> for uint {
|
||||||
static fn decode(&self, d: &D) -> uint {
|
static fn decode(&self, d: &D) -> uint {
|
||||||
d.read_uint()
|
d.read_uint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for u8 {
|
pub impl<S:Encoder> Encodable<S> for u8 {
|
||||||
fn encode(&self, s: &S) { s.emit_u8(*self) }
|
fn encode(&self, s: &S) { s.emit_u8(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for u8 {
|
pub impl<D:Decoder> Decodable<D> for u8 {
|
||||||
static fn decode(&self, d: &D) -> u8 {
|
static fn decode(&self, d: &D) -> u8 {
|
||||||
d.read_u8()
|
d.read_u8()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for u16 {
|
pub impl<S:Encoder> Encodable<S> for u16 {
|
||||||
fn encode(&self, s: &S) { s.emit_u16(*self) }
|
fn encode(&self, s: &S) { s.emit_u16(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for u16 {
|
pub impl<D:Decoder> Decodable<D> for u16 {
|
||||||
static fn decode(&self, d: &D) -> u16 {
|
static fn decode(&self, d: &D) -> u16 {
|
||||||
d.read_u16()
|
d.read_u16()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for u32 {
|
pub impl<S:Encoder> Encodable<S> for u32 {
|
||||||
fn encode(&self, s: &S) { s.emit_u32(*self) }
|
fn encode(&self, s: &S) { s.emit_u32(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for u32 {
|
pub impl<D:Decoder> Decodable<D> for u32 {
|
||||||
static fn decode(&self, d: &D) -> u32 {
|
static fn decode(&self, d: &D) -> u32 {
|
||||||
d.read_u32()
|
d.read_u32()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for u64 {
|
pub impl<S:Encoder> Encodable<S> for u64 {
|
||||||
fn encode(&self, s: &S) { s.emit_u64(*self) }
|
fn encode(&self, s: &S) { s.emit_u64(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for u64 {
|
pub impl<D:Decoder> Decodable<D> for u64 {
|
||||||
static fn decode(&self, d: &D) -> u64 {
|
static fn decode(&self, d: &D) -> u64 {
|
||||||
d.read_u64()
|
d.read_u64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for int {
|
pub impl<S:Encoder> Encodable<S> for int {
|
||||||
fn encode(&self, s: &S) { s.emit_int(*self) }
|
fn encode(&self, s: &S) { s.emit_int(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for int {
|
pub impl<D:Decoder> Decodable<D> for int {
|
||||||
static fn decode(&self, d: &D) -> int {
|
static fn decode(&self, d: &D) -> int {
|
||||||
d.read_int()
|
d.read_int()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for i8 {
|
pub impl<S:Encoder> Encodable<S> for i8 {
|
||||||
fn encode(&self, s: &S) { s.emit_i8(*self) }
|
fn encode(&self, s: &S) { s.emit_i8(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for i8 {
|
pub impl<D:Decoder> Decodable<D> for i8 {
|
||||||
static fn decode(&self, d: &D) -> i8 {
|
static fn decode(&self, d: &D) -> i8 {
|
||||||
d.read_i8()
|
d.read_i8()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for i16 {
|
pub impl<S:Encoder> Encodable<S> for i16 {
|
||||||
fn encode(&self, s: &S) { s.emit_i16(*self) }
|
fn encode(&self, s: &S) { s.emit_i16(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for i16 {
|
pub impl<D:Decoder> Decodable<D> for i16 {
|
||||||
static fn decode(&self, d: &D) -> i16 {
|
static fn decode(&self, d: &D) -> i16 {
|
||||||
d.read_i16()
|
d.read_i16()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for i32 {
|
pub impl<S:Encoder> Encodable<S> for i32 {
|
||||||
fn encode(&self, s: &S) { s.emit_i32(*self) }
|
fn encode(&self, s: &S) { s.emit_i32(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for i32 {
|
pub impl<D:Decoder> Decodable<D> for i32 {
|
||||||
static fn decode(&self, d: &D) -> i32 {
|
static fn decode(&self, d: &D) -> i32 {
|
||||||
d.read_i32()
|
d.read_i32()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for i64 {
|
pub impl<S:Encoder> Encodable<S> for i64 {
|
||||||
fn encode(&self, s: &S) { s.emit_i64(*self) }
|
fn encode(&self, s: &S) { s.emit_i64(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for i64 {
|
pub impl<D:Decoder> Decodable<D> for i64 {
|
||||||
static fn decode(&self, d: &D) -> i64 {
|
static fn decode(&self, d: &D) -> i64 {
|
||||||
d.read_i64()
|
d.read_i64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for &str {
|
pub impl<S:Encoder> Encodable<S> for &str {
|
||||||
fn encode(&self, s: &S) { s.emit_borrowed_str(*self) }
|
fn encode(&self, s: &S) { s.emit_borrowed_str(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for ~str {
|
pub impl<S:Encoder> Encodable<S> for ~str {
|
||||||
fn encode(&self, s: &S) { s.emit_owned_str(*self) }
|
fn encode(&self, s: &S) { s.emit_owned_str(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for ~str {
|
pub impl<D:Decoder> Decodable<D> for ~str {
|
||||||
static fn decode(&self, d: &D) -> ~str {
|
static fn decode(&self, d: &D) -> ~str {
|
||||||
d.read_owned_str()
|
d.read_owned_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for @str {
|
pub impl<S:Encoder> Encodable<S> for @str {
|
||||||
fn encode(&self, s: &S) { s.emit_managed_str(*self) }
|
fn encode(&self, s: &S) { s.emit_managed_str(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for @str {
|
pub impl<D:Decoder> Decodable<D> for @str {
|
||||||
static fn decode(&self, d: &D) -> @str {
|
static fn decode(&self, d: &D) -> @str {
|
||||||
d.read_managed_str()
|
d.read_managed_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for float {
|
pub impl<S:Encoder> Encodable<S> for float {
|
||||||
fn encode(&self, s: &S) { s.emit_float(*self) }
|
fn encode(&self, s: &S) { s.emit_float(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for float {
|
pub impl<D:Decoder> Decodable<D> for float {
|
||||||
static fn decode(&self, d: &D) -> float {
|
static fn decode(&self, d: &D) -> float {
|
||||||
d.read_float()
|
d.read_float()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for f32 {
|
pub impl<S:Encoder> Encodable<S> for f32 {
|
||||||
fn encode(&self, s: &S) { s.emit_f32(*self) }
|
fn encode(&self, s: &S) { s.emit_f32(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for f32 {
|
pub impl<D:Decoder> Decodable<D> for f32 {
|
||||||
static fn decode(&self, d: &D) -> f32 {
|
static fn decode(&self, d: &D) -> f32 {
|
||||||
d.read_f32() }
|
d.read_f32() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for f64 {
|
pub impl<S:Encoder> Encodable<S> for f64 {
|
||||||
fn encode(&self, s: &S) { s.emit_f64(*self) }
|
fn encode(&self, s: &S) { s.emit_f64(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for f64 {
|
pub impl<D:Decoder> Decodable<D> for f64 {
|
||||||
static fn decode(&self, d: &D) -> f64 {
|
static fn decode(&self, d: &D) -> f64 {
|
||||||
d.read_f64()
|
d.read_f64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for bool {
|
pub impl<S:Encoder> Encodable<S> for bool {
|
||||||
fn encode(&self, s: &S) { s.emit_bool(*self) }
|
fn encode(&self, s: &S) { s.emit_bool(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for bool {
|
pub impl<D:Decoder> Decodable<D> for bool {
|
||||||
static fn decode(&self, d: &D) -> bool {
|
static fn decode(&self, d: &D) -> bool {
|
||||||
d.read_bool()
|
d.read_bool()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for () {
|
pub impl<S:Encoder> Encodable<S> for () {
|
||||||
fn encode(&self, s: &S) { s.emit_nil() }
|
fn encode(&self, s: &S) { s.emit_nil() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for () {
|
pub impl<D:Decoder> Decodable<D> for () {
|
||||||
static fn decode(&self, d: &D) -> () {
|
static fn decode(&self, d: &D) -> () {
|
||||||
d.read_nil()
|
d.read_nil()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for &T {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for &T {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
s.emit_borrowed(|| (**self).encode(s))
|
s.emit_borrowed(|| (**self).encode(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for ~T {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~T {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
s.emit_owned(|| (**self).encode(s))
|
s.emit_owned(|| (**self).encode(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for ~T {
|
pub impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~T {
|
||||||
static fn decode(&self, d: &D) -> ~T {
|
static fn decode(&self, d: &D) -> ~T {
|
||||||
d.read_owned(|| ~Decodable::decode(d))
|
d.read_owned(|| ~Decodable::decode(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for @T {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
s.emit_managed(|| (**self).encode(s))
|
s.emit_managed(|| (**self).encode(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for @T {
|
pub impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T {
|
||||||
static fn decode(&self, d: &D) -> @T {
|
static fn decode(&self, d: &D) -> @T {
|
||||||
d.read_managed(|| @Decodable::decode(d))
|
d.read_managed(|| @Decodable::decode(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for &[T] {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for &[T] {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
do s.emit_borrowed_vec(self.len()) {
|
do s.emit_borrowed_vec(self.len()) {
|
||||||
for self.eachi |i, e| {
|
for self.eachi |i, e| {
|
||||||
|
@ -326,7 +326,7 @@ pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for &[T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for ~[T] {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~[T] {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
do s.emit_owned_vec(self.len()) {
|
do s.emit_owned_vec(self.len()) {
|
||||||
for self.eachi |i, e| {
|
for self.eachi |i, e| {
|
||||||
|
@ -336,7 +336,7 @@ pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for ~[T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for ~[T] {
|
pub impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~[T] {
|
||||||
static fn decode(&self, d: &D) -> ~[T] {
|
static fn decode(&self, d: &D) -> ~[T] {
|
||||||
do d.read_owned_vec |len| {
|
do d.read_owned_vec |len| {
|
||||||
do vec::from_fn(len) |i| {
|
do vec::from_fn(len) |i| {
|
||||||
|
@ -346,7 +346,7 @@ pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for ~[T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for @[T] {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for @[T] {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
do s.emit_managed_vec(self.len()) {
|
do s.emit_managed_vec(self.len()) {
|
||||||
for self.eachi |i, e| {
|
for self.eachi |i, e| {
|
||||||
|
@ -356,7 +356,7 @@ pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for @[T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for @[T] {
|
pub impl<D:Decoder,T:Decodable<D>> Decodable<D> for @[T] {
|
||||||
static fn decode(&self, d: &D) -> @[T] {
|
static fn decode(&self, d: &D) -> @[T] {
|
||||||
do d.read_managed_vec |len| {
|
do d.read_managed_vec |len| {
|
||||||
do at_vec::from_fn(len) |i| {
|
do at_vec::from_fn(len) |i| {
|
||||||
|
@ -366,7 +366,7 @@ pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for @[T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
|
pub impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
do s.emit_enum(~"option") {
|
do s.emit_enum(~"option") {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -381,7 +381,7 @@ pub impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
|
pub impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> {
|
||||||
static fn decode(&self, d: &D) -> Option<T> {
|
static fn decode(&self, d: &D) -> Option<T> {
|
||||||
do d.read_enum(~"option") {
|
do d.read_enum(~"option") {
|
||||||
do d.read_enum_variant |i| {
|
do d.read_enum_variant |i| {
|
||||||
|
@ -396,7 +396,7 @@ pub impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder, T0: Encodable<S>, T1: Encodable<S>> Encodable<S>
|
pub impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S>
|
||||||
for (T0, T1) {
|
for (T0, T1) {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -410,7 +410,7 @@ pub impl<S: Encoder, T0: Encodable<S>, T1: Encodable<S>> Encodable<S>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder, T0: Decodable<D>, T1: Decodable<D>> Decodable<D>
|
pub impl<D:Decoder,T0:Decodable<D>,T1:Decodable<D>> Decodable<D>
|
||||||
for (T0, T1) {
|
for (T0, T1) {
|
||||||
static fn decode(&self, d: &D) -> (T0, T1) {
|
static fn decode(&self, d: &D) -> (T0, T1) {
|
||||||
do d.read_tup(2) {
|
do d.read_tup(2) {
|
||||||
|
@ -552,7 +552,7 @@ pub trait EncoderHelpers {
|
||||||
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T));
|
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> EncoderHelpers for S {
|
pub impl<S:Encoder> EncoderHelpers for S {
|
||||||
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T)) {
|
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T)) {
|
||||||
do self.emit_owned_vec(v.len()) {
|
do self.emit_owned_vec(v.len()) {
|
||||||
for v.eachi |i, e| {
|
for v.eachi |i, e| {
|
||||||
|
@ -568,7 +568,7 @@ pub trait DecoderHelpers {
|
||||||
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T];
|
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> DecoderHelpers for D {
|
pub impl<D:Decoder> DecoderHelpers for D {
|
||||||
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T] {
|
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T] {
|
||||||
do self.read_owned_vec |len| {
|
do self.read_owned_vec |len| {
|
||||||
do vec::from_fn(len) |i| {
|
do vec::from_fn(len) |i| {
|
||||||
|
|
|
@ -131,7 +131,7 @@ pub impl<V> SmallIntMap<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<V: Copy> SmallIntMap<V> {
|
pub impl<V:Copy> SmallIntMap<V> {
|
||||||
fn update_with_key(&mut self, key: uint, val: V,
|
fn update_with_key(&mut self, key: uint, val: V,
|
||||||
ff: fn(uint, V, V) -> V) -> bool {
|
ff: fn(uint, V, V) -> V) -> bool {
|
||||||
let new_val = match self.find(&key) {
|
let new_val = match self.find(&key) {
|
||||||
|
|
|
@ -25,12 +25,12 @@ type Le<T> = pure fn(v1: &T, v2: &T) -> bool;
|
||||||
* Has worst case O(n log n) performance, best case O(n), but
|
* Has worst case O(n log n) performance, best case O(n), but
|
||||||
* is not space efficient. This is a stable sort.
|
* is not space efficient. This is a stable sort.
|
||||||
*/
|
*/
|
||||||
pub pure fn merge_sort<T: Copy>(v: &[const T], le: Le<T>) -> ~[T] {
|
pub pure fn merge_sort<T:Copy>(v: &[const T], le: Le<T>) -> ~[T] {
|
||||||
type Slice = (uint, uint);
|
type Slice = (uint, uint);
|
||||||
|
|
||||||
unsafe {return merge_sort_(v, (0u, len(v)), le);}
|
unsafe {return merge_sort_(v, (0u, len(v)), le);}
|
||||||
|
|
||||||
fn merge_sort_<T: Copy>(v: &[const T], slice: Slice, le: Le<T>)
|
fn merge_sort_<T:Copy>(v: &[const T], slice: Slice, le: Le<T>)
|
||||||
-> ~[T] {
|
-> ~[T] {
|
||||||
let begin = slice.first();
|
let begin = slice.first();
|
||||||
let end = slice.second();
|
let end = slice.second();
|
||||||
|
@ -45,7 +45,7 @@ pub pure fn merge_sort<T: Copy>(v: &[const T], le: Le<T>) -> ~[T] {
|
||||||
return merge(le, merge_sort_(v, a, le), merge_sort_(v, b, le));
|
return merge(le, merge_sort_(v, a, le), merge_sort_(v, b, le));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge<T: Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
|
fn merge<T:Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
|
||||||
let mut rs = vec::with_capacity(len(a) + len(b));
|
let mut rs = vec::with_capacity(len(a) + len(b));
|
||||||
let a_len = len(a);
|
let a_len = len(a);
|
||||||
let mut a_ix = 0;
|
let mut a_ix = 0;
|
||||||
|
@ -103,7 +103,7 @@ pub fn quick_sort<T>(arr: &mut [T], compare_func: Le<T>) {
|
||||||
qsort::<T>(arr, 0u, len::<T>(arr) - 1u, compare_func);
|
qsort::<T>(arr, 0u, len::<T>(arr) - 1u, compare_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn qsort3<T: Copy Ord Eq>(arr: &mut [T], left: int, right: int) {
|
fn qsort3<T:Copy + Ord + Eq>(arr: &mut [T], left: int, right: int) {
|
||||||
if right <= left { return; }
|
if right <= left { return; }
|
||||||
let v: T = arr[right];
|
let v: T = arr[right];
|
||||||
let mut i: int = left - 1;
|
let mut i: int = left - 1;
|
||||||
|
@ -160,7 +160,7 @@ fn qsort3<T: Copy Ord Eq>(arr: &mut [T], left: int, right: int) {
|
||||||
*
|
*
|
||||||
* This is an unstable sort.
|
* This is an unstable sort.
|
||||||
*/
|
*/
|
||||||
pub fn quick_sort3<T: Copy Ord Eq>(arr: &mut [T]) {
|
pub fn quick_sort3<T:Copy + Ord + Eq>(arr: &mut [T]) {
|
||||||
if arr.len() <= 1 { return; }
|
if arr.len() <= 1 { return; }
|
||||||
qsort3(arr, 0, (arr.len() - 1) as int);
|
qsort3(arr, 0, (arr.len() - 1) as int);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ pub trait Sort {
|
||||||
fn qsort(self);
|
fn qsort(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy Ord Eq> Sort for &mut [T] {
|
impl<T:Copy + Ord + Eq> Sort for &mut [T] {
|
||||||
fn qsort(self) { quick_sort3(self); }
|
fn qsort(self) { quick_sort3(self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ const MIN_MERGE: uint = 64;
|
||||||
const MIN_GALLOP: uint = 7;
|
const MIN_GALLOP: uint = 7;
|
||||||
const INITIAL_TMP_STORAGE: uint = 128;
|
const INITIAL_TMP_STORAGE: uint = 128;
|
||||||
|
|
||||||
pub fn tim_sort<T: Copy Ord>(array: &mut [T]) {
|
pub fn tim_sort<T:Copy + Ord>(array: &mut [T]) {
|
||||||
let size = array.len();
|
let size = array.len();
|
||||||
if size < 2 {
|
if size < 2 {
|
||||||
return;
|
return;
|
||||||
|
@ -216,7 +216,7 @@ pub fn tim_sort<T: Copy Ord>(array: &mut [T]) {
|
||||||
ms.merge_force_collapse(array);
|
ms.merge_force_collapse(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn binarysort<T: Copy Ord>(array: &mut [T], start: uint) {
|
fn binarysort<T:Copy + Ord>(array: &mut [T], start: uint) {
|
||||||
let size = array.len();
|
let size = array.len();
|
||||||
let mut start = start;
|
let mut start = start;
|
||||||
assert start <= size;
|
assert start <= size;
|
||||||
|
@ -266,7 +266,7 @@ pure fn min_run_length(n: uint) -> uint {
|
||||||
return n + r;
|
return n + r;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_run_ascending<T: Copy Ord>(array: &mut [T]) -> uint {
|
fn count_run_ascending<T:Copy + Ord>(array: &mut [T]) -> uint {
|
||||||
let size = array.len();
|
let size = array.len();
|
||||||
assert size > 0;
|
assert size > 0;
|
||||||
if size == 1 { return 1; }
|
if size == 1 { return 1; }
|
||||||
|
@ -286,7 +286,7 @@ fn count_run_ascending<T: Copy Ord>(array: &mut [T]) -> uint {
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn gallop_left<T: Copy Ord>(key: &const T, array: &[const T],
|
pure fn gallop_left<T:Copy + Ord>(key: &const T, array: &[const T],
|
||||||
hint: uint) -> uint {
|
hint: uint) -> uint {
|
||||||
let size = array.len();
|
let size = array.len();
|
||||||
assert size != 0 && hint < size;
|
assert size != 0 && hint < size;
|
||||||
|
@ -335,7 +335,7 @@ pure fn gallop_left<T: Copy Ord>(key: &const T, array: &[const T],
|
||||||
return ofs;
|
return ofs;
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn gallop_right<T: Copy Ord>(key: &const T, array: &[const T],
|
pure fn gallop_right<T:Copy + Ord>(key: &const T, array: &[const T],
|
||||||
hint: uint) -> uint {
|
hint: uint) -> uint {
|
||||||
let size = array.len();
|
let size = array.len();
|
||||||
assert size != 0 && hint < size;
|
assert size != 0 && hint < size;
|
||||||
|
@ -404,7 +404,7 @@ fn MergeState<T>() -> MergeState<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy Ord> MergeState<T> {
|
impl<T:Copy + Ord> MergeState<T> {
|
||||||
fn push_run(&self, run_base: uint, run_len: uint) {
|
fn push_run(&self, run_base: uint, run_len: uint) {
|
||||||
let tmp = RunState{base: run_base, len: run_len};
|
let tmp = RunState{base: run_base, len: run_len};
|
||||||
self.runs.push(tmp);
|
self.runs.push(tmp);
|
||||||
|
@ -708,7 +708,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn copy_vec<T: Copy>(dest: &mut [T], s1: uint,
|
fn copy_vec<T:Copy>(dest: &mut [T], s1: uint,
|
||||||
from: &[const T], s2: uint, len: uint) {
|
from: &[const T], s2: uint, len: uint) {
|
||||||
assert s1+len <= dest.len() && s2+len <= from.len();
|
assert s1+len <= dest.len() && s2+len <= from.len();
|
||||||
|
|
||||||
|
@ -1019,7 +1019,7 @@ mod big_tests {
|
||||||
tabulate_managed(low, high);
|
tabulate_managed(low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn multiplyVec<T: Copy>(arr: &[const T], num: uint) -> ~[T] {
|
fn multiplyVec<T:Copy>(arr: &[const T], num: uint) -> ~[T] {
|
||||||
let size = arr.len();
|
let size = arr.len();
|
||||||
let res = do vec::from_fn(num) |i| {
|
let res = do vec::from_fn(num) |i| {
|
||||||
arr[i % size]
|
arr[i % size]
|
||||||
|
@ -1035,7 +1035,7 @@ mod big_tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tabulate_unique(lo: uint, hi: uint) {
|
fn tabulate_unique(lo: uint, hi: uint) {
|
||||||
fn isSorted<T: Ord>(arr: &[const T]) {
|
fn isSorted<T:Ord>(arr: &[const T]) {
|
||||||
for uint::range(0, arr.len()-1) |i| {
|
for uint::range(0, arr.len()-1) |i| {
|
||||||
if arr[i] > arr[i+1] {
|
if arr[i] > arr[i+1] {
|
||||||
fail!(~"Array not sorted");
|
fail!(~"Array not sorted");
|
||||||
|
@ -1107,7 +1107,7 @@ mod big_tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tabulate_managed(lo: uint, hi: uint) {
|
fn tabulate_managed(lo: uint, hi: uint) {
|
||||||
fn isSorted<T: Ord>(arr: &[const @T]) {
|
fn isSorted<T:Ord>(arr: &[const @T]) {
|
||||||
for uint::range(0, arr.len()-1) |i| {
|
for uint::range(0, arr.len()-1) |i| {
|
||||||
if arr[i] > arr[i+1] {
|
if arr[i] > arr[i+1] {
|
||||||
fail!(~"Array not sorted");
|
fail!(~"Array not sorted");
|
||||||
|
|
|
@ -84,7 +84,7 @@ struct SemInner<Q> {
|
||||||
enum Sem<Q> = Exclusive<SemInner<Q>>;
|
enum Sem<Q> = Exclusive<SemInner<Q>>;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn new_sem<Q: Owned>(count: int, q: Q) -> Sem<Q> {
|
fn new_sem<Q:Owned>(count: int, q: Q) -> Sem<Q> {
|
||||||
Sem(exclusive(SemInner {
|
Sem(exclusive(SemInner {
|
||||||
mut count: count, waiters: new_waitqueue(), blocked: q }))
|
mut count: count, waiters: new_waitqueue(), blocked: q }))
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
impl<Q: Owned> &Sem<Q> {
|
impl<Q:Owned> &Sem<Q> {
|
||||||
fn acquire() {
|
fn acquire() {
|
||||||
let mut waiter_nobe = None;
|
let mut waiter_nobe = None;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -167,7 +167,7 @@ type SemRelease = SemReleaseGeneric<()>;
|
||||||
type SemAndSignalRelease = SemReleaseGeneric<~[Waitqueue]>;
|
type SemAndSignalRelease = SemReleaseGeneric<~[Waitqueue]>;
|
||||||
struct SemReleaseGeneric<Q> { sem: &Sem<Q> }
|
struct SemReleaseGeneric<Q> { sem: &Sem<Q> }
|
||||||
|
|
||||||
impl<Q: Owned> Drop for SemReleaseGeneric<Q> {
|
impl<Q:Owned> Drop for SemReleaseGeneric<Q> {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
self.sem.release();
|
self.sem.release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ use core;
|
||||||
* * ch - a channel of type T to send a `val` on
|
* * ch - a channel of type T to send a `val` on
|
||||||
* * val - a value of type T to send over the provided `ch`
|
* * val - a value of type T to send over the provided `ch`
|
||||||
*/
|
*/
|
||||||
pub fn delayed_send<T: Owned>(iotask: &IoTask,
|
pub fn delayed_send<T:Owned>(iotask: &IoTask,
|
||||||
msecs: uint,
|
msecs: uint,
|
||||||
ch: &Chan<T>,
|
ch: &Chan<T>,
|
||||||
val: T) {
|
val: T) {
|
||||||
|
@ -123,7 +123,7 @@ pub fn sleep(iotask: &IoTask, msecs: uint) {
|
||||||
* on the provided port in the allotted timeout period, then the result will
|
* on the provided port in the allotted timeout period, then the result will
|
||||||
* be a `Some(T)`. If not, then `None` will be returned.
|
* be a `Some(T)`. If not, then `None` will be returned.
|
||||||
*/
|
*/
|
||||||
pub fn recv_timeout<T: Copy Owned>(iotask: &IoTask,
|
pub fn recv_timeout<T:Copy + Owned>(iotask: &IoTask,
|
||||||
msecs: uint,
|
msecs: uint,
|
||||||
wait_po: &Port<T>)
|
wait_po: &Port<T>)
|
||||||
-> Option<T> {
|
-> Option<T> {
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub struct TreeMap<K, V> {
|
||||||
priv length: uint
|
priv length: uint
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Eq Ord, V: Eq> Eq for TreeMap<K, V> {
|
impl<K:Eq + Ord,V:Eq> Eq for TreeMap<K, V> {
|
||||||
pure fn eq(&self, other: &TreeMap<K, V>) -> bool {
|
pure fn eq(&self, other: &TreeMap<K, V>) -> bool {
|
||||||
if self.len() != other.len() {
|
if self.len() != other.len() {
|
||||||
false
|
false
|
||||||
|
@ -66,7 +66,7 @@ impl<K: Eq Ord, V: Eq> Eq for TreeMap<K, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lexicographical comparison
|
// Lexicographical comparison
|
||||||
pure fn lt<K: Ord, V>(a: &TreeMap<K, V>, b: &TreeMap<K, V>) -> bool {
|
pure fn lt<K:Ord,V>(a: &TreeMap<K, V>, b: &TreeMap<K, V>) -> bool {
|
||||||
let mut x = a.iter();
|
let mut x = a.iter();
|
||||||
let mut y = b.iter();
|
let mut y = b.iter();
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ pure fn lt<K: Ord, V>(a: &TreeMap<K, V>, b: &TreeMap<K, V>) -> bool {
|
||||||
return a_len < b_len;
|
return a_len < b_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> Ord for TreeMap<K, V> {
|
impl<K:Ord,V> Ord for TreeMap<K, V> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &TreeMap<K, V>) -> bool {
|
pure fn lt(&self, other: &TreeMap<K, V>) -> bool {
|
||||||
lt(self, other)
|
lt(self, other)
|
||||||
|
@ -104,7 +104,7 @@ impl<K: Ord, V> Ord for TreeMap<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> BaseIter<(&K, &V)> for TreeMap<K, V> {
|
impl<K:Ord,V> BaseIter<(&K, &V)> for TreeMap<K, V> {
|
||||||
/// Visit all key-value pairs in order
|
/// Visit all key-value pairs in order
|
||||||
pure fn each(&self, f: fn(&(&self/K, &self/V)) -> bool) {
|
pure fn each(&self, f: fn(&(&self/K, &self/V)) -> bool) {
|
||||||
each(&self.root, f)
|
each(&self.root, f)
|
||||||
|
@ -112,14 +112,14 @@ impl<K: Ord, V> BaseIter<(&K, &V)> for TreeMap<K, V> {
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> ReverseIter<(&K, &V)> for TreeMap<K, V> {
|
impl<K:Ord,V> ReverseIter<(&K, &V)> for TreeMap<K, V> {
|
||||||
/// Visit all key-value pairs in reverse order
|
/// Visit all key-value pairs in reverse order
|
||||||
pure fn each_reverse(&self, f: fn(&(&self/K, &self/V)) -> bool) {
|
pure fn each_reverse(&self, f: fn(&(&self/K, &self/V)) -> bool) {
|
||||||
each_reverse(&self.root, f);
|
each_reverse(&self.root, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> Container for TreeMap<K, V> {
|
impl<K:Ord,V> Container for TreeMap<K, V> {
|
||||||
/// Return the number of elements in the map
|
/// Return the number of elements in the map
|
||||||
pure fn len(&self) -> uint { self.length }
|
pure fn len(&self) -> uint { self.length }
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ impl<K: Ord, V> Container for TreeMap<K, V> {
|
||||||
pure fn is_empty(&self) -> bool { self.root.is_none() }
|
pure fn is_empty(&self) -> bool { self.root.is_none() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> Mutable for TreeMap<K, V> {
|
impl<K:Ord,V> Mutable for TreeMap<K, V> {
|
||||||
/// Clear the map, removing all key-value pairs.
|
/// Clear the map, removing all key-value pairs.
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.root = None;
|
self.root = None;
|
||||||
|
@ -135,7 +135,7 @@ impl<K: Ord, V> Mutable for TreeMap<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> Map<K, V> for TreeMap<K, V> {
|
impl<K:Ord,V> Map<K, V> for TreeMap<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, key: &K) -> bool {
|
pure fn contains_key(&self, key: &K) -> bool {
|
||||||
self.find(key).is_some()
|
self.find(key).is_some()
|
||||||
|
@ -184,7 +184,7 @@ impl<K: Ord, V> Map<K, V> for TreeMap<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <K: Ord, V> TreeMap<K, V> {
|
impl <K:Ord,V> TreeMap<K, V> {
|
||||||
/// Create an empty TreeMap
|
/// Create an empty TreeMap
|
||||||
static pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
|
static pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ pub struct TreeMapIterator<K, V> {
|
||||||
priv current: Option<&~TreeNode<K, V>>
|
priv current: Option<&~TreeNode<K, V>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <K: Ord, V> TreeMapIterator<K, V> {
|
impl <K:Ord,V> TreeMapIterator<K, V> {
|
||||||
// Returns the current node, or None if this iterator is at the end.
|
// Returns the current node, or None if this iterator is at the end.
|
||||||
fn get(&const self) -> Option<(&self/K, &self/V)> {
|
fn get(&const self) -> Option<(&self/K, &self/V)> {
|
||||||
match self.current {
|
match self.current {
|
||||||
|
@ -224,7 +224,7 @@ impl <K: Ord, V> TreeMapIterator<K, V> {
|
||||||
|
|
||||||
/// Advance the iterator to the next node (in order). If this iterator
|
/// Advance the iterator to the next node (in order). If this iterator
|
||||||
/// is finished, does nothing.
|
/// is finished, does nothing.
|
||||||
pub fn map_next<K: Ord, V>(iter: &mut TreeMapIterator/&a<K, V>) {
|
pub fn map_next<K:Ord,V>(iter: &mut TreeMapIterator/&a<K, V>) {
|
||||||
while !iter.stack.is_empty() || iter.node.is_some() {
|
while !iter.stack.is_empty() || iter.node.is_some() {
|
||||||
match *iter.node {
|
match *iter.node {
|
||||||
Some(ref x) => {
|
Some(ref x) => {
|
||||||
|
@ -246,25 +246,25 @@ pub struct TreeSet<T> {
|
||||||
priv map: TreeMap<T, ()>
|
priv map: TreeMap<T, ()>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> BaseIter<T> for TreeSet<T> {
|
impl<T:Ord> BaseIter<T> for TreeSet<T> {
|
||||||
/// Visit all values in order
|
/// Visit all values in order
|
||||||
pure fn each(&self, f: fn(&T) -> bool) { self.map.each_key(f) }
|
pure fn each(&self, f: fn(&T) -> bool) { self.map.each_key(f) }
|
||||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> ReverseIter<T> for TreeSet<T> {
|
impl<T:Ord> ReverseIter<T> for TreeSet<T> {
|
||||||
/// Visit all values in reverse order
|
/// Visit all values in reverse order
|
||||||
pure fn each_reverse(&self, f: fn(&T) -> bool) {
|
pure fn each_reverse(&self, f: fn(&T) -> bool) {
|
||||||
self.map.each_key_reverse(f)
|
self.map.each_key_reverse(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Eq Ord> Eq for TreeSet<T> {
|
impl<T:Eq + Ord> Eq for TreeSet<T> {
|
||||||
pure fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
|
pure fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
|
||||||
pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
|
pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Ord for TreeSet<T> {
|
impl<T:Ord> Ord for TreeSet<T> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map }
|
pure fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -275,7 +275,7 @@ impl<T: Ord> Ord for TreeSet<T> {
|
||||||
pure fn gt(&self, other: &TreeSet<T>) -> bool { self.map > other.map }
|
pure fn gt(&self, other: &TreeSet<T>) -> bool { self.map > other.map }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Container for TreeSet<T> {
|
impl<T:Ord> Container for TreeSet<T> {
|
||||||
/// Return the number of elements in the set
|
/// Return the number of elements in the set
|
||||||
pure fn len(&self) -> uint { self.map.len() }
|
pure fn len(&self) -> uint { self.map.len() }
|
||||||
|
|
||||||
|
@ -283,12 +283,12 @@ impl<T: Ord> Container for TreeSet<T> {
|
||||||
pure fn is_empty(&self) -> bool { self.map.is_empty() }
|
pure fn is_empty(&self) -> bool { self.map.is_empty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Mutable for TreeSet<T> {
|
impl<T:Ord> Mutable for TreeSet<T> {
|
||||||
/// Clear the set, removing all values.
|
/// Clear the set, removing all values.
|
||||||
fn clear(&mut self) { self.map.clear() }
|
fn clear(&mut self) { self.map.clear() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Set<T> for TreeSet<T> {
|
impl<T:Ord> Set<T> for TreeSet<T> {
|
||||||
/// Return true if the set contains a value
|
/// Return true if the set contains a value
|
||||||
pure fn contains(&self, value: &T) -> bool {
|
pure fn contains(&self, value: &T) -> bool {
|
||||||
self.map.contains_key(value)
|
self.map.contains_key(value)
|
||||||
|
@ -510,7 +510,7 @@ impl<T: Ord> Set<T> for TreeSet<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <T: Ord> TreeSet<T> {
|
impl <T:Ord> TreeSet<T> {
|
||||||
/// Create an empty TreeSet
|
/// Create an empty TreeSet
|
||||||
static pure fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
static pure fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ pub struct TreeSetIterator<T> {
|
||||||
priv iter: TreeMapIterator<T, ()>
|
priv iter: TreeMapIterator<T, ()>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <T: Ord> TreeSetIterator<T> {
|
impl <T:Ord> TreeSetIterator<T> {
|
||||||
/// Returns the current node, or None if this iterator is at the end.
|
/// Returns the current node, or None if this iterator is at the end.
|
||||||
fn get(&const self) -> Option<&self/T> {
|
fn get(&const self) -> Option<&self/T> {
|
||||||
match self.iter.get() {
|
match self.iter.get() {
|
||||||
|
@ -538,7 +538,7 @@ impl <T: Ord> TreeSetIterator<T> {
|
||||||
|
|
||||||
/// Advance the iterator to the next node (in order). If this iterator is
|
/// Advance the iterator to the next node (in order). If this iterator is
|
||||||
/// finished, does nothing.
|
/// finished, does nothing.
|
||||||
pub fn set_next<T: Ord>(iter: &mut TreeSetIterator/&a<T>) {
|
pub fn set_next<T:Ord>(iter: &mut TreeSetIterator/&a<T>) {
|
||||||
map_next(&mut iter.iter);
|
map_next(&mut iter.iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,14 +552,14 @@ struct TreeNode<K, V> {
|
||||||
level: uint
|
level: uint
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <K: Ord, V> TreeNode<K, V> {
|
impl <K:Ord,V> TreeNode<K, V> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
static pure fn new(key: K, value: V) -> TreeNode<K, V> {
|
static pure fn new(key: K, value: V) -> TreeNode<K, V> {
|
||||||
TreeNode{key: key, value: value, left: None, right: None, level: 1}
|
TreeNode{key: key, value: value, left: None, right: None, level: 1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn each<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
|
pure fn each<K:Ord,V>(node: &r/Option<~TreeNode<K, V>>,
|
||||||
f: fn(&(&r/K, &r/V)) -> bool) {
|
f: fn(&(&r/K, &r/V)) -> bool) {
|
||||||
do node.iter |x| {
|
do node.iter |x| {
|
||||||
each(&x.left, f);
|
each(&x.left, f);
|
||||||
|
@ -567,7 +567,7 @@ pure fn each<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn each_reverse<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
|
pure fn each_reverse<K:Ord,V>(node: &r/Option<~TreeNode<K, V>>,
|
||||||
f: fn(&(&r/K, &r/V)) -> bool) {
|
f: fn(&(&r/K, &r/V)) -> bool) {
|
||||||
do node.iter |x| {
|
do node.iter |x| {
|
||||||
each_reverse(&x.right, f);
|
each_reverse(&x.right, f);
|
||||||
|
@ -576,7 +576,7 @@ pure fn each_reverse<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove left horizontal link by rotating right
|
// Remove left horizontal link by rotating right
|
||||||
fn skew<K: Ord, V>(node: &mut ~TreeNode<K, V>) {
|
fn skew<K:Ord,V>(node: &mut ~TreeNode<K, V>) {
|
||||||
if node.left.map_default(false, |x| x.level == node.level) {
|
if node.left.map_default(false, |x| x.level == node.level) {
|
||||||
let mut save = node.left.swap_unwrap();
|
let mut save = node.left.swap_unwrap();
|
||||||
node.left <-> save.right; // save.right now None
|
node.left <-> save.right; // save.right now None
|
||||||
|
@ -587,7 +587,7 @@ fn skew<K: Ord, V>(node: &mut ~TreeNode<K, V>) {
|
||||||
|
|
||||||
// Remove dual horizontal link by rotating left and increasing level of
|
// Remove dual horizontal link by rotating left and increasing level of
|
||||||
// the parent
|
// the parent
|
||||||
fn split<K: Ord, V>(node: &mut ~TreeNode<K, V>) {
|
fn split<K:Ord,V>(node: &mut ~TreeNode<K, V>) {
|
||||||
if node.right.map_default(false,
|
if node.right.map_default(false,
|
||||||
|x| x.right.map_default(false, |y| y.level == node.level)) {
|
|x| x.right.map_default(false, |y| y.level == node.level)) {
|
||||||
let mut save = node.right.swap_unwrap();
|
let mut save = node.right.swap_unwrap();
|
||||||
|
@ -598,7 +598,7 @@ fn split<K: Ord, V>(node: &mut ~TreeNode<K, V>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: K,
|
fn insert<K:Ord,V>(node: &mut Option<~TreeNode<K, V>>, key: K,
|
||||||
value: V) -> bool {
|
value: V) -> bool {
|
||||||
match *node {
|
match *node {
|
||||||
Some(ref mut save) => {
|
Some(ref mut save) => {
|
||||||
|
@ -625,8 +625,8 @@ fn insert<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: K,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
|
fn remove<K:Ord,V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
|
||||||
fn heir_swap<K: Ord, V>(node: &mut ~TreeNode<K, V>,
|
fn heir_swap<K:Ord,V>(node: &mut ~TreeNode<K, V>,
|
||||||
child: &mut Option<~TreeNode<K, V>>) {
|
child: &mut Option<~TreeNode<K, V>>) {
|
||||||
// *could* be done without recursion, but it won't borrow check
|
// *could* be done without recursion, but it won't borrow check
|
||||||
do child.mutate |mut child| {
|
do child.mutate |mut child| {
|
||||||
|
@ -772,7 +772,7 @@ mod test_treemap {
|
||||||
assert m.find(&k1) == Some(&v1);
|
assert m.find(&k1) == Some(&v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_equal<K: Eq Ord, V: Eq>(ctrl: &[(K, V)], map: &TreeMap<K, V>) {
|
fn check_equal<K:Eq + Ord,V:Eq>(ctrl: &[(K, V)], map: &TreeMap<K, V>) {
|
||||||
assert ctrl.is_empty() == map.is_empty();
|
assert ctrl.is_empty() == map.is_empty();
|
||||||
for ctrl.each |x| {
|
for ctrl.each |x| {
|
||||||
let &(k, v) = x;
|
let &(k, v) = x;
|
||||||
|
@ -792,7 +792,7 @@ mod test_treemap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_left<K: Ord, V>(node: &Option<~TreeNode<K, V>>,
|
fn check_left<K:Ord,V>(node: &Option<~TreeNode<K, V>>,
|
||||||
parent: &~TreeNode<K, V>) {
|
parent: &~TreeNode<K, V>) {
|
||||||
match *node {
|
match *node {
|
||||||
Some(ref r) => {
|
Some(ref r) => {
|
||||||
|
@ -805,7 +805,7 @@ mod test_treemap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_right<K: Ord, V>(node: &Option<~TreeNode<K, V>>,
|
fn check_right<K:Ord,V>(node: &Option<~TreeNode<K, V>>,
|
||||||
parent: &~TreeNode<K, V>, parent_red: bool) {
|
parent: &~TreeNode<K, V>, parent_red: bool) {
|
||||||
match *node {
|
match *node {
|
||||||
Some(ref r) => {
|
Some(ref r) => {
|
||||||
|
@ -820,7 +820,7 @@ mod test_treemap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_structure<K: Ord, V>(map: &TreeMap<K, V>) {
|
fn check_structure<K:Ord,V>(map: &TreeMap<K, V>) {
|
||||||
match map.root {
|
match map.root {
|
||||||
Some(ref r) => {
|
Some(ref r) => {
|
||||||
check_left(&r.left, r);
|
check_left(&r.left, r);
|
||||||
|
|
|
@ -138,7 +138,7 @@ impl WorkKey {
|
||||||
|
|
||||||
type WorkMap = LinearMap<WorkKey, ~str>;
|
type WorkMap = LinearMap<WorkKey, ~str>;
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for WorkMap {
|
pub impl<S:Encoder> Encodable<S> for WorkMap {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
let mut d = ~[];
|
let mut d = ~[];
|
||||||
for self.each |&(k, v)| {
|
for self.each |&(k, v)| {
|
||||||
|
@ -149,7 +149,7 @@ pub impl<S: Encoder> Encodable<S> for WorkMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for WorkMap {
|
pub impl<D:Decoder> Decodable<D> for WorkMap {
|
||||||
static fn decode(&self, d: &D) -> WorkMap {
|
static fn decode(&self, d: &D) -> WorkMap {
|
||||||
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
||||||
let mut w = LinearMap::new();
|
let mut w = LinearMap::new();
|
||||||
|
|
|
@ -32,7 +32,7 @@ macro_rules! interner_key (
|
||||||
#[deriving_eq]
|
#[deriving_eq]
|
||||||
pub struct ident { repr: uint }
|
pub struct ident { repr: uint }
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for ident {
|
pub impl<S:Encoder> Encodable<S> for ident {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
let intr = match unsafe {
|
let intr = match unsafe {
|
||||||
task::local_data::local_data_get(interner_key!())
|
task::local_data::local_data_get(interner_key!())
|
||||||
|
@ -45,7 +45,7 @@ pub impl<S: Encoder> Encodable<S> for ident {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for ident {
|
pub impl<D:Decoder> Decodable<D> for ident {
|
||||||
static fn decode(d: &D) -> ident {
|
static fn decode(d: &D) -> ident {
|
||||||
let intr = match unsafe {
|
let intr = match unsafe {
|
||||||
task::local_data::local_data_get(interner_key!())
|
task::local_data::local_data_get(interner_key!())
|
||||||
|
@ -383,7 +383,7 @@ pub enum inferable<T> {
|
||||||
infer(node_id)
|
infer(node_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> {
|
pub impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> {
|
||||||
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
|
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
|
||||||
match *self {
|
match *self {
|
||||||
expl(ref t) =>
|
expl(ref t) =>
|
||||||
|
|
|
@ -140,12 +140,12 @@ pub impl cmp::Eq for span {
|
||||||
pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
|
pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<S: Encoder> Encodable<S> for span {
|
pub impl<S:Encoder> Encodable<S> for span {
|
||||||
/* Note #1972 -- spans are encoded but not decoded */
|
/* Note #1972 -- spans are encoded but not decoded */
|
||||||
fn encode(&self, _s: &S) { }
|
fn encode(&self, _s: &S) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<D: Decoder> Decodable<D> for span {
|
pub impl<D:Decoder> Decodable<D> for span {
|
||||||
static fn decode(_d: &D) -> span {
|
static fn decode(_d: &D) -> span {
|
||||||
dummy_sp()
|
dummy_sp()
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect<T: Copy>(diag: span_handler,
|
pub fn expect<T:Copy>(diag: span_handler,
|
||||||
opt: Option<T>,
|
opt: Option<T>,
|
||||||
msg: fn() -> ~str) -> T {
|
msg: fn() -> ~str) -> T {
|
||||||
match opt {
|
match opt {
|
||||||
|
|
|
@ -23,7 +23,7 @@ For example, a type like:
|
||||||
|
|
||||||
would generate two implementations like:
|
would generate two implementations like:
|
||||||
|
|
||||||
impl<S: std::serialize::Encoder> Encodable<S> for Node {
|
impl<S:std::serialize::Encoder> Encodable<S> for Node {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
do s.emit_struct("Node", 1) {
|
do s.emit_struct("Node", 1) {
|
||||||
s.emit_field("id", 0, || s.emit_uint(self.id))
|
s.emit_field("id", 0, || s.emit_uint(self.id))
|
||||||
|
@ -31,7 +31,7 @@ impl<S: std::serialize::Encoder> Encodable<S> for Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Decoder> Decodable for node_id {
|
impl<D:Decoder> Decodable for node_id {
|
||||||
static fn decode(d: &D) -> Node {
|
static fn decode(d: &D) -> Node {
|
||||||
do d.read_struct("Node", 1) {
|
do d.read_struct("Node", 1) {
|
||||||
Node {
|
Node {
|
||||||
|
@ -54,7 +54,7 @@ would yield functions like:
|
||||||
S: Encoder,
|
S: Encoder,
|
||||||
T: Encodable<S>
|
T: Encodable<S>
|
||||||
> spanned<T>: Encodable<S> {
|
> spanned<T>: Encodable<S> {
|
||||||
fn encode<S: Encoder>(s: &S) {
|
fn encode<S:Encoder>(s: &S) {
|
||||||
do s.emit_rec {
|
do s.emit_rec {
|
||||||
s.emit_field("node", 0, || self.node.encode(s));
|
s.emit_field("node", 0, || self.node.encode(s));
|
||||||
s.emit_field("span", 1, || self.span.encode(s));
|
s.emit_field("span", 1, || self.span.encode(s));
|
||||||
|
|
|
@ -319,7 +319,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||||
+items: ~[@ast::item]) -> @ast::item {
|
+items: ~[@ast::item]) -> @ast::item {
|
||||||
|
|
||||||
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
||||||
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
|
// parser bug whereby `fn f<T:::kinds::Owned>` doesn't parse.
|
||||||
let vi = ast::view_item_use(~[
|
let vi = ast::view_item_use(~[
|
||||||
@codemap::spanned {
|
@codemap::spanned {
|
||||||
node: ast::view_path_simple(
|
node: ast::view_path_simple(
|
||||||
|
|
|
@ -212,7 +212,7 @@ pub impl Parser {
|
||||||
|
|
||||||
// parse a sequence bracketed by '<' and '>', stopping
|
// parse a sequence bracketed by '<' and '>', stopping
|
||||||
// before the '>'.
|
// before the '>'.
|
||||||
fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::Token>,
|
fn parse_seq_to_before_gt<T:Copy>(sep: Option<token::Token>,
|
||||||
f: fn(Parser) -> T) -> ~[T] {
|
f: fn(Parser) -> T) -> ~[T] {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
|
@ -231,7 +231,7 @@ pub impl Parser {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_seq_to_gt<T: Copy>(sep: Option<token::Token>,
|
fn parse_seq_to_gt<T:Copy>(sep: Option<token::Token>,
|
||||||
f: fn(Parser) -> T) -> ~[T] {
|
f: fn(Parser) -> T) -> ~[T] {
|
||||||
let v = self.parse_seq_to_before_gt(sep, f);
|
let v = self.parse_seq_to_before_gt(sep, f);
|
||||||
self.expect_gt();
|
self.expect_gt();
|
||||||
|
@ -240,7 +240,7 @@ pub impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a sequence bracketed by '<' and '>'
|
// parse a sequence bracketed by '<' and '>'
|
||||||
fn parse_seq_lt_gt<T: Copy>(sep: Option<token::Token>,
|
fn parse_seq_lt_gt<T:Copy>(sep: Option<token::Token>,
|
||||||
f: fn(Parser) -> T) -> spanned<~[T]> {
|
f: fn(Parser) -> T) -> spanned<~[T]> {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(token::LT);
|
self.expect(token::LT);
|
||||||
|
@ -253,7 +253,7 @@ pub impl Parser {
|
||||||
// parse a sequence, including the closing delimiter. The function
|
// parse a sequence, including the closing delimiter. The function
|
||||||
// f must consume tokens until reaching the next separator or
|
// f must consume tokens until reaching the next separator or
|
||||||
// closing bracket.
|
// closing bracket.
|
||||||
fn parse_seq_to_end<T: Copy>(ket: token::Token, sep: seq_sep,
|
fn parse_seq_to_end<T:Copy>(ket: token::Token, sep: seq_sep,
|
||||||
f: fn(Parser) -> T) -> ~[T] {
|
f: fn(Parser) -> T) -> ~[T] {
|
||||||
let val = self.parse_seq_to_before_end(ket, sep, f);
|
let val = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -263,7 +263,7 @@ pub impl Parser {
|
||||||
// parse a sequence, not including the closing delimiter. The function
|
// parse a sequence, not including the closing delimiter. The function
|
||||||
// f must consume tokens until reaching the next separator or
|
// f must consume tokens until reaching the next separator or
|
||||||
// closing bracket.
|
// closing bracket.
|
||||||
fn parse_seq_to_before_end<T: Copy>(ket: token::Token, sep: seq_sep,
|
fn parse_seq_to_before_end<T:Copy>(ket: token::Token, sep: seq_sep,
|
||||||
f: fn(Parser) -> T) -> ~[T] {
|
f: fn(Parser) -> T) -> ~[T] {
|
||||||
let mut first: bool = true;
|
let mut first: bool = true;
|
||||||
let mut v: ~[T] = ~[];
|
let mut v: ~[T] = ~[];
|
||||||
|
@ -284,7 +284,7 @@ pub impl Parser {
|
||||||
// parse a sequence, including the closing delimiter. The function
|
// parse a sequence, including the closing delimiter. The function
|
||||||
// f must consume tokens until reaching the next separator or
|
// f must consume tokens until reaching the next separator or
|
||||||
// closing bracket.
|
// closing bracket.
|
||||||
fn parse_unspanned_seq<T: Copy>(bra: token::Token,
|
fn parse_unspanned_seq<T:Copy>(bra: token::Token,
|
||||||
ket: token::Token,
|
ket: token::Token,
|
||||||
sep: seq_sep,
|
sep: seq_sep,
|
||||||
f: fn(Parser) -> T) -> ~[T] {
|
f: fn(Parser) -> T) -> ~[T] {
|
||||||
|
@ -296,7 +296,7 @@ pub impl Parser {
|
||||||
|
|
||||||
// NB: Do not use this function unless you actually plan to place the
|
// NB: Do not use this function unless you actually plan to place the
|
||||||
// spanned list in the AST.
|
// spanned list in the AST.
|
||||||
fn parse_seq<T: Copy>(bra: token::Token, ket: token::Token, sep: seq_sep,
|
fn parse_seq<T:Copy>(bra: token::Token, ket: token::Token, sep: seq_sep,
|
||||||
f: fn(Parser) -> T) -> spanned<~[T]> {
|
f: fn(Parser) -> T) -> spanned<~[T]> {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(bra);
|
self.expect(bra);
|
||||||
|
|
|
@ -2282,7 +2282,7 @@ pub mod test {
|
||||||
//use util;
|
//use util;
|
||||||
use util::testing::check_equal;
|
use util::testing::check_equal;
|
||||||
|
|
||||||
fn string_check<T : Eq> (given : &T, expected: &T) {
|
fn string_check<T:Eq> (given : &T, expected: &T) {
|
||||||
if !(given == expected) {
|
if !(given == expected) {
|
||||||
fail!(fmt!("given %?, expected %?",given,expected));
|
fail!(fmt!("given %?, expected %?",given,expected));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub struct Interner<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// when traits can extend traits, we should extend index<uint,T> to get []
|
// when traits can extend traits, we should extend index<uint,T> to get []
|
||||||
pub impl<T: Eq IterBytes Hash Const Copy> Interner<T> {
|
pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
|
||||||
static fn new() -> Interner<T> {
|
static fn new() -> Interner<T> {
|
||||||
Interner {
|
Interner {
|
||||||
map: LinearMap::new(),
|
map: LinearMap::new(),
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
// support for test cases.
|
// support for test cases.
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
|
|
||||||
pub pure fn check_equal_ptr<T : cmp::Eq> (given : &T, expected: &T) {
|
pub pure fn check_equal_ptr<T:cmp::Eq> (given : &T, expected: &T) {
|
||||||
if !((given == expected) && (expected == given )) {
|
if !((given == expected) && (expected == given )) {
|
||||||
fail!(fmt!("given %?, expected %?",given,expected));
|
fail!(fmt!("given %?, expected %?",given,expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn check_equal<T : cmp::Eq> (given : T, expected: T) {
|
pub pure fn check_equal<T:cmp::Eq> (given : T, expected: T) {
|
||||||
if !((given == expected) && (expected == given )) {
|
if !((given == expected) && (expected == given )) {
|
||||||
fail!(fmt!("given %?, expected %?",given,expected));
|
fail!(fmt!("given %?, expected %?",given,expected));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use core::pipes::*;
|
use core::pipes::*;
|
||||||
|
|
||||||
pub fn foo<T: Owned Copy>(x: T) -> Port<T> {
|
pub fn foo<T:Owned + Copy>(x: T) -> Port<T> {
|
||||||
let (p, c) = stream();
|
let (p, c) = stream();
|
||||||
do task::spawn() {
|
do task::spawn() {
|
||||||
c.send(x);
|
c.send(x);
|
||||||
|
|
|
@ -16,11 +16,11 @@ pub struct Entry<A,B> {key: A, value: B}
|
||||||
|
|
||||||
pub struct alist<A,B> { eq_fn: fn@(A,A) -> bool, data: DVec<Entry<A,B>> }
|
pub struct alist<A,B> { eq_fn: fn@(A,A) -> bool, data: DVec<Entry<A,B>> }
|
||||||
|
|
||||||
pub fn alist_add<A: Copy, B: Copy>(lst: alist<A,B>, k: A, v: B) {
|
pub fn alist_add<A:Copy,B:Copy>(lst: alist<A,B>, k: A, v: B) {
|
||||||
lst.data.push(Entry{key:k, value:v});
|
lst.data.push(Entry{key:k, value:v});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn alist_get<A: Copy, B: Copy>(lst: alist<A,B>, k: A) -> B {
|
pub fn alist_get<A:Copy,B:Copy>(lst: alist<A,B>, k: A) -> B {
|
||||||
let eq_fn = lst.eq_fn;
|
let eq_fn = lst.eq_fn;
|
||||||
for lst.data.each |entry| {
|
for lst.data.each |entry| {
|
||||||
if eq_fn(entry.key, k) { return entry.value; }
|
if eq_fn(entry.key, k) { return entry.value; }
|
||||||
|
@ -29,13 +29,13 @@ pub fn alist_get<A: Copy, B: Copy>(lst: alist<A,B>, k: A) -> B {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_int_alist<B: Copy>() -> alist<int, B> {
|
pub fn new_int_alist<B:Copy>() -> alist<int, B> {
|
||||||
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return alist {eq_fn: eq_int, data: DVec()};
|
return alist {eq_fn: eq_int, data: DVec()};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_int_alist_2<B: Copy>() -> alist<int, B> {
|
pub fn new_int_alist_2<B:Copy>() -> alist<int, B> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return alist {eq_fn: eq_int, data: DVec()};
|
return alist {eq_fn: eq_int, data: DVec()};
|
||||||
|
|
|
@ -23,13 +23,13 @@ impl<T:Const> Drop for arc_destruct<T> {
|
||||||
fn finalize(&self) {}
|
fn finalize(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arc_destruct<T: Const>(data: int) -> arc_destruct<T> {
|
fn arc_destruct<T:Const>(data: int) -> arc_destruct<T> {
|
||||||
arc_destruct {
|
arc_destruct {
|
||||||
_data: data
|
_data: data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arc<T: Const>(_data: T) -> arc_destruct<T> {
|
fn arc<T:Const>(_data: T) -> arc_destruct<T> {
|
||||||
arc_destruct(0)
|
arc_destruct(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,6 @@ use std::oldmap::HashMap;
|
||||||
pub type header_map = HashMap<~str, @DVec<@~str>>;
|
pub type header_map = HashMap<~str, @DVec<@~str>>;
|
||||||
|
|
||||||
// the unused ty param is necessary so this gets monomorphized
|
// the unused ty param is necessary so this gets monomorphized
|
||||||
pub fn request<T: Copy>(req: header_map) {
|
pub fn request<T:Copy>(req: header_map) {
|
||||||
let _x = copy *(copy *req.get(&~"METHOD"))[0u];
|
let _x = copy *(copy *req.get(&~"METHOD"))[0u];
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,6 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub fn to_closure<A: Durable Copy>(x: A) -> @fn() -> A {
|
pub fn to_closure<A:Durable + Copy>(x: A) -> @fn() -> A {
|
||||||
fn@() -> A { copy x }
|
fn@() -> A { copy x }
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl read for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read<T: read Copy>(s: ~str) -> T {
|
pub fn read<T:read + Copy>(s: ~str) -> T {
|
||||||
match read::readMaybe(s) {
|
match read::readMaybe(s) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
_ => fail!(~"read failed!")
|
_ => fail!(~"read failed!")
|
||||||
|
|
|
@ -14,4 +14,4 @@ trait Baz { fn h() -> int; }
|
||||||
|
|
||||||
trait Quux: Foo Bar Baz { }
|
trait Quux: Foo Bar Baz { }
|
||||||
|
|
||||||
impl<T: Foo Bar Baz> Quux for T { }
|
impl<T:Foo + Bar + Baz> Quux for T { }
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn timed(result: &mut float, op: fn()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Results {
|
impl Results {
|
||||||
fn bench_int<T: Set<uint>>(&mut self, rng: @rand::Rng, num_keys: uint,
|
fn bench_int<T:Set<uint>>(&mut self, rng: @rand::Rng, num_keys: uint,
|
||||||
rand_cap: uint, f: fn() -> T) {
|
rand_cap: uint, f: fn() -> T) {
|
||||||
{
|
{
|
||||||
let mut set = f();
|
let mut set = f();
|
||||||
|
@ -70,7 +70,7 @@ impl Results {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bench_str<T: Set<~str>>(&mut self, rng: @rand::Rng, num_keys: uint,
|
fn bench_str<T:Set<~str>>(&mut self, rng: @rand::Rng, num_keys: uint,
|
||||||
f: fn() -> T) {
|
f: fn() -> T) {
|
||||||
{
|
{
|
||||||
let mut set = f();
|
let mut set = f();
|
||||||
|
|
|
@ -72,7 +72,7 @@ macro_rules! follow (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fn switch<T: Owned, Tb: Owned, U>(+endp: pipes::RecvPacketBuffered<T, Tb>,
|
fn switch<T:Owned,Tb:Owned,U>(+endp: pipes::RecvPacketBuffered<T, Tb>,
|
||||||
f: fn(+v: Option<T>) -> U) -> U {
|
f: fn(+v: Option<T>) -> U) -> U {
|
||||||
f(pipes::try_recv(endp))
|
f(pipes::try_recv(endp))
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
|
||||||
return (xx as float) * 100f / (yy as float);
|
return (xx as float) * 100f / (yy as float);
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn le_by_val<TT: Copy, UU: Copy Ord>(kv0: &(TT,UU),
|
pure fn le_by_val<TT:Copy,UU:Copy + Ord>(kv0: &(TT,UU),
|
||||||
kv1: &(TT,UU)) -> bool {
|
kv1: &(TT,UU)) -> bool {
|
||||||
let (_, v0) = *kv0;
|
let (_, v0) = *kv0;
|
||||||
let (_, v1) = *kv1;
|
let (_, v1) = *kv1;
|
||||||
return v0 >= v1;
|
return v0 >= v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn le_by_key<TT: Copy Ord, UU: Copy>(kv0: &(TT,UU),
|
pure fn le_by_key<TT:Copy + Ord,UU:Copy>(kv0: &(TT,UU),
|
||||||
kv1: &(TT,UU)) -> bool {
|
kv1: &(TT,UU)) -> bool {
|
||||||
let (k0, _) = *kv0;
|
let (k0, _) = *kv0;
|
||||||
let (k1, _) = *kv1;
|
let (k1, _) = *kv1;
|
||||||
|
@ -42,7 +42,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort by key, then by value
|
// sort by key, then by value
|
||||||
fn sortKV<TT: Copy Ord, UU: Copy Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
|
fn sortKV<TT:Copy + Ord,UU:Copy + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
|
||||||
return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val);
|
return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
trait A { fn foo(); }
|
trait A { fn foo(); }
|
||||||
trait B { fn foo(); }
|
trait B { fn foo(); }
|
||||||
|
|
||||||
fn foo<T: A B>(t: T) {
|
fn foo<T:A + B>(t: T) {
|
||||||
t.foo(); //~ ERROR multiple applicable methods in scope
|
t.foo(); //~ ERROR multiple applicable methods in scope
|
||||||
//~^ NOTE candidate #1 derives from the bound `A`
|
//~^ NOTE candidate #1 derives from the bound `A`
|
||||||
//~^^ NOTE candidate #2 derives from the bound `B`
|
//~^^ NOTE candidate #2 derives from the bound `B`
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
use iter::BaseIter;
|
use iter::BaseIter;
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fn b<C:Copy Const, D>(x: C) -> C;
|
fn b<C:Copy + Const,D>(x: C) -> C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct E {
|
struct E {
|
||||||
|
@ -24,7 +24,7 @@ struct E {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl A for E {
|
impl A for E {
|
||||||
fn b<F:Copy, G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 1 bound, but
|
fn b<F:Copy,G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 1 bound, but
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
use iter::BaseIter;
|
use iter::BaseIter;
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fn b<C:Copy, D>(x: C) -> C;
|
fn b<C:Copy,D>(x: C) -> C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct E {
|
struct E {
|
||||||
|
@ -21,7 +21,7 @@ struct E {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl A for E {
|
impl A for E {
|
||||||
fn b<F:Copy Const, G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 2 bounds, but
|
fn b<F:Copy + Const,G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 2 bounds, but
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
use iter::BaseIter;
|
use iter::BaseIter;
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fn b<C:Copy, D>(x: C) -> C;
|
fn b<C:Copy,D>(x: C) -> C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct E {
|
struct E {
|
||||||
|
@ -22,7 +22,7 @@ struct E {
|
||||||
|
|
||||||
impl A for E {
|
impl A for E {
|
||||||
// n.b. The error message is awful -- see #3404
|
// n.b. The error message is awful -- see #3404
|
||||||
fn b<F:Copy, G>(_x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type
|
fn b<F:Copy,G>(_x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub mod stream {
|
pub mod stream {
|
||||||
pub enum Stream<T: Owned> { send(T, ::stream::server::Stream<T>), }
|
pub enum Stream<T:Owned> { send(T, ::stream::server::Stream<T>), }
|
||||||
pub mod server {
|
pub mod server {
|
||||||
use core::option;
|
use core::option;
|
||||||
use core::pipes;
|
use core::pipes;
|
||||||
|
|
||||||
impl<T: Owned> Stream<T> {
|
impl<T:Owned> Stream<T> {
|
||||||
pub fn recv() -> extern fn(+v: Stream<T>) -> ::stream::Stream<T> {
|
pub fn recv() -> extern fn(+v: Stream<T>) -> ::stream::Stream<T> {
|
||||||
// resolve really should report just one error here.
|
// resolve really should report just one error here.
|
||||||
// Change the test case when it changes.
|
// Change the test case when it changes.
|
||||||
|
@ -28,7 +28,7 @@ pub mod stream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Stream<T: Owned> = pipes::RecvPacket<::stream::Stream<T>>;
|
pub type Stream<T:Owned> = pipes::RecvPacket<::stream::Stream<T>>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// xfail-test
|
// xfail-test
|
||||||
// error-pattern: instantiating a type parameter with an incompatible type
|
// error-pattern: instantiating a type parameter with an incompatible type
|
||||||
struct S<T: Const> {
|
struct S<T:Const> {
|
||||||
s: T,
|
s: T,
|
||||||
mut cant_nest: ()
|
mut cant_nest: ()
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ fn to_foo_2<T:Copy>(t: T) -> foo {
|
||||||
{f:t} as foo //~ ERROR value may contain borrowed pointers; use `&static` bound
|
{f:t} as foo //~ ERROR value may contain borrowed pointers; use `&static` bound
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_foo_3<T:Copy &static>(t: T) -> foo {
|
fn to_foo_3<T:Copy + &static>(t: T) -> foo {
|
||||||
// OK---T may escape as part of the returned foo value, but it is
|
// OK---T may escape as part of the returned foo value, but it is
|
||||||
// owned and hence does not contain borrowed ptrs
|
// owned and hence does not contain borrowed ptrs
|
||||||
{f:t} as foo
|
{f:t} as foo
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
trait foo { fn foo(); }
|
trait foo { fn foo(); }
|
||||||
|
|
||||||
fn to_foo<T: Copy foo>(t: T) -> foo {
|
fn to_foo<T:Copy + foo>(t: T) -> foo {
|
||||||
t as foo //~ ERROR value may contain borrowed pointers; use `&static` bound
|
t as foo //~ ERROR value may contain borrowed pointers; use `&static` bound
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_foo2<T: Copy foo &static>(t: T) -> foo {
|
fn to_foo2<T:Copy + foo + &static>(t: T) -> foo {
|
||||||
t as foo
|
t as foo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn copy1<T: Copy>(t: T) -> fn@() -> T {
|
fn copy1<T:Copy>(t: T) -> fn@() -> T {
|
||||||
fn@() -> T { t } //~ ERROR value may contain borrowed pointers
|
fn@() -> T { t } //~ ERROR value may contain borrowed pointers
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy2<T: Copy &static>(t: T) -> fn@() -> T {
|
fn copy2<T:Copy + &static>(t: T) -> fn@() -> T {
|
||||||
fn@() -> T { t }
|
fn@() -> T { t }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn send<T: Owned>(ch: _chan<T>, -data: T) {
|
fn send<T:Owned>(ch: _chan<T>, -data: T) {
|
||||||
log(debug, ch);
|
log(debug, ch);
|
||||||
log(debug, data);
|
log(debug, data);
|
||||||
fail!();
|
fail!();
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue