Struct priority_matrix::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,
impl<R, C, W> PriorityMatrix<R, C, W>where R: Clone + Eq + Hash, C: Clone + Eq + Hash, W: Clone + Ord,
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)
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);
}
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)
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);
}
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)
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);
}
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> ⓘ
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,
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>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more