1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
pub mod vec { pub trait Uniq { fn uniq(&self, other: Self) -> Self; fn unique(&self) -> Self; fn is_unique(&self) -> bool; } impl<T: Clone + PartialEq> Uniq for Vec<T> { fn uniq(&self, other: Vec<T>) -> Vec<T> { let mut uniq_val = vec![]; for x in self.to_vec() { let mut unique = true; for y in other.to_vec() { if x == y { unique = false } }; if unique { uniq_val.push(x.clone()) } }; uniq_val } fn unique(&self) -> Vec<T> { let mut a = self.clone(); for x in 0..a.len() { for y in x+1..a.len() { if a[x] == a[y] { a.remove(y); break; } } } a } fn is_unique(&self) -> bool { let mut a = true; for x in 0..self.len() { for y in x+1..self.len() { if self[x] == self[y] { a = false; break; } } } a } } pub trait Empty { fn empty(&self)-> bool; } impl<T: PartialEq> Empty for Vec<T> { fn empty(&self) -> bool { self.len() == 0 } } } pub fn uniques<T: PartialEq + Clone>(a: Vec<T>, b: Vec<T>) -> Vec<Vec<T>> { use self::vec::Uniq; vec![a.uniq(b.clone()), b.uniq(a)] }