pub struct LinkedList<K, V>{ /* private fields */ }Expand description
A LinkedList implementation that mimics std::map behavior from C++
- Supports bidirectional iteration
- Uses only the less-than operation for comparisons
- Provides hint-based insertion
Implementations§
Source§impl<K, V> LinkedList<K, V>
impl<K, V> LinkedList<K, V>
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check if a key exists in the LinkedList
Sourcepub fn get(&self, search_key: &K) -> Option<&V>
pub fn get(&self, search_key: &K) -> Option<&V>
Get a reference to the value associated with a key
Sourcepub fn get_at(&self, index: Index) -> Option<(&K, &V)>
pub fn get_at(&self, index: Index) -> Option<(&K, &V)>
Get a reference to the key and value at a given node index
Sourcepub fn get_k_at(&self, index: Index) -> Option<&K>
pub fn get_k_at(&self, index: Index) -> Option<&K>
Get a reference to the key and value at a given node index
Sourcepub fn get_v_at(&self, index: Index) -> Option<&V>
pub fn get_v_at(&self, index: Index) -> Option<&V>
Get a reference to the key and value at a given node index
Sourcepub fn get_kv(&self, search_key: &K) -> Option<(&K, &V)>
pub fn get_kv(&self, search_key: &K) -> Option<(&K, &V)>
Get a reference to the value associated with a key
Sourcepub fn get_mut(&mut self, search_key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, search_key: &K) -> Option<&mut V>
Get a mutable reference to the value associated with a key
Source§impl<K, V> LinkedList<K, V>
impl<K, V> LinkedList<K, V>
Sourcepub fn insert_with_hint(
&mut self,
key: K,
value: V,
hint: Index,
) -> Result<Index, CppMapError>
pub fn insert_with_hint( &mut self, key: K, value: V, hint: Index, ) -> Result<Index, CppMapError>
Insert a key-value pair at the specified pos if possible. Returns the index of the inserted node Does nothing if that exact key already exists in the list
Sourcepub fn insert(&mut self, key: K, value: V) -> Result<Index, CppMapError>
pub fn insert(&mut self, key: K, value: V) -> Result<Index, CppMapError>
Insert a key-value pair Returns the index of the inserted node Does nothing if that exact key already exists in the list
Source§impl<K, V> LinkedList<K, V>
impl<K, V> LinkedList<K, V>
Source§impl<K, V> LinkedList<K, V>
impl<K, V> LinkedList<K, V>
pub fn sequential_find_position( &self, key: &K, hint_position: Index, ) -> Option<Index>
Sourcepub fn lower_bound(&self, key: &K) -> Option<Index>
pub fn lower_bound(&self, key: &K) -> Option<Index>
Emulates the C++ std::map.lower_bound() Returns a cursor pointing at the first element that is greater or equal than the given key.
Sourcepub fn upper_bound(&self, key: &K) -> Option<Index>
pub fn upper_bound(&self, key: &K) -> Option<Index>
Emulates the C++ std::map.upper_bound() Returns a cursor pointing at the first element in the map whose key is greater than the given key
Sourcepub fn next_pos(&self, current: Option<Index>) -> Option<Index>
pub fn next_pos(&self, current: Option<Index>) -> Option<Index>
Get the next node index (for iterator-like traversal)
Sourcepub fn prev_pos(&self, current: Option<Index>) -> Option<Index>
pub fn prev_pos(&self, current: Option<Index>) -> Option<Index>
Get the previous node index (for bidirectional iterator-like traversal)
pub fn is_pos_valid(&self, index: Option<Index>) -> bool
Sourcepub fn is_at_first(&self, pos: Option<Index>) -> bool
pub fn is_at_first(&self, pos: Option<Index>) -> bool
Return true if pointer is at head position or if the list is empty
Sourcepub fn is_at_last(&self, pos: Option<Index>) -> bool
pub fn is_at_last(&self, pos: Option<Index>) -> bool
Return true if pointer is at tail position or if the list is empty
Sourcepub fn change_key_of_node(
&mut self,
index: Index,
new_key: K,
) -> Result<Index, CppMapError>
pub fn change_key_of_node( &mut self, index: Index, new_key: K, ) -> Result<Index, CppMapError>
Danger zone: replace the key of a specific node. This is only supposed to be done on keys that evaluates as identical
Source§impl<K, V> LinkedList<K, V>
impl<K, V> LinkedList<K, V>
Sourcepub fn remove_by_index(
&mut self,
cursor_index: &mut Option<Index>,
) -> Option<(K, V)>
pub fn remove_by_index( &mut self, cursor_index: &mut Option<Index>, ) -> Option<(K, V)>
Removes node at current index, updating the index to point to the next valid position Returns the key-value pair if removal was successful. Moves cursor current to the old prev value if existed. Else pick old next index.
Source§impl<K, V> LinkedList<K, V>
impl<K, V> LinkedList<K, V>
pub fn validate(&self)
pub fn assert_is_in_order(&self)
Sourcepub fn debug_print(&self)where
K: Display,
pub fn debug_print(&self)where
K: Display,
Print the LinkedList in a visual tabulated format for debugging