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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let matrix: PriorityMatrix<char, &str, i32> = [
        ('a', "alpha", 0),
        ('a', "beta", 3),
        ('b', "alpha", 2),
        ('b', "beta", 1),
    ]
    .into_iter()
    .collect();

    // Get the maximum entry
    let entry = matrix.peek().unwrap();
    assert_eq!(entry.row, &'a');
    assert_eq!(entry.column, &"beta");
    assert_eq!(entry.weight, &3);

    // Get the maximum entry in a row
    let entry = matrix.peek_from_row(&'b').unwrap();
    assert_eq!(entry.row, &'b');
    assert_eq!(entry.column, &"alpha");
    assert_eq!(entry.weight, &2);

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

    // Get the maximum entry
    let entry = matrix.peek().unwrap();
    assert_eq!(entry.row, &'a');
    assert_eq!(entry.column, &"beta");
    assert_eq!(entry.weight, &3);

    // Get the maximum entry in a row
    let entry = matrix.peek_from_row(&'b').unwrap();
    assert_eq!(entry.row, &'b');
    assert_eq!(entry.column, &"alpha");
    assert_eq!(entry.weight, &2);

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

    // Get the maximum entry
    let entry = matrix.peek().unwrap();
    assert_eq!(entry.row, &'a');
    assert_eq!(entry.column, &"beta");
    assert_eq!(entry.weight, &3);

    // Get the maximum entry in a row
    let entry = matrix.peek_from_row(&'b').unwrap();
    assert_eq!(entry.row, &'b');
    assert_eq!(entry.column, &"alpha");
    assert_eq!(entry.weight, &2);

    // Get the maximum entry in a column
    let entry = matrix.peek_from_column(&"alpha").unwrap();
    assert_eq!(entry.row, &'b');
    assert_eq!(entry.column, &"alpha");
    assert_eq!(entry.weight, &2);
}
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>

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 copy of the value. Read more
1.0.0 · source§

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) -> Selfwhere 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,

§

type Item = (R, C, W)

The type of the elements being iterated over.
§

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> RefUnwindSafe for PriorityMatrix<R, C, W>where C: RefUnwindSafe, R: RefUnwindSafe, W: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.