Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,19 @@
use std::collections::HashSet;
use std::hash::Hash;
fn remove_duplicate_elements_hashing<T: Hash + Eq>(elements: &mut Vec<T>) {
let set: HashSet<_> = elements.drain(..).collect();
elements.extend(set.into_iter());
}
fn remove_duplicate_elements_sorting<T: Ord>(elements: &mut Vec<T>) {
elements.sort_unstable(); // order does not matter
elements.dedup();
}
fn main() {
let mut sample_elements = vec![0, 0, 1, 1, 2, 3, 2];
println!("Before removal of duplicates : {:?}", sample_elements);
remove_duplicate_elements_sorting(&mut sample_elements);
println!("After removal of duplicates : {:?}", sample_elements);
}