LinkedList

Struct LinkedList 

Source
pub struct LinkedList<K, V>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,
{ /* 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>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source

pub fn contains_key(&self, key: &K) -> bool

Check if a key exists in the LinkedList

Source

pub fn get(&self, search_key: &K) -> Option<&V>

Get a reference to the value associated with a key

Source

pub fn get_at(&self, index: Index) -> Option<(&K, &V)>

Get a reference to the key and value at a given node index

Source

pub fn get_k_at(&self, index: Index) -> Option<&K>

Get a reference to the key and value at a given node index

Source

pub fn get_v_at(&self, index: Index) -> Option<&V>

Get a reference to the key and value at a given node index

Source

pub fn get_kv(&self, search_key: &K) -> Option<(&K, &V)>

Get a reference to the value associated with a key

Source

pub fn get_mut(&mut self, search_key: &K) -> Option<&mut V>

Get a mutable reference to the value associated with a key

Source

pub fn set_v_at(&mut self, index: Index, input_val: V) -> Option<V>

Get a reference to the key and value at a given node index

Source

pub fn get_mut_at(&mut self, index: Index) -> Option<(&K, &mut V)>

Get a mutable reference to the value at a given node index

Source§

impl<K, V> LinkedList<K, V>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source

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

Source

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>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source

pub fn iter(&self) -> LinkedListIter<'_, K, V>

Source§

impl<K, V> LinkedList<K, V>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source

pub fn len(&self) -> usize

Get the number of elements in the LinkedList

Source

pub fn is_empty(&self) -> bool

Check if the LinkedList is empty

Source

pub fn sequential_find_position( &self, key: &K, hint_position: Index, ) -> Option<Index>

Source

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.

Source

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

Source

pub fn next_pos(&self, current: Option<Index>) -> Option<Index>

Get the next node index (for iterator-like traversal)

Source

pub fn prev_pos(&self, current: Option<Index>) -> Option<Index>

Get the previous node index (for bidirectional iterator-like traversal)

Source

pub fn is_pos_valid(&self, index: Option<Index>) -> bool

Source

pub fn first(&self) -> Option<Index>

Get the first element (equivalent to begin() in std::map)

Source

pub fn last(&self) -> Option<Index>

Get the last element (equivalent to rbegin() in std::map)

Source

pub fn is_at_first(&self, pos: Option<Index>) -> bool

Return true if pointer is at head position or if the list is empty

Source

pub fn is_at_last(&self, pos: Option<Index>) -> bool

Return true if pointer is at tail position or if the list is empty

Source

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>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source

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

pub fn remove(&mut self, key: &K) -> Option<(K, V)>

Remove a node by key Returns the value of the removed node if found

Source

pub fn clear(&mut self)

Clear the LinkedList

Source§

impl<K, V> LinkedList<K, V>
where K: Debug + Display + Clone + IsLessThan, V: Debug + Clone,

Source

pub fn validate(&self)

Source

pub fn assert_is_in_order(&self)
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source

pub fn debug_print(&self)
where K: Display,

Print the LinkedList in a visual tabulated format for debugging

Trait Implementations§

Source§

impl<K, V> Debug for LinkedList<K, V>
where K: Debug + Clone + IsLessThan + Debug, V: Debug + Clone + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for LinkedList<K, V>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V> FromIterator<(K, V)> for LinkedList<K, V>
where K: Debug + Clone + IsLessThan, V: Debug + Clone,

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for LinkedList<K, V>

§

impl<K, V> RefUnwindSafe for LinkedList<K, V>

§

impl<K, V> Send for LinkedList<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for LinkedList<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for LinkedList<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for LinkedList<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V