aboutsummaryrefslogtreecommitdiff
path: root/src/index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.rs')
-rw-r--r--src/index.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/index.rs b/src/index.rs
index 368697d..fd38298 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -49,7 +49,7 @@ impl Index {
let mut nof = 1;
let mut counter = 0;
let mut crawler_handles = Vec::new();
- let num_threads = thread::available_parallelism().unwrap().get().min(4);
+ let num_threads = thread::available_parallelism().unwrap().get();
let mut tx_vec : Vec<Sender<String>> = Vec::new();
let mut indexes = Vec::new();
@@ -156,7 +156,7 @@ impl Index {
join_handle.join().ok();
});
- Index::merge(indexes.iter().collect(), |p| { callback(GenState::Merging, p) })
+ Index::merge(indexes, |p| { callback(GenState::Merging, p) })
}
pub fn from_file(path : &String) -> Self {
@@ -180,7 +180,7 @@ impl Index {
}
}
- fn merge_into(&mut self, other : &Index) {
+ fn merge_into(&mut self, other : Index) {
let mut dict = self.dictionary.clone();
thread::scope(|s| {
let mut a_hash : HashSet<&FileCache> = HashSet::new();
@@ -232,11 +232,11 @@ impl Index {
});
}
- pub fn merge(mut indexes : Vec<&Index>, callback : impl Fn(u8)) -> Self {
+ pub fn merge(mut indexes : Vec<Index>, callback : impl Fn(u8)) -> Self {
let max = indexes.len();
indexes.sort_by(|a, b| a.filecache.len().cmp(&b.filecache.len()));
- let mut merged_index : Index = indexes.pop().unwrap().clone();
+ let mut merged_index : Index = indexes.pop().unwrap();
for (i, index) in indexes.into_iter().enumerate() {
callback((i * 100 / max) as u8);
@@ -280,14 +280,15 @@ impl Index {
let dict_list_handle = s.spawn(|| {
self.dictionary.to_list().join(",")
});
- let mut output : String = self.filecache.iter().map(|c| format!("{}, {}\n", c.path.replace(',', "\0"), c.vector.stringify())).collect();
- output += "#";
- output += dict_list_handle.join().unwrap().as_str();
- output += "\n";
let index_file = File::create(path).expect("could not open output file");
let mut file = BufWriter::new(index_file);
- file.write_all(output.as_bytes()).expect("could not write");
+
+ for fc in self.filecache.iter() {
+ write!(file, "{}, {}\n", fc.path.replace(',', "\0"), fc.vector.stringify()).ok();
+ }
+
+ write!(file, "#{}\n", dict_list_handle.join().unwrap().as_str()).ok();
file.flush().ok();
});
}