pub struct PIterator<K, V>{ /* private fields */ }Expand description
An effort to emulate a C++ std::map iterator in Rust. It will have functionality like: prev(), next(), get(), erase(), lower_bound(), replace_key()
Implementations§
Source§impl<K, V> PIterator<K, V>
impl<K, V> PIterator<K, V>
Sourcepub fn new(list: Rc<RefCell<LinkedList<K, V>>>) -> Result<Self, MapError>
pub fn new(list: Rc<RefCell<LinkedList<K, V>>>) -> Result<Self, MapError>
Initiates the pointer with a list, set current to the head of the list.
Sourcepub fn new_2(list: Rc<RefCell<LinkedList<K, V>>>, current: usize) -> Self
pub fn new_2(list: Rc<RefCell<LinkedList<K, V>>>, current: usize) -> Self
Initiates the pointer with a list, set index.
Sourcepub fn next(&mut self) -> Result<(), MapError>
pub fn next(&mut self) -> Result<(), MapError>
Move to the next element. Note that this is NOT a Rust iterator next() method. Always check validity of the iterator with is_ok() after next()
Sourcepub fn prev(&mut self) -> Result<(), MapError>
pub fn prev(&mut self) -> Result<(), MapError>
Move to the previous element Always check validity of the iterator with is_ok() after prev()
Sourcepub fn move_to_head(&mut self) -> Result<(), MapError>
pub fn move_to_head(&mut self) -> Result<(), MapError>
Move to the first element
Sourcepub fn move_to_tail(&mut self) -> Result<(), MapError>
pub fn move_to_tail(&mut self) -> Result<(), MapError>
Move to the last element
Sourcepub fn is_ok(&self) -> Result<bool, MapError>
pub fn is_ok(&self) -> Result<bool, MapError>
Return true if pointer has NOT moved past beginning or end of the list
Sourcepub fn is_at_head(&self) -> Result<bool, MapError>
pub fn is_at_head(&self) -> Result<bool, MapError>
Return true if pointer is at head position or if the list is empty
Sourcepub fn is_at_tail(&self) -> Result<bool, MapError>
pub fn is_at_tail(&self) -> Result<bool, MapError>
Return true if pointer is at tail position or if the list is empty
Sourcepub fn replace_key(&mut self, key: K) -> Result<(), MapError>
pub fn replace_key(&mut self, key: K) -> Result<(), MapError>
Replace current key. This will destroy the internal order of element if you replace an element with something out of order.
Sourcepub fn remove_current(&mut self) -> Result<(K, V), MapError>
pub fn remove_current(&mut self) -> Result<(K, V), MapError>
Remove the current element and return it. Move current to the old prev value if exist. Else pick old next index. Note: make sure that there are no other Pointer objects at this position.
Sourcepub fn lower_bound(
list: Rc<RefCell<LinkedList<K, V>>>,
key: K,
) -> Result<Self, MapError>
pub fn lower_bound( list: Rc<RefCell<LinkedList<K, V>>>, key: K, ) -> Result<Self, MapError>
Returns a new Pointer positioned at the lower bound item. Lower bound item is the first element in the container whose key is not considered to go before position (i.e., either it is equivalent or goes after). Returns a Pointer where is_ok() returns false if no data is found