2个不稳定版本
0.2.0 | 2023年4月19日 |
---|---|
0.1.0 | 2023年2月12日 |
#2191 in 数据结构
13KB
296 代码行
priority-matrix
Rust包实现了支持按行、按列和整个矩阵查询最大键的矩阵数据结构。
示例
以下代码是一个查询矩阵、行或列中具有最大权重的键的示例。完整的示例可以在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');
许可证
本项目采用MIT许可证发布。请阅读许可证文件。
lib.rs
:
Rust包实现了支持按行、按列和整个矩阵查询最大键的矩阵数据结构。
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);
依赖
~1.5MB
~26K SLoC