This is my code: pub fn parsetracks<'a>(contents: &'a str) -> Result<TranscriptMap,…
- User
This is my code:
pub fn parse_tracks<'a>(contents: &'a str) -> Result<TranscriptMap, &'static str> { // let pseudomap: Arc<DashMap<String, Vec<(u32, u32, String)>>> = Arc::new(DashMap::new());
let mut tracks = contents .par_lines() .filter(|x| !x.starts_with("#")) .filter_map(|x| Record::new(x).ok()) .fold( || HashMap::new(), |mut acc, record| { // let mut ps_acc = pseudomap.entry(record.chrom.clone()).or_insert(Vec::new()); // ps_acc.push((record.tx_start, record.tx_end, record.id.clone())); let k = acc.entry(record.chrom).or_insert(vec![]); k.push(record.info); acc }, ) .reduce( || HashMap::new(), |mut acc, map| { for (k, v) in map { let acc_v = acc.entry(k).or_insert(Vec::new()); acc_v.extend(v); } acc }, ); tracks.par_iter_mut().for_each(|(_, v)| { v.par_sort_unstable_by_key(|x| (x.0, x.1)); }); Ok(tracks)}
where:
pub type TranscriptMap = HashMap<Chromosome, Vec>; pub type Chromosome = String;
this is pretty fast but I just realized that real use cases will build the hashmap with millions of elements (if no thousands of millions). I need to make this more faster and more efficient to hold. Any ideas? You are free to use any crate, algorithm or data structure you want!
- Assistant