This commit is contained in:
2025-12-14 14:46:23 -08:00
parent f115b9104a
commit 63eb0fc374

View File

@@ -31,9 +31,16 @@ async fn main()->Result<(),Error>{
return Err(Error::InvalidArgs); return Err(Error::InvalidArgs);
}; };
const ONE_SECOND:u64=1<<32;
struct FoldState{ struct FoldState{
count:usize, count:usize,
jumps:u64, jumps:u64,
duration:u64,
}
impl std::fmt::Display for FoldState{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"count={} jumps={} duration={}",self.count,self.jumps,self.duration as f64/(ONE_SECOND as f64))
}
} }
let available_parallelism=std::thread::available_parallelism()?.get(); let available_parallelism=std::thread::available_parallelism()?.get();
@@ -54,14 +61,19 @@ async fn main()->Result<(),Error>{
} }
}) })
.buffer_unordered(available_parallelism) .buffer_unordered(available_parallelism)
.try_fold(FoldState{count:0,jumps:0},async|mut state,(path,block)|{ .try_fold(FoldState{count:0,jumps:0,duration:0},async|mut state,(path,block)|{
state.count+=1; state.count+=1;
state.jumps+=block.sound_events.iter() state.jumps+=block.sound_events.iter()
.filter(|event|event.event.sound_type==v0::SoundType::JumpGround) .filter(|event|event.event.sound_type==v0::SoundType::JumpGround)
.count() as u64; .count() as u64;
println!("{} {:?} tally={}",state.count,path.file_name(),state.jumps); if let (Some(first),Some(last))=(block.output_events.first(),block.output_events.last()){
let last=last.time*(ONE_SECOND as f64);
let first=first.time*(ONE_SECOND as f64);
state.duration+=last as u64-first as u64;
}
println!("{:?} {}",path.file_name(),state);
Ok(state) Ok(state)
}).await?; }).await?;
println!("total jump count = {}",tally.jumps); println!("{}",tally);
Ok(()) Ok(())
} }