std: Demode more of list and treemap

This commit is contained in:
Brian Anderson
2012-09-26 18:12:07 -07:00
parent 5424f21d5d
commit 0ec267b276
4 changed files with 8 additions and 8 deletions

View File

@@ -63,7 +63,7 @@ struct Arena {
unsafe { unsafe {
destroy_chunk(&self.head); destroy_chunk(&self.head);
for list::each(self.chunks) |chunk| { for list::each(self.chunks) |chunk| {
if !chunk.is_pod { destroy_chunk(&chunk); } if !chunk.is_pod { destroy_chunk(chunk); }
} }
} }
} }

View File

@@ -59,7 +59,7 @@ 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
fn has<T: Copy Eq>(ls: @List<T>, +elt: T) -> bool { 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; }
} }
return false; return false;
} }
@@ -135,11 +135,11 @@ fn iter<T>(l: @List<T>, f: fn((&T))) {
} }
/// Iterate over a list /// Iterate over a list
fn each<T>(l: @List<T>, f: fn(T) -> bool) { fn each<T>(l: @List<T>, f: fn((&T)) -> bool) {
let mut cur = l; let mut cur = l;
loop { loop {
cur = match *cur { cur = match *cur {
Cons(hd, tl) => { Cons(ref hd, tl) => {
if !f(hd) { return; } if !f(hd) { return; }
tl tl
} }

View File

@@ -73,13 +73,13 @@ fn find<K: Copy Eq Ord, V: Copy>(m: &const TreeEdge<K, V>, +k: K)
} }
/// Visit all pairs in the map in order. /// Visit all pairs in the map in order.
fn traverse<K, V: Copy>(m: &const TreeEdge<K, V>, f: fn(K, V)) { fn traverse<K, V: Copy>(m: &const TreeEdge<K, V>, f: fn((&K), (&V))) {
match copy *m { match copy *m {
None => (), None => (),
Some(node) => { Some(node) => {
traverse(&const node.left, f); traverse(&const node.left, f);
// copy of value is req'd as f() requires an immutable ptr // copy of value is req'd as f() requires an immutable ptr
f(node.key, copy node.value); f(&node.key, &copy node.value);
traverse(&const node.right, f); traverse(&const node.right, f);
} }
} }
@@ -130,7 +130,7 @@ mod tests {
fn t(n: @mut int, +k: int, +_v: ()) { fn t(n: @mut int, +k: int, +_v: ()) {
assert (*n == k); *n += 1; assert (*n == k); *n += 1;
} }
traverse(m, |x,y| t(n, x, y)); traverse(m, |x,y| t(n, *x, *y));
} }
#[test] #[test]

View File

@@ -181,7 +181,7 @@ impl isr_alist: get_and_find_region {
fn find(br: ty::bound_region) -> Option<ty::region> { fn find(br: ty::bound_region) -> Option<ty::region> {
for list::each(self) |isr| { for list::each(self) |isr| {
let (isr_br, isr_r) = isr; let (isr_br, isr_r) = *isr;
if isr_br == br { return Some(isr_r); } if isr_br == br { return Some(isr_r); }
} }
return None; return None;