-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement rbtree iterators, increment version to 0.10.3
- Loading branch information
1 parent
820dedb
commit ed2942b
Showing
7 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::internal::rb_tree::node::Node; | ||
use std::marker::PhantomData; | ||
|
||
/// An iterator over a Red-Black tree's nodes. | ||
pub struct Iter<'a, K, V> { | ||
pub(super) node: *mut Node<K, V>, | ||
pub(super) _marker: PhantomData<&'a ()>, | ||
} | ||
|
||
pub struct IterMut<'a, K, V> { | ||
pub(super) node: *mut Node<K, V>, | ||
pub(super) _marker: PhantomData<&'a mut ()>, | ||
} | ||
|
||
impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> { | ||
type Item = (&'a K, &'a V); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
unsafe { self.node.as_ref() } | ||
.and_then(Node::next) | ||
.map(|node| (node.key(), node.val())) | ||
} | ||
} | ||
|
||
impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> { | ||
type Item = (&'a K, &'a mut V); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
unsafe { self.node.as_mut() } | ||
.and_then(Node::next_mut) | ||
.map(|node| (&node.pair.0, &mut node.pair.1)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters