use crate::cli::*;
use crate::peg::Config;
use clap::Parser;
use std::error::Error;
#[derive(Debug, Parser)]
#[command(about = "Generates LDPC codes using the Progressive Edge Growth algorithm")]
pub struct Args {
pub num_rows: usize,
pub num_columns: usize,
pub wc: usize,
pub seed: u64,
#[arg(long)]
pub girth: bool,
}
impl Args {
fn config(&self) -> Config {
Config {
nrows: self.num_rows,
ncols: self.num_columns,
wc: self.wc,
}
}
}
impl Run for Args {
fn run(&self) -> Result<(), Box<dyn Error>> {
let conf = self.config();
let h = conf.run(self.seed)?;
for r in 0..h.num_rows() {
if h.row_weight(r) < 2 {
eprint!("warning: at least 1 row weight ≤ 1");
if conf.wc < 3 {
eprint!(" (try col weight ≥ 3?)");
}
eprintln!();
break;
}
}
println!("{}", h.alist());
if self.girth {
match h.girth() {
Some(g) => eprintln!("Code girth = {}", g),
None => eprintln!("Code girth = infinity (there are no cycles)"),
};
}
Ok(())
}
}