Skip to content

Commit 6cb50ef

Browse files
committed
Fix all problems with duplicated items
1 parent c83a702 commit 6cb50ef

File tree

1 file changed

+12
-46
lines changed

1 file changed

+12
-46
lines changed

czkawka_core/src/similar_images.rs

+12-46
Original file line numberDiff line numberDiff line change
@@ -683,50 +683,19 @@ impl SimilarImages {
683683
mem::swap(&mut all_hashed_images, &mut self.image_hashes);
684684

685685
let all_hashes: Vec<_> = all_hashed_images.keys().collect();
686-
let mut already_used_hashes: HashSet<_> = Default::default(); // List of already user hashes
687-
688-
for (hash, vec_file_entry) in all_hashed_images.clone() {
689-
// There exists 2 or more images with same hash
690-
if vec_file_entry.len() >= 2 {
691-
already_used_hashes.insert(hash.clone());
692-
collected_similar_images.insert(hash, vec_file_entry);
693-
} else {
694-
self.bktree.add(hash.clone());
695-
}
696-
}
697-
698-
//// PROGRESS THREAD START
699-
let check_was_stopped = AtomicBool::new(false); // Used for breaking from GUI and ending check thread
700-
let progress_thread_run = Arc::new(AtomicBool::new(true));
701-
702-
let atomic_mode_counter = Arc::new(AtomicUsize::new(0));
703686

704-
let progress_thread_handle = if let Some(progress_sender) = progress_sender {
705-
let progress_send = progress_sender.clone();
706-
let progress_thread_run = progress_thread_run.clone();
707-
let atomic_mode_counter = atomic_mode_counter.clone();
708-
let all_hashes_number = all_hashes.len();
709-
thread::spawn(move || loop {
710-
progress_send
711-
.unbounded_send(ProgressData {
712-
current_stage: 2,
713-
max_stage: 3,
714-
images_checked: atomic_mode_counter.load(Ordering::Relaxed) as usize,
715-
images_to_check: all_hashes_number,
716-
})
717-
.unwrap();
718-
if !progress_thread_run.load(Ordering::Relaxed) {
719-
break;
687+
// Checking entries with tolerance 0 is really easy and fast, because only entries with same hashes needs to be checked
688+
if tolerance == 0 {
689+
for (hash, vec_file_entry) in all_hashed_images.clone() {
690+
if vec_file_entry.len() >= 2 {
691+
collected_similar_images.insert(hash, vec_file_entry);
720692
}
721-
sleep(Duration::from_millis(LOOP_DURATION as u64));
722-
})
693+
}
723694
} else {
724-
thread::spawn(|| {})
725-
};
726-
//// PROGRESS THREAD END
727-
let mut timer = SystemTime::now();
695+
for hash in &all_hashes {
696+
self.bktree.add(hash.to_vec());
697+
}
728698

729-
if tolerance > 0 {
730699
let number_of_processors = num_cpus::get();
731700
let chunks = all_hashes.chunks(all_hashes.len() / number_of_processors);
732701

@@ -790,13 +759,12 @@ impl SimilarImages {
790759
}
791760
}
792761

762+
#[cfg(debug_assertions)]
793763
debug_check_for_duplicated_things(hashes_parents.clone(), hashes_similarity.clone(), all_hashed_images.clone(), "BEFORE");
794764

795765
(hashes_parents, hashes_similarity)
796766
})
797767
.collect();
798-
Common::print_time(timer, SystemTime::now(), "CHECKING IN PARRAREL".to_string());
799-
timer = SystemTime::now();
800768

801769
{
802770
let mut new_hashes_parents: HashMap<&Vec<u8>, u32> = Default::default();
@@ -847,9 +815,8 @@ impl SimilarImages {
847815
}
848816
}
849817
}
850-
Common::print_time(timer, SystemTime::now(), "Connecting results".to_string());
851-
timer = SystemTime::now();
852818

819+
#[cfg(debug_assertions)]
853820
debug_check_for_duplicated_things(new_hashes_parents.clone(), new_hashes_similarity.clone(), all_hashed_images.clone(), "LATTER");
854821

855822
// Collecting results
@@ -868,12 +835,11 @@ impl SimilarImages {
868835
}
869836
collected_similar_images.get_mut(parent_hash).unwrap().append(&mut vec_fe);
870837
}
871-
Common::print_time(timer, SystemTime::now(), "Creating entries".to_string());
872838
}
873839
}
874840

875841
// Validating if group contains duplicated results
876-
//#[cfg(debug_assertions)]
842+
#[cfg(debug_assertions)]
877843
{
878844
let mut result_hashset: HashSet<String> = Default::default();
879845
let mut found = false;

0 commit comments

Comments
 (0)