std: More demoding
This commit is contained in:
parent
565b39b302
commit
74a46ea74c
5 changed files with 27 additions and 27 deletions
|
|
@ -137,17 +137,17 @@ impl BigBitv {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn each_storage(op: fn(&v: uint) -> bool) {
|
||||
fn each_storage(op: fn(v: &mut uint) -> bool) {
|
||||
for uint::range(0, self.storage.len()) |i| {
|
||||
let mut w = self.storage[i];
|
||||
let b = !op(w);
|
||||
let b = !op(&mut w);
|
||||
self.storage[i] = w;
|
||||
if !b { break; }
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn invert() { for self.each_storage() |w| { w = !w } }
|
||||
fn invert() { for self.each_storage() |w| { *w = !*w } }
|
||||
|
||||
#[inline(always)]
|
||||
fn union(b: &BigBitv, nbits: uint) -> bool {
|
||||
|
|
@ -337,7 +337,7 @@ impl Bitv {
|
|||
* bitvectors contain identical elements.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn equal(v1: Bitv) -> bool {
|
||||
fn equal(v1: &Bitv) -> bool {
|
||||
if self.nbits != v1.nbits { return false; }
|
||||
match self.rep {
|
||||
Small(ref b) => match v1.rep {
|
||||
|
|
@ -356,7 +356,7 @@ impl Bitv {
|
|||
fn clear() {
|
||||
match self.rep {
|
||||
Small(ref b) => b.clear(),
|
||||
Big(ref s) => for s.each_storage() |w| { w = 0u }
|
||||
Big(ref s) => for s.each_storage() |w| { *w = 0u }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -365,7 +365,7 @@ impl Bitv {
|
|||
fn set_all() {
|
||||
match self.rep {
|
||||
Small(ref b) => b.set_all(),
|
||||
Big(ref s) => for s.each_storage() |w| { w = !0u } }
|
||||
Big(ref s) => for s.each_storage() |w| { *w = !0u } }
|
||||
}
|
||||
|
||||
/// Invert all bits
|
||||
|
|
@ -373,7 +373,7 @@ impl Bitv {
|
|||
fn invert() {
|
||||
match self.rep {
|
||||
Small(ref b) => b.invert(),
|
||||
Big(ref s) => for s.each_storage() |w| { w = !w } }
|
||||
Big(ref s) => for s.each_storage() |w| { *w = !*w } }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -386,7 +386,7 @@ impl Bitv {
|
|||
* Returns `true` if `v0` was changed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn difference(v: ~Bitv) -> bool { self.do_op(Difference, v) }
|
||||
fn difference(v: &Bitv) -> bool { self.do_op(Difference, v) }
|
||||
|
||||
/// Returns true if all bits are 1
|
||||
#[inline(always)]
|
||||
|
|
@ -863,14 +863,14 @@ mod tests {
|
|||
fn test_equal_differing_sizes() {
|
||||
let v0 = Bitv(10u, false);
|
||||
let v1 = Bitv(11u, false);
|
||||
assert !v0.equal(v1);
|
||||
assert !v0.equal(&v1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_equal_greatly_differing_sizes() {
|
||||
let v0 = Bitv(10u, false);
|
||||
let v1 = Bitv(110u, false);
|
||||
assert !v0.equal(v1);
|
||||
assert !v0.equal(&v1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -881,7 +881,7 @@ mod tests {
|
|||
let b = bitv::Bitv(1, true);
|
||||
b.set(0, true);
|
||||
|
||||
assert a.equal(b);
|
||||
assert a.equal(&b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -896,7 +896,7 @@ mod tests {
|
|||
b.set(i, true);
|
||||
}
|
||||
|
||||
assert a.equal(b);
|
||||
assert a.equal(&b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
|
|||
*
|
||||
* Fails if `ofs` is greater or equal to the length of the vector
|
||||
*/
|
||||
fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
|
||||
fn set<T: Copy>(t: CVec<T>, ofs: uint, +v: T) {
|
||||
assert ofs < len(t);
|
||||
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ use core::cmp::{Eq};
|
|||
|
||||
trait Deque<T> {
|
||||
fn size() -> uint;
|
||||
fn add_front(T);
|
||||
fn add_back(T);
|
||||
fn add_front(+v: T);
|
||||
fn add_back(+v: T);
|
||||
fn pop_front() -> T;
|
||||
fn pop_back() -> T;
|
||||
fn peek_front() -> T;
|
||||
|
|
@ -55,7 +55,7 @@ fn create<T: Copy>() -> Deque<T> {
|
|||
|
||||
impl <T: Copy> Repr<T>: Deque<T> {
|
||||
fn size() -> uint { return self.nelts; }
|
||||
fn add_front(t: T) {
|
||||
fn add_front(+t: T) {
|
||||
let oldlo: uint = self.lo;
|
||||
if self.lo == 0u {
|
||||
self.lo = self.elts.len() - 1u;
|
||||
|
|
@ -68,7 +68,7 @@ fn create<T: Copy>() -> Deque<T> {
|
|||
self.elts.set_elt(self.lo, Some(t));
|
||||
self.nelts += 1u;
|
||||
}
|
||||
fn add_back(t: T) {
|
||||
fn add_back(+t: T) {
|
||||
if self.lo == self.hi && self.nelts != 0u {
|
||||
self.elts.swap(|v| grow(self.nelts, self.lo, move v));
|
||||
self.lo = 0u;
|
||||
|
|
|
|||
|
|
@ -738,7 +738,7 @@ impl TcpSocket {
|
|||
result::Result<~[u8], TcpErrData>>, TcpErrData> {
|
||||
read_start(&self)
|
||||
}
|
||||
fn read_stop(-read_port:
|
||||
fn read_stop(+read_port:
|
||||
comm::Port<result::Result<~[u8], TcpErrData>>) ->
|
||||
result::Result<(), TcpErrData> {
|
||||
read_stop(&self, move read_port)
|
||||
|
|
|
|||
|
|
@ -72,21 +72,21 @@ fn map_slices<A: Copy Send, B: Copy Send>(
|
|||
}
|
||||
|
||||
/// A parallel version of map.
|
||||
pub fn map<A: Copy Send, B: Copy Send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] {
|
||||
pub fn map<A: Copy Send, B: Copy Send>(xs: &[A], f: fn~((&A)) -> B) -> ~[B] {
|
||||
vec::concat(map_slices(xs, || {
|
||||
fn~(_base: uint, slice : &[A], copy f) -> ~[B] {
|
||||
vec::map(slice, |x| f(*x))
|
||||
vec::map(slice, |x| f(x))
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/// A parallel version of mapi.
|
||||
pub fn mapi<A: Copy Send, B: Copy Send>(xs: ~[A],
|
||||
f: fn~(uint, A) -> B) -> ~[B] {
|
||||
pub fn mapi<A: Copy Send, B: Copy Send>(xs: &[A],
|
||||
f: fn~(uint, (&A)) -> B) -> ~[B] {
|
||||
let slices = map_slices(xs, || {
|
||||
fn~(base: uint, slice : &[A], copy f) -> ~[B] {
|
||||
vec::mapi(slice, |i, x| {
|
||||
f(i + base, *x)
|
||||
f(i + base, x)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
@ -119,21 +119,21 @@ pub fn mapi_factory<A: Copy Send, B: Copy Send>(
|
|||
}
|
||||
|
||||
/// Returns true if the function holds for all elements in the vector.
|
||||
pub fn alli<A: Copy Send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool {
|
||||
pub fn alli<A: Copy Send>(xs: &[A], f: fn~(uint, (&A)) -> bool) -> bool {
|
||||
do vec::all(map_slices(xs, || {
|
||||
fn~(base: uint, slice : &[A], copy f) -> bool {
|
||||
vec::alli(slice, |i, x| {
|
||||
f(i + base, *x)
|
||||
f(i + base, x)
|
||||
})
|
||||
}
|
||||
})) |x| { *x }
|
||||
}
|
||||
|
||||
/// Returns true if the function holds for any elements in the vector.
|
||||
pub fn any<A: Copy Send>(xs: ~[A], f: fn~(A) -> bool) -> bool {
|
||||
pub fn any<A: Copy Send>(xs: &[A], f: fn~(&(A)) -> bool) -> bool {
|
||||
do vec::any(map_slices(xs, || {
|
||||
fn~(_base : uint, slice: &[A], copy f) -> bool {
|
||||
vec::any(slice, |x| f(*x))
|
||||
vec::any(slice, |x| f(x))
|
||||
}
|
||||
})) |x| { *x }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue