use crate::cli::*;
use crate::peg::Config;
use clap::Parser;
use std::error::Error;
#[derive(Debug, Parser)]
#[structopt(about = "Generates LDPC codes using the Progressive Edge Growth algorithm")]
pub struct Args {
num_rows: usize,
num_columns: usize,
wc: usize,
seed: u64,
#[structopt(long)]
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)?;
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(())
}
}