Struct hashlink::linked_hash_map::CursorMut
source · pub struct CursorMut<'a, K, V, S> { /* private fields */ }
Expand description
The CursorMut
struct and its implementation provide the basic mutable Cursor API for Linked
lists as proposed in
here, with
several exceptions:
- It behaves similarly to Rust’s Iterators, returning
None
when the end of the list is reached. A guard node is positioned between the head and tail of the linked list to facilitate this. If the cursor is over this guard node,None
is returned, signaling the end or start of the list. From this position, the cursor can move in either direction as the linked list is circular, with the guard node connecting the two ends. - The current implementation does not include an
index
method, as it does not track the index of its elements. It provides access to each map entry as a tuple of(&K, &mut V)
.
Implementations§
source§impl<'a, K, V, S> CursorMut<'a, K, V, S>
impl<'a, K, V, S> CursorMut<'a, K, V, S>
sourcepub fn current(&mut self) -> Option<(&K, &mut V)>
pub fn current(&mut self) -> Option<(&K, &mut V)>
Returns an Option
of the current element in the list, provided it is not the
guard node, and None
overwise.
sourcepub fn peek_next(&mut self) -> Option<(&K, &mut V)>
pub fn peek_next(&mut self) -> Option<(&K, &mut V)>
Retrieves the next element in the list (moving towards the end).
sourcepub fn peek_prev(&mut self) -> Option<(&K, &mut V)>
pub fn peek_prev(&mut self) -> Option<(&K, &mut V)>
Retrieves the previous element in the list (moving towards the front).
sourcepub fn move_next(&mut self)
pub fn move_next(&mut self)
Updates the pointer to the current element to the next element in the list (that is, moving towards the end).
sourcepub fn move_prev(&mut self)
pub fn move_prev(&mut self)
Updates the pointer to the current element to the previous element in the list (that is, moving towards the front).
sourcepub fn insert_before(&mut self, key: K, value: V) -> Option<V>
pub fn insert_before(&mut self, key: K, value: V) -> Option<V>
Inserts the provided key and value before the current element. It checks if an entry
with the given key exists and, if so, replaces its value with the provided key
parameter. The key is not updated; this matters for types that can be ==
without
being identical.
If the entry doesn’t exist, it creates a new one. If a value has been updated, the
function returns the old value wrapped with Some
and None
otherwise.
sourcepub fn insert_after(&mut self, key: K, value: V) -> Option<V>
pub fn insert_after(&mut self, key: K, value: V) -> Option<V>
Inserts the provided key and value after the current element. It checks if an entry
with the given key exists and, if so, replaces its value with the provided key
parameter. The key is not updated; this matters for types that can be ==
without
being identical.
If the entry doesn’t exist, it creates a new one. If a value has been updated, the
function returns the old value wrapped with Some
and None
otherwise.