Skip to content

Commit

Permalink
MutableIter impl for Option + use it in treemap
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Mar 15, 2013
1 parent c3fe0b9 commit a49ccee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use ops::Add;
use kinds::Copy;
use util;
use num::Zero;
use iter::BaseIter;
use iter::{BaseIter, MutableIter};

#[cfg(test)] use ptr;
#[cfg(test)] use str;
Expand Down Expand Up @@ -323,6 +323,13 @@ impl<T> BaseIter<T> for Option<T> {
}
}
impl<T> MutableIter<T> for Option<T> {
#[inline(always)]
fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) {
match *self { None => (), Some(ref mut t) => { f(t); } }
}
}
pub impl<T> Option<T> {
/// Returns true if the option equals `none`
#[inline(always)]
Expand Down
19 changes: 5 additions & 14 deletions src/libstd/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
}
};

return a_len < b_len;
a_len < b_len
}

impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> {
Expand Down Expand Up @@ -694,22 +694,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,

skew(save);

match save.right {
Some(ref mut right) => {
for save.right.each_mut |right| {
skew(right);
match right.right {
Some(ref mut x) => { skew(x) },
None => ()
}
}
None => ()
for right.right.each_mut |x| { skew(x) }
}

split(save);
match save.right {
Some(ref mut x) => { split(x) },
None => ()
}
for save.right.each_mut |x| { split(x) }
}

return removed;
Expand All @@ -718,7 +709,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
}

*node = None;
return true;
true
}

#[cfg(test)]
Expand Down

5 comments on commit a49ccee

@bors
Copy link
Contributor

@bors bors commented on a49ccee Mar 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a49ccee Mar 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/iter = a49ccee into auto

@bors
Copy link
Contributor

@bors bors commented on a49ccee Mar 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/iter = a49ccee merged ok, testing candidate = c724dae

@bors
Copy link
Contributor

@bors bors commented on a49ccee Mar 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a49ccee Mar 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = c724dae

Please sign in to comment.