#matrix #key #queries #maximum #supports #priority #per-column

priority-matrix

A matrix that supports per-row, per-column and whole-matrix maximum key queries

2 unstable releases

0.2.0 Apr 19, 2023
0.1.0 Feb 12, 2023

#2318 in Data structures

Download history 70/week @ 2024-02-21 29/week @ 2024-02-28

99 downloads per month

MIT license

13KB
296 lines

priority-matrix

The Rust crate implements the matrix data structure that supports per-row, per-column and whole-matrix maximum key queries.

Example

The code below is an example to query the key with the maximum weight either in the matrix, in a row or in a column. The complete example can be found in peek.rs.

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.weight, &3);

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

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

License

This project is distributed under MIT license. Please read the license file.


lib.rs:

The Rust crate implements the matrix data structure that supports per-row, per-column and whole-matrix maximum key queries.

use priority_matrix::PriorityMatrix;

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);

Dependencies

~1.5MB
~26K SLoC