use std::path::Path; use std::fs::File; use std::io::{BufRead, BufReader}; use fqdn_trie::FqdnTrieSet; use std::time::{Instant, Duration}; use cpu_time::ProcessTime; use fqdn::FQDN; fn main() { // Create a path to the desired file let path = Path::new("/Users/xophe/Logiciels/TESS/Antidote/mudkeys"); // Open the path in read-only mode, returns `io::Result` let file = File::open(&path).unwrap(); let reader = BufReader::new(file); let mut fqdns = reader.lines() .filter_map(|l| l.ok()) .filter_map(|s| s.parse::().ok()) .filter(|s| s.depth() > 3) .collect::>(); println!("test file contains {} FQDN", fqdns.len()); let now = Instant::now(); let start = ProcessTime::try_now().expect("Getting process time failed"); let mut trie = FqdnTrieSet::new(FQDN::default()); trie.extend(fqdns.iter().step_by(3).cloned()); let cpu_time: Duration = start.try_elapsed().expect("Getting process time failed"); let elapsed = now.elapsed(); println!("time elapsed using for building the trie: real={:?}, cpu={:?}", elapsed, cpu_time); fqdns.iter_mut().for_each(|f| *f = f.parent().unwrap().into()); let mut count = 0; let now = Instant::now(); let start = ProcessTime::try_now().expect("Getting process time failed"); fqdns.iter() .for_each(|f| { let found = trie.lookup(f); if !found.is_root() { count += 1; } }); let cpu_time: Duration = start.try_elapsed().expect("Getting process time failed"); let elapsed = now.elapsed(); println!("found {} fqdn", count); println!("time elapsed using for building the trie: real={:?}, cpu={:?}", elapsed, cpu_time); let _ = trie.open_dot_view(); }