pub struct PriorityMatrix<R, C, W>{ /* 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>
impl<R, C, W> PriorityMatrix<R, C, W>
pub fn new(&self) -> Self
pub fn insert(&mut self, row: R, col: C, weight: W) -> Option<W>
Sourcepub fn peek(&self) -> Option<BorrowedEntry<'_, R, C, W>>
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}
Sourcepub fn peek_from_row<'a>(
&'a self,
row: &'a R,
) -> Option<BorrowedEntry<'_, R, C, W>>
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}
Sourcepub fn peek_from_column<'a>(
&'a self,
col: &'a C,
) -> Option<BorrowedEntry<'a, R, C, W>>
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}
pub fn pop(&mut self) -> Option<OwnedEntry<R, C, W>>
pub fn pop_from_row(&mut self, row: &R) -> Option<OwnedEntry<R, C, W>>
pub fn pop_from_column(&mut self, col: &C) -> Option<OwnedEntry<R, C, W>>
pub fn remove(&mut self, row: &R, col: &C) -> bool
pub fn remove_row(&mut self, row: &R)
pub fn remove_column(&mut self, col: &C)
pub fn remove_row_and_column(&mut self, row: &R, col: &C)
pub fn iter(&self) -> Iter<'_, R, C, W> ⓘ
pub fn is_empty(&self) -> bool
pub fn row_keys(&self) -> impl Iterator<Item = &R>
pub fn column_keys(&self) -> impl Iterator<Item = &C>
Trait Implementations§
Source§impl<R, C, W> Clone for PriorityMatrix<R, C, W>
impl<R, C, W> Clone for PriorityMatrix<R, C, W>
Source§fn clone(&self) -> PriorityMatrix<R, C, W>
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)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<R, C, W> Debug for PriorityMatrix<R, C, W>
impl<R, C, W> Debug for PriorityMatrix<R, C, W>
Source§impl<R, C, W> Default for PriorityMatrix<R, C, W>
impl<R, C, W> Default for PriorityMatrix<R, C, W>
Source§impl<R, C, W> FromIterator<(R, C, W)> for PriorityMatrix<R, C, W>
impl<R, C, W> FromIterator<(R, C, W)> for PriorityMatrix<R, C, W>
Source§impl<R, C, W> IntoIterator for PriorityMatrix<R, C, W>
impl<R, C, W> IntoIterator for PriorityMatrix<R, C, W>
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>
impl<R, C, W> Sync for PriorityMatrix<R, C, W>
impl<R, C, W> Unpin for PriorityMatrix<R, C, W>
impl<R, C, W> UnwindSafe for PriorityMatrix<R, C, W>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more