Struct PriorityMatrix

Source
pub struct PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash, C: Clone + Eq + Hash, W: Clone + Ord,
{ /* private fields */ }
Expand description

The 2-dimensional matrix that supports per-row and per-column maximum key queries.

Implementations§

Source§

impl<R, C, W> PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash, C: Clone + Eq + Hash, W: Clone + Ord,

Source

pub fn new(&self) -> Self

Source

pub fn insert(&mut self, row: R, col: C, weight: W) -> Option<W>

Source

pub fn peek(&self) -> Option<BorrowedEntry<'_, R, C, W>>

Examples found in repository?
examples/peek.rs (line 14)
3fn main() {
4    let matrix: PriorityMatrix<char, &str, i32> = [
5        ('a', "alpha", 0),
6        ('a', "beta", 3),
7        ('b', "alpha", 2),
8        ('b', "beta", 1),
9    ]
10    .into_iter()
11    .collect();
12
13    // Get the maximum entry
14    let entry = matrix.peek().unwrap();
15    assert_eq!(entry.row, &'a');
16    assert_eq!(entry.column, &"beta");
17    assert_eq!(entry.weight, &3);
18
19    // Get the maximum entry in a row
20    let entry = matrix.peek_from_row(&'b').unwrap();
21    assert_eq!(entry.row, &'b');
22    assert_eq!(entry.column, &"alpha");
23    assert_eq!(entry.weight, &2);
24
25    // Get the maximum entry in a column
26    let entry = matrix.peek_from_column(&"alpha").unwrap();
27    assert_eq!(entry.row, &'b');
28    assert_eq!(entry.column, &"alpha");
29    assert_eq!(entry.weight, &2);
30}
Source

pub fn peek_from_row<'a>( &'a self, row: &'a R, ) -> Option<BorrowedEntry<'_, R, C, W>>

Examples found in repository?
examples/peek.rs (line 20)
3fn main() {
4    let matrix: PriorityMatrix<char, &str, i32> = [
5        ('a', "alpha", 0),
6        ('a', "beta", 3),
7        ('b', "alpha", 2),
8        ('b', "beta", 1),
9    ]
10    .into_iter()
11    .collect();
12
13    // Get the maximum entry
14    let entry = matrix.peek().unwrap();
15    assert_eq!(entry.row, &'a');
16    assert_eq!(entry.column, &"beta");
17    assert_eq!(entry.weight, &3);
18
19    // Get the maximum entry in a row
20    let entry = matrix.peek_from_row(&'b').unwrap();
21    assert_eq!(entry.row, &'b');
22    assert_eq!(entry.column, &"alpha");
23    assert_eq!(entry.weight, &2);
24
25    // Get the maximum entry in a column
26    let entry = matrix.peek_from_column(&"alpha").unwrap();
27    assert_eq!(entry.row, &'b');
28    assert_eq!(entry.column, &"alpha");
29    assert_eq!(entry.weight, &2);
30}
Source

pub fn peek_from_column<'a>( &'a self, col: &'a C, ) -> Option<BorrowedEntry<'a, R, C, W>>

Examples found in repository?
examples/peek.rs (line 26)
3fn main() {
4    let matrix: PriorityMatrix<char, &str, i32> = [
5        ('a', "alpha", 0),
6        ('a', "beta", 3),
7        ('b', "alpha", 2),
8        ('b', "beta", 1),
9    ]
10    .into_iter()
11    .collect();
12
13    // Get the maximum entry
14    let entry = matrix.peek().unwrap();
15    assert_eq!(entry.row, &'a');
16    assert_eq!(entry.column, &"beta");
17    assert_eq!(entry.weight, &3);
18
19    // Get the maximum entry in a row
20    let entry = matrix.peek_from_row(&'b').unwrap();
21    assert_eq!(entry.row, &'b');
22    assert_eq!(entry.column, &"alpha");
23    assert_eq!(entry.weight, &2);
24
25    // Get the maximum entry in a column
26    let entry = matrix.peek_from_column(&"alpha").unwrap();
27    assert_eq!(entry.row, &'b');
28    assert_eq!(entry.column, &"alpha");
29    assert_eq!(entry.weight, &2);
30}
Source

pub fn pop(&mut self) -> Option<OwnedEntry<R, C, W>>

Source

pub fn pop_from_row(&mut self, row: &R) -> Option<OwnedEntry<R, C, W>>

Source

pub fn pop_from_column(&mut self, col: &C) -> Option<OwnedEntry<R, C, W>>

Source

pub fn remove(&mut self, row: &R, col: &C) -> bool

Source

pub fn remove_row(&mut self, row: &R)

Source

pub fn remove_column(&mut self, col: &C)

Source

pub fn remove_row_and_column(&mut self, row: &R, col: &C)

Source

pub fn iter(&self) -> Iter<'_, R, C, W>

Source

pub fn len(&self) -> usize

Returns the number of elements of this matrix.

Source

pub fn is_empty(&self) -> bool

Source

pub fn row_keys(&self) -> impl Iterator<Item = &R>

Source

pub fn column_keys(&self) -> impl Iterator<Item = &C>

Trait Implementations§

Source§

impl<R, C, W> Clone for PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash + Clone, C: Clone + Eq + Hash + Clone, W: Clone + Ord + Clone,

Source§

fn clone(&self) -> PriorityMatrix<R, C, W>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R, C, W> Debug for PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash + Debug, C: Clone + Eq + Hash + Debug, W: Clone + Ord + Debug,

Source§

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

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

impl<R, C, W> Default for PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash, C: Clone + Eq + Hash, W: Clone + Ord,

Source§

fn default() -> Self

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

impl<R, C, W> FromIterator<(R, C, W)> for PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash, C: Clone + Eq + Hash, W: Clone + Ord,

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = (R, C, W)>,

Creates a value from an iterator. Read more
Source§

impl<R, C, W> IntoIterator for PriorityMatrix<R, C, W>
where R: Clone + Eq + Hash, C: Clone + Eq + Hash, W: Clone + Ord,

Source§

type Item = (R, C, W)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<R, C, W>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<R, C, W> Freeze for PriorityMatrix<R, C, W>

§

impl<R, C, W> RefUnwindSafe for PriorityMatrix<R, C, W>

§

impl<R, C, W> Send for PriorityMatrix<R, C, W>
where R: Send, C: Send, W: Send,

§

impl<R, C, W> Sync for PriorityMatrix<R, C, W>
where R: Sync, C: Sync, W: Sync,

§

impl<R, C, W> Unpin for PriorityMatrix<R, C, W>
where R: Unpin, C: Unpin, W: Unpin,

§

impl<R, C, W> UnwindSafe for PriorityMatrix<R, C, W>
where R: UnwindSafe, C: UnwindSafe, W: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.