Skip to content

MutableIter impl for Option + use it in treemap #5395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)]
19 changes: 5 additions & 14 deletions src/libstd/treemap.rs
Original file line number Diff line number Diff line change
@@ -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> {
@@ -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;
@@ -718,7 +709,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
}

*node = None;
return true;
true
}

#[cfg(test)]