use std::fs;
use std::time::SystemTime;
use std::{collections::VecDeque, path::Path, sync::Arc};
use crate::Flt;
pub(crate) mod h5;
pub fn find_unused_buf<T>(q: &mut VecDeque<Arc<T>>) -> Option<Arc<T>>
where
{
q.iter_mut()
.position(|g| Arc::get_mut(g).is_some())
.and_then(|p| q.remove(p))
}
pub fn get_current_timestamp() -> Flt {
let now = SystemTime::now();
let duration = now
.duration_since(SystemTime::UNIX_EPOCH)
.expect("System clock thinks it is before UNIX_EPOCH");
duration.as_secs_f64() as Flt
}
pub fn get_modified_timestamp(path: &Path) -> Result<Flt, std::io::Error> {
let metadata = fs::metadata(path)?;
let modified = metadata.modified()?;
let duration = modified
.duration_since(SystemTime::UNIX_EPOCH)
.expect("System clock thinks it is before UNIX_EPOCH");
Ok(duration.as_secs_f64() as Flt)
}