26 lines
644 B
Rust
26 lines
644 B
Rust
use crate::matrix::MatrixGF2;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct TannerGraph {
|
|
pub check: Vec<Vec<usize>>,
|
|
pub bits: Vec<Vec<usize>>,
|
|
}
|
|
|
|
impl TannerGraph {
|
|
pub fn from_matrix(matrix: &MatrixGF2) -> Self {
|
|
let mut check = vec![vec![]; matrix.rows];
|
|
let mut bits = vec![vec![]; matrix.cols];
|
|
|
|
for (i, row_check) in check.iter_mut().enumerate() {
|
|
for (j, col_bits) in bits.iter_mut().enumerate() {
|
|
if matrix.get(i, j) == 0 {
|
|
row_check.push(j);
|
|
col_bits.push(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
Self { check, bits }
|
|
}
|
|
}
|