aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dictionary.rs4
-rw-r--r--src/gui/mod.rs2
-rw-r--r--src/index.rs21
-rw-r--r--src/main.rs2
4 files changed, 15 insertions, 14 deletions
diff --git a/src/dictionary.rs b/src/dictionary.rs
index 563621d..3e05b91 100644
--- a/src/dictionary.rs
+++ b/src/dictionary.rs
@@ -79,7 +79,7 @@ impl Dictionary {
if !fv.contains_key(&i) {
fv.insert(i, 1);
} else {
- let c : u64 = *fv.get(&i).unwrap();
+ let c = *fv.get(&i).unwrap();
fv.insert(i, c + 1);
}
}
@@ -95,7 +95,7 @@ impl Dictionary {
if !fv.contains_key(&i) {
fv.insert(i, 1);
} else {
- let c : u64 = *fv.get(&i).unwrap();
+ let c = *fv.get(&i).unwrap();
fv.insert(i, c + 1);
}
}
diff --git a/src/gui/mod.rs b/src/gui/mod.rs
index 0dcf430..f56dd71 100644
--- a/src/gui/mod.rs
+++ b/src/gui/mod.rs
@@ -60,7 +60,7 @@ struct GenProgress {
impl SearchState {
pub async fn search(self) -> Vec<SearchResult> {
- let search_args = splitter::split_to_words(self.search.clone());
+ let search_args = splitter::split_to_words(self.search);
self.index.search(search_args)
}
}
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();
});
}
diff --git a/src/main.rs b/src/main.rs
index f9d5018..729b40d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -62,7 +62,7 @@ fn main() {
let merged = args.get(2).unwrap().clone();
let v : Vec<String> = args.get(3..(args.len())).unwrap().into();
let indexes : Vec<Index> = v.iter().map(Index::from_file).collect();
- Index::merge(indexes.iter().collect(),
+ Index::merge(indexes,
|p| {
eprint!("\r\x1b[2K{}% merged", p);
}