Skip to content

Commit

Permalink
little speed ups
Browse files Browse the repository at this point in the history
  • Loading branch information
tph5595 committed Jan 29, 2025
1 parent bc02e87 commit 7c58803
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 132 deletions.
4 changes: 2 additions & 2 deletions src/barcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ impl Eq for Node {}
#[derive(Debug, Clone)]
struct Event {
event_type: EventType,
value: f64,
value: f32,
}

const fn create_event(birth: f64, death: f64, i: usize) -> Node {
const fn create_event(birth: f32, death: f32, i: usize) -> Node {
Node {
birth_event: Event {
event_type: EventType::Birth,
Expand Down
4 changes: 2 additions & 2 deletions src/birthdeath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::str::FromStr;

#[derive(Debug)]
pub struct BirthDeath {
pub birth: f64,
pub death: f64,
pub birth: f32,
pub death: f32,
}

impl FromStr for BirthDeath {
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use clap::Parser;
use csv::Writer;
use std::error::Error;
use std::fs;
use std::time::Instant;

/// Generates the PL for a set of birth death pairs
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -40,6 +41,7 @@ struct Args {
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();

let now = Instant::now();
let bd_paris: Vec<fast_pl::birthdeath::BirthDeath> = fs::read_to_string(args.name)?
.lines()
.filter(|s| !s.contains("inf") && !s.is_empty())
Expand All @@ -49,6 +51,9 @@ fn main() -> Result<(), Box<dyn Error>> {

let landscapes = fast_pl::rpls::pairs_to_landscape(bd_paris, args.k, args.debug)?;

let elapsed = now.elapsed();
println!("Elapsed: {elapsed:.?}");

if !args.csv.is_empty() {
let mut wtr = Writer::from_path(args.csv)?;
for landscape in &landscapes {
Expand All @@ -71,7 +76,7 @@ fn main() -> Result<(), Box<dyn Error>> {

#[cfg(test)]
mod tests {
fn test_runner(k: usize, bd_pairs_vec: Vec<(f64, f64)>, answer_vec: Vec<Vec<(f64, f64)>>) {
fn test_runner(k: usize, bd_pairs_vec: Vec<(f32, f32)>, answer_vec: Vec<Vec<(f32, f32)>>) {
let bd_pairs = bd_pairs_vec
.into_iter()
.map(|(x, y)| fast_pl::birthdeath::BirthDeath { birth: x, death: y })
Expand Down
Loading

0 comments on commit 7c58803

Please sign in to comment.